Skip to main content

tablegis

tablegis is a Python package for geospatial data processing and analysis, built on geopandas, pandas, shapely, and pyproj. It provides a series of utility functions to simplify common GIS operations.

Features

  • Distance Calculation: Efficiently compute the nearest distance between DataFrames.
  • Spatial Analysis: Create buffers (input in meters), Voronoi polygons, Delaunay triangulations, etc.
  • Format Conversion: Easily convert between GeoDataFrame and formats like Shapefile, KML, etc.
  • Coordinate Aggregation: Provides tools for aggregating coordinate points into grids.
  • Geometric Operations: Includes merging polygons, calculating centroids, adding sectors, etc.

Installation

1、You can install tablegis from PyPI:

pip install tablegis

2、Or, install the latest version directly from the GitHub repository:

pip install git+https://github.com/Non-existent987/tablegis.git

3、After downloading the project, it is convenient to import from local files for modification.

import sys
import pandas as pd
# Find the file path of the tablegis you downloaded.
sys.path.insert(0, r'C:\Users\Administrator\Desktop\tablegis')
# Now it can be imported.
import tablegis as tg

Quick Start

Here is a simple example of how to use tablegis:

1. Find the nearest point (in df2) for each point in df1 and add its ID, longitude, latitude, and distance.

import pandas as pd
import tablegis as tg

# Create two example DataFrames
df1 = pd.DataFrame({
    'id': [1, 2, 3],
    'lon1': [116.404, 116.405, 116.406],
    'lat1': [39.915, 39.916, 39.917]
})

df2 = pd.DataFrame({
    'id': ['A', 'B', 'C', 'D'],
    'lon2': [116.403, 116.407, 116.404, 116.408],
    'lat2': [39.914, 39.918, 39.916, 39.919]
})

# Calculate the nearest 1 point
result = tg.min_distance_twotable(df1, df2, lon1='lon1', lat1='lat1', lon2='lon2', lat2='lat2', df2_id='id', n=1)
# Calculate the nearest 2 points
result2 = tg.min_distance_twotable(df1, df2, lon1='lon1', lat1='lat1', lon2='lon2', lat2='lat2', df2_id='id', n=2)

print("\nExample result (distance in meters):")
print(result)
print(result2)

Result Display:

Table df1:

id lon1 lat1
A 114.0 30.0
B 114.1 30.1

Table df2:

id lon2 lat2
p1 114.01 30.01
p2 114.05 30.05
p3 114.12 30.12

Nearest 1 point:

id lon1 lat1 nearest1_id nearest1_lon2 nearest1_lat2 nearest1_distance
A 114.0 30.0 p1 114.01 30.01 1470.515926
B 114.1 30.1 p3 114.12 30.12 2939.507557

Nearest 2 points:

id lon1 lat1 nearest1_id nearest1_lon2 nearest1_lat2 nearest1_distance nearest2_id nearest2_lon2 nearest2_lat2 nearest2_distance mean_distance
A 114.0 30.0 p1 114.01 30.01 1470.515926 p2 114.05 30.05 7351.852775 4411.184351
B 114.1 30.1 p3 114.12 30.12 2939.507557 p2 114.05 30.05 7350.037700 5144.772629

2. Find the nearest point for each point within the same table and add its ID, longitude, latitude, and distance.

import pandas as pd
import tablegis as tg

# Create an example DataFrame
df2 = pd.DataFrame({
    'id': ['A', 'B', 'C', 'D'],
    'lon2': [116.403, 116.407, 116.404, 116.408],
    'lat2': [39.914, 39.918, 39.916, 39.919]
})

# Calculate the nearest 1 point
result = tg.min_distance_onetable(df2, 'lon2', 'lat2', idname='id', n=1)
# Calculate the nearest 2 points
result2 = tg.min_distance_onetable(df2, 'lon2', 'lat2', idname='id', n=2)

print("\nExample result (distance in meters):")
print(result)
print(result2)

Result Display:

Table df2:

id lon2 lat2
p1 114.01 30.01
p2 114.05 30.05
p3 114.12 30.12

Nearest 1 point:

id lon2 lat2 nearest1_id nearest1_lon2 nearest1_lat2 nearest1_distance
0 p1 114.01 30.01 p2 114.05 30.05 5881.336911
1 p2 114.05 30.05 p1 114.01 30.01 5881.336911
2 p3 114.12 30.12 p2 114.05 30.05 10289.545038

Nearest 2 points:

id lon2 lat2 nearest1_id nearest1_lon2 nearest1_lat2 nearest1_distance nearest2_id nearest2_lon2 nearest2_lat2 nearest2_distance mean_distance
0 p1 114.01 30.01 p2 114.05 30.05 5881.336911 p3 114.12 30.12 16170.880987 11026.108949
1 p2 114.05 30.05 p1 114.01 30.01 5881.336911 p3 114.12 30.12 10289.545038 8085.440974
2 p3 114.12 30.12 p2 114.05 30.05 10289.545038 p1 114.01 30.01 16170.880987 13230.213012

Contributing

Contributions in all forms are welcome, including feature requests, bug reports, and code contributions.

License

This project is licensed under the MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tablegis-0.0.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tablegis-0.0.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file tablegis-0.0.1.tar.gz.

File metadata

  • Download URL: tablegis-0.0.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.8

File hashes

Hashes for tablegis-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2717f04d44330b43dbb487afa7d345bb08cc4bad8d27d7e2aefe42f6ff1a6863
MD5 ae95b4a6b027958e18b1af4f569d4c61
BLAKE2b-256 44a362d5b79ef05a98a67bbdfe8ac75966d4cff15bfb22649985c5efae8cd93b

See more details on using hashes here.

File details

Details for the file tablegis-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: tablegis-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.8

File hashes

Hashes for tablegis-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e48afeac0f9bca108ad287b5e392fb775f4aeefa4279e4e30d7236e637a170ad
MD5 158825037a2d09d9c77df1f195bcaf83
BLAKE2b-256 304038fe805e1233744a31714b4d912dc5b58f1bb532e758edad3838ce409fd0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

This release

0.0.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page