tablegis 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tablegis-0.0.1/LICENSE +21 -0
- tablegis-0.0.1/MANIFEST.in +5 -0
- tablegis-0.0.1/PKG-INFO +215 -0
- tablegis-0.0.1/README.md +168 -0
- tablegis-0.0.1/README_pypi.md +165 -0
- tablegis-0.0.1/pyproject.toml +40 -0
- tablegis-0.0.1/setup.cfg +4 -0
- tablegis-0.0.1/tablegis/__init__.py +21 -0
- tablegis-0.0.1/tablegis/core.py +311 -0
- tablegis-0.0.1/tablegis/utils.py +105 -0
- tablegis-0.0.1/tablegis.egg-info/PKG-INFO +215 -0
- tablegis-0.0.1/tablegis.egg-info/SOURCES.txt +14 -0
- tablegis-0.0.1/tablegis.egg-info/dependency_links.txt +1 -0
- tablegis-0.0.1/tablegis.egg-info/requires.txt +10 -0
- tablegis-0.0.1/tablegis.egg-info/top_level.txt +1 -0
- tablegis-0.0.1/tests/test_core.py +206 -0
tablegis-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Non-existent987
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tablegis-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tablegis
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A powerful Python library for geospatial data processing, analysis and conversion - integrating pandas with GIS operations
|
|
5
|
+
Author-email: Non-existent987 <jiaqi0425_000@163.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Non-existent987
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/Non-existent987/tablegis
|
|
29
|
+
Project-URL: Bug Tracker, https://github.com/Non-existent987/tablegis/issues
|
|
30
|
+
Project-URL: Repository, https://github.com/Non-existent987/tablegis.git
|
|
31
|
+
Keywords: gis,geospatial,pandas,geopandas,shapefile,kml,geojson,spatial-analysis,geographic,geometry,mapping
|
|
32
|
+
Classifier: Programming Language :: Python :: 3
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Operating System :: OS Independent
|
|
35
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
36
|
+
Requires-Python: >=3.7
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
License-File: LICENSE
|
|
39
|
+
Requires-Dist: geopandas
|
|
40
|
+
Requires-Dist: pandas
|
|
41
|
+
Requires-Dist: numpy
|
|
42
|
+
Requires-Dist: shapely
|
|
43
|
+
Requires-Dist: simplekml
|
|
44
|
+
Requires-Dist: pyshp
|
|
45
|
+
Requires-Dist: geographiclib
|
|
46
|
+
Requires-Dist: kml2geojson
|
|
47
|
+
Requires-Dist: scipy
|
|
48
|
+
Requires-Dist: pyproj
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
# tablegis
|
|
52
|
+
|
|
53
|
+
`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.
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
* **Distance Calculation**: Efficiently compute the nearest distance between DataFrames.
|
|
58
|
+
* **Spatial Analysis**: Create buffers (input in meters), Voronoi polygons, Delaunay triangulations, etc.
|
|
59
|
+
* **Format Conversion**: Easily convert between `GeoDataFrame` and formats like `Shapefile`, `KML`, etc.
|
|
60
|
+
* **Coordinate Aggregation**: Provides tools for aggregating coordinate points into grids.
|
|
61
|
+
* **Geometric Operations**: Includes merging polygons, calculating centroids, adding sectors, etc.
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
1、You can install `tablegis` from PyPI:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install tablegis
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
2、Or, install the latest version directly from the GitHub repository:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install git+https://github.com/Non-existent987/tablegis.git
|
|
75
|
+
```
|
|
76
|
+
3、After downloading the project, it is convenient to import from local files for modification.
|
|
77
|
+
```bash
|
|
78
|
+
import sys
|
|
79
|
+
import pandas as pd
|
|
80
|
+
# Find the file path of the tablegis you downloaded.
|
|
81
|
+
sys.path.insert(0, r'C:\Users\Administrator\Desktop\tablegis')
|
|
82
|
+
# Now it can be imported.
|
|
83
|
+
import tablegis as tg
|
|
84
|
+
```
|
|
85
|
+
## Quick Start
|
|
86
|
+
|
|
87
|
+
Here is a simple example of how to use `tablegis`:
|
|
88
|
+
|
|
89
|
+
### 1. Find the nearest point (in df2) for each point in df1 and add its ID, longitude, latitude, and distance.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import pandas as pd
|
|
93
|
+
import tablegis as tg
|
|
94
|
+
|
|
95
|
+
# Create two example DataFrames
|
|
96
|
+
df1 = pd.DataFrame({
|
|
97
|
+
'id': [1, 2, 3],
|
|
98
|
+
'lon1': [116.404, 116.405, 116.406],
|
|
99
|
+
'lat1': [39.915, 39.916, 39.917]
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
df2 = pd.DataFrame({
|
|
103
|
+
'id': ['A', 'B', 'C', 'D'],
|
|
104
|
+
'lon2': [116.403, 116.407, 116.404, 116.408],
|
|
105
|
+
'lat2': [39.914, 39.918, 39.916, 39.919]
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
# Calculate the nearest 1 point
|
|
109
|
+
result = tg.min_distance_twotable(df1, df2, lon1='lon1', lat1='lat1', lon2='lon2', lat2='lat2', df2_id='id', n=1)
|
|
110
|
+
# Calculate the nearest 2 points
|
|
111
|
+
result2 = tg.min_distance_twotable(df1, df2, lon1='lon1', lat1='lat1', lon2='lon2', lat2='lat2', df2_id='id', n=2)
|
|
112
|
+
|
|
113
|
+
print("\nExample result (distance in meters):")
|
|
114
|
+
print(result)
|
|
115
|
+
print(result2)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Result Display:**
|
|
119
|
+
|
|
120
|
+
<table>
|
|
121
|
+
<tr>
|
|
122
|
+
<td style="vertical-align: top; padding-right: 50px;">
|
|
123
|
+
|
|
124
|
+
**Table df1:**
|
|
125
|
+
|
|
126
|
+
| id | lon1 | lat1 |
|
|
127
|
+
|----|-------|------|
|
|
128
|
+
| A | 114.0 | 30.0 |
|
|
129
|
+
| B | 114.1 | 30.1 |
|
|
130
|
+
|
|
131
|
+
</td>
|
|
132
|
+
<td style="vertical-align: top;">
|
|
133
|
+
|
|
134
|
+
**Table df2:**
|
|
135
|
+
|
|
136
|
+
| id | lon2 | lat2 |
|
|
137
|
+
|----|--------|-------|
|
|
138
|
+
| p1 | 114.01 | 30.01 |
|
|
139
|
+
| p2 | 114.05 | 30.05 |
|
|
140
|
+
| p3 | 114.12 | 30.12 |
|
|
141
|
+
|
|
142
|
+
</td>
|
|
143
|
+
</tr>
|
|
144
|
+
</table>
|
|
145
|
+
|
|
146
|
+
**Nearest 1 point:**
|
|
147
|
+
|
|
148
|
+
| id | lon1 | lat1 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance |
|
|
149
|
+
|----|-------|------|-------------|---------------|---------------|-------------------|
|
|
150
|
+
| A | 114.0 | 30.0 | p1 | 114.01 | 30.01 | 1470.515926 |
|
|
151
|
+
| B | 114.1 | 30.1 | p3 | 114.12 | 30.12 | 2939.507557 |
|
|
152
|
+
|
|
153
|
+
**Nearest 2 points:**
|
|
154
|
+
|
|
155
|
+
| id | lon1 | lat1 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance | nearest2_id | nearest2_lon2 | nearest2_lat2 | nearest2_distance | mean_distance |
|
|
156
|
+
|----|-------|------|-------------|---------------|---------------|-------------------|-------------|---------------|---------------|-------------------|---------------|
|
|
157
|
+
| A | 114.0 | 30.0 | p1 | 114.01 | 30.01 | 1470.515926 | p2 | 114.05 | 30.05 | 7351.852775 | 4411.184351 |
|
|
158
|
+
| B | 114.1 | 30.1 | p3 | 114.12 | 30.12 | 2939.507557 | p2 | 114.05 | 30.05 | 7350.037700 | 5144.772629 |
|
|
159
|
+
|
|
160
|
+
### 2. Find the nearest point for each point within the same table and add its ID, longitude, latitude, and distance.
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
import pandas as pd
|
|
164
|
+
import tablegis as tg
|
|
165
|
+
|
|
166
|
+
# Create an example DataFrame
|
|
167
|
+
df2 = pd.DataFrame({
|
|
168
|
+
'id': ['A', 'B', 'C', 'D'],
|
|
169
|
+
'lon2': [116.403, 116.407, 116.404, 116.408],
|
|
170
|
+
'lat2': [39.914, 39.918, 39.916, 39.919]
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
# Calculate the nearest 1 point
|
|
174
|
+
result = tg.min_distance_onetable(df2, 'lon2', 'lat2', idname='id', n=1)
|
|
175
|
+
# Calculate the nearest 2 points
|
|
176
|
+
result2 = tg.min_distance_onetable(df2, 'lon2', 'lat2', idname='id', n=2)
|
|
177
|
+
|
|
178
|
+
print("\nExample result (distance in meters):")
|
|
179
|
+
print(result)
|
|
180
|
+
print(result2)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**Result Display:**
|
|
184
|
+
|
|
185
|
+
**Table df2:**
|
|
186
|
+
|
|
187
|
+
| id | lon2 | lat2 |
|
|
188
|
+
|----|--------|-------|
|
|
189
|
+
| p1 | 114.01 | 30.01 |
|
|
190
|
+
| p2 | 114.05 | 30.05 |
|
|
191
|
+
| p3 | 114.12 | 30.12 |
|
|
192
|
+
|
|
193
|
+
**Nearest 1 point:**
|
|
194
|
+
|
|
195
|
+
| | id | lon2 | lat2 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance |
|
|
196
|
+
|---:|----|--------|-------|-------------|---------------|---------------|-------------------|
|
|
197
|
+
| 0 | p1 | 114.01 | 30.01 | p2 | 114.05 | 30.05 | 5881.336911 |
|
|
198
|
+
| 1 | p2 | 114.05 | 30.05 | p1 | 114.01 | 30.01 | 5881.336911 |
|
|
199
|
+
| 2 | p3 | 114.12 | 30.12 | p2 | 114.05 | 30.05 | 10289.545038 |
|
|
200
|
+
|
|
201
|
+
**Nearest 2 points:**
|
|
202
|
+
|
|
203
|
+
| | id | lon2 | lat2 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance | nearest2_id | nearest2_lon2 | nearest2_lat2 | nearest2_distance | mean_distance |
|
|
204
|
+
|---:|----|--------|-------|-------------|---------------|---------------|-------------------|-------------|---------------|---------------|-------------------|---------------|
|
|
205
|
+
| 0 | p1 | 114.01 | 30.01 | p2 | 114.05 | 30.05 | 5881.336911 | p3 | 114.12 | 30.12 | 16170.880987 | 11026.108949 |
|
|
206
|
+
| 1 | p2 | 114.05 | 30.05 | p1 | 114.01 | 30.01 | 5881.336911 | p3 | 114.12 | 30.12 | 10289.545038 | 8085.440974 |
|
|
207
|
+
| 2 | p3 | 114.12 | 30.12 | p2 | 114.05 | 30.05 | 10289.545038 | p1 | 114.01 | 30.01 | 16170.880987 | 13230.213012 |
|
|
208
|
+
|
|
209
|
+
## Contributing
|
|
210
|
+
|
|
211
|
+
Contributions in all forms are welcome, including feature requests, bug reports, and code contributions.
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
This project is licensed under the MIT License.
|
tablegis-0.0.1/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# tablegis
|
|
2
|
+
|
|
3
|
+
[English](README.md) | [简体中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
`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.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
* **Distance Calculation**: Efficiently compute the nearest distance between DataFrames.
|
|
10
|
+
* **Spatial Analysis**: Create buffers (input in meters), Voronoi polygons, Delaunay triangulations, etc.
|
|
11
|
+
* **Format Conversion**: Easily convert between `GeoDataFrame` and formats like `Shapefile`, `KML`, etc.
|
|
12
|
+
* **Coordinate Aggregation**: Provides tools for aggregating coordinate points into grids.
|
|
13
|
+
* **Geometric Operations**: Includes merging polygons, calculating centroids, adding sectors, etc.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
1、You can install `tablegis` from PyPI:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install tablegis
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
2、Or, install the latest version directly from the GitHub repository:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install git+https://github.com/Non-existent987/tablegis.git
|
|
27
|
+
```
|
|
28
|
+
3、After downloading the project, it is convenient to import from local files for modification.
|
|
29
|
+
```bash
|
|
30
|
+
import sys
|
|
31
|
+
import pandas as pd
|
|
32
|
+
# Find the file path of the tablegis you downloaded.
|
|
33
|
+
sys.path.insert(0, r'C:\Users\Administrator\Desktop\tablegis')
|
|
34
|
+
# Now it can be imported.
|
|
35
|
+
import tablegis as tg
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
Here is a simple example of how to use `tablegis`:
|
|
41
|
+
|
|
42
|
+
### 1. Find the nearest point (in df2) for each point in df1 and add its ID, longitude, latitude, and distance.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import pandas as pd
|
|
46
|
+
import tablegis as tg
|
|
47
|
+
|
|
48
|
+
# Create two example DataFrames
|
|
49
|
+
df1 = pd.DataFrame({
|
|
50
|
+
'id': [1, 2, 3],
|
|
51
|
+
'lon1': [116.404, 116.405, 116.406],
|
|
52
|
+
'lat1': [39.915, 39.916, 39.917]
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
df2 = pd.DataFrame({
|
|
56
|
+
'id': ['A', 'B', 'C', 'D'],
|
|
57
|
+
'lon2': [116.403, 116.407, 116.404, 116.408],
|
|
58
|
+
'lat2': [39.914, 39.918, 39.916, 39.919]
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
# Calculate the nearest 1 point
|
|
62
|
+
result = tg.min_distance_twotable(df1, df2, lon1='lon1', lat1='lat1', lon2='lon2', lat2='lat2', df2_id='id', n=1)
|
|
63
|
+
# Calculate the nearest 2 points
|
|
64
|
+
result2 = tg.min_distance_twotable(df1, df2, lon1='lon1', lat1='lat1', lon2='lon2', lat2='lat2', df2_id='id', n=2)
|
|
65
|
+
|
|
66
|
+
print("\nExample result (distance in meters):")
|
|
67
|
+
print(result)
|
|
68
|
+
print(result2)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Result Display:**
|
|
72
|
+
|
|
73
|
+
<table>
|
|
74
|
+
<tr>
|
|
75
|
+
<td style="vertical-align: top; padding-right: 50px;">
|
|
76
|
+
|
|
77
|
+
**Table df1:**
|
|
78
|
+
|
|
79
|
+
| id | lon1 | lat1 |
|
|
80
|
+
|----|-------|------|
|
|
81
|
+
| A | 114.0 | 30.0 |
|
|
82
|
+
| B | 114.1 | 30.1 |
|
|
83
|
+
|
|
84
|
+
</td>
|
|
85
|
+
<td style="vertical-align: top;">
|
|
86
|
+
|
|
87
|
+
**Table df2:**
|
|
88
|
+
|
|
89
|
+
| id | lon2 | lat2 |
|
|
90
|
+
|----|--------|-------|
|
|
91
|
+
| p1 | 114.01 | 30.01 |
|
|
92
|
+
| p2 | 114.05 | 30.05 |
|
|
93
|
+
| p3 | 114.12 | 30.12 |
|
|
94
|
+
|
|
95
|
+
</td>
|
|
96
|
+
</tr>
|
|
97
|
+
</table>
|
|
98
|
+
|
|
99
|
+
**Nearest 1 point:**
|
|
100
|
+
|
|
101
|
+
| id | lon1 | lat1 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance |
|
|
102
|
+
|----|-------|------|-------------|---------------|---------------|-------------------|
|
|
103
|
+
| A | 114.0 | 30.0 | p1 | 114.01 | 30.01 | 1470.515926 |
|
|
104
|
+
| B | 114.1 | 30.1 | p3 | 114.12 | 30.12 | 2939.507557 |
|
|
105
|
+
|
|
106
|
+
**Nearest 2 points:**
|
|
107
|
+
|
|
108
|
+
| id | lon1 | lat1 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance | nearest2_id | nearest2_lon2 | nearest2_lat2 | nearest2_distance | mean_distance |
|
|
109
|
+
|----|-------|------|-------------|---------------|---------------|-------------------|-------------|---------------|---------------|-------------------|---------------|
|
|
110
|
+
| A | 114.0 | 30.0 | p1 | 114.01 | 30.01 | 1470.515926 | p2 | 114.05 | 30.05 | 7351.852775 | 4411.184351 |
|
|
111
|
+
| B | 114.1 | 30.1 | p3 | 114.12 | 30.12 | 2939.507557 | p2 | 114.05 | 30.05 | 7350.037700 | 5144.772629 |
|
|
112
|
+
|
|
113
|
+
### 2. Find the nearest point for each point within the same table and add its ID, longitude, latitude, and distance.
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
import pandas as pd
|
|
117
|
+
import tablegis as tg
|
|
118
|
+
|
|
119
|
+
# Create an example DataFrame
|
|
120
|
+
df2 = pd.DataFrame({
|
|
121
|
+
'id': ['A', 'B', 'C', 'D'],
|
|
122
|
+
'lon2': [116.403, 116.407, 116.404, 116.408],
|
|
123
|
+
'lat2': [39.914, 39.918, 39.916, 39.919]
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
# Calculate the nearest 1 point
|
|
127
|
+
result = tg.min_distance_onetable(df2, 'lon2', 'lat2', idname='id', n=1)
|
|
128
|
+
# Calculate the nearest 2 points
|
|
129
|
+
result2 = tg.min_distance_onetable(df2, 'lon2', 'lat2', idname='id', n=2)
|
|
130
|
+
|
|
131
|
+
print("\nExample result (distance in meters):")
|
|
132
|
+
print(result)
|
|
133
|
+
print(result2)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Result Display:**
|
|
137
|
+
|
|
138
|
+
**Table df2:**
|
|
139
|
+
|
|
140
|
+
| id | lon2 | lat2 |
|
|
141
|
+
|----|--------|-------|
|
|
142
|
+
| p1 | 114.01 | 30.01 |
|
|
143
|
+
| p2 | 114.05 | 30.05 |
|
|
144
|
+
| p3 | 114.12 | 30.12 |
|
|
145
|
+
|
|
146
|
+
**Nearest 1 point:**
|
|
147
|
+
|
|
148
|
+
| | id | lon2 | lat2 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance |
|
|
149
|
+
|---:|----|--------|-------|-------------|---------------|---------------|-------------------|
|
|
150
|
+
| 0 | p1 | 114.01 | 30.01 | p2 | 114.05 | 30.05 | 5881.336911 |
|
|
151
|
+
| 1 | p2 | 114.05 | 30.05 | p1 | 114.01 | 30.01 | 5881.336911 |
|
|
152
|
+
| 2 | p3 | 114.12 | 30.12 | p2 | 114.05 | 30.05 | 10289.545038 |
|
|
153
|
+
|
|
154
|
+
**Nearest 2 points:**
|
|
155
|
+
|
|
156
|
+
| | id | lon2 | lat2 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance | nearest2_id | nearest2_lon2 | nearest2_lat2 | nearest2_distance | mean_distance |
|
|
157
|
+
|---:|----|--------|-------|-------------|---------------|---------------|-------------------|-------------|---------------|---------------|-------------------|---------------|
|
|
158
|
+
| 0 | p1 | 114.01 | 30.01 | p2 | 114.05 | 30.05 | 5881.336911 | p3 | 114.12 | 30.12 | 16170.880987 | 11026.108949 |
|
|
159
|
+
| 1 | p2 | 114.05 | 30.05 | p1 | 114.01 | 30.01 | 5881.336911 | p3 | 114.12 | 30.12 | 10289.545038 | 8085.440974 |
|
|
160
|
+
| 2 | p3 | 114.12 | 30.12 | p2 | 114.05 | 30.05 | 10289.545038 | p1 | 114.01 | 30.01 | 16170.880987 | 13230.213012 |
|
|
161
|
+
|
|
162
|
+
## Contributing
|
|
163
|
+
|
|
164
|
+
Contributions in all forms are welcome, including feature requests, bug reports, and code contributions.
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# tablegis
|
|
2
|
+
|
|
3
|
+
`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.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
* **Distance Calculation**: Efficiently compute the nearest distance between DataFrames.
|
|
8
|
+
* **Spatial Analysis**: Create buffers (input in meters), Voronoi polygons, Delaunay triangulations, etc.
|
|
9
|
+
* **Format Conversion**: Easily convert between `GeoDataFrame` and formats like `Shapefile`, `KML`, etc.
|
|
10
|
+
* **Coordinate Aggregation**: Provides tools for aggregating coordinate points into grids.
|
|
11
|
+
* **Geometric Operations**: Includes merging polygons, calculating centroids, adding sectors, etc.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
1、You can install `tablegis` from PyPI:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install tablegis
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2、Or, install the latest version directly from the GitHub repository:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install git+https://github.com/Non-existent987/tablegis.git
|
|
25
|
+
```
|
|
26
|
+
3、After downloading the project, it is convenient to import from local files for modification.
|
|
27
|
+
```bash
|
|
28
|
+
import sys
|
|
29
|
+
import pandas as pd
|
|
30
|
+
# Find the file path of the tablegis you downloaded.
|
|
31
|
+
sys.path.insert(0, r'C:\Users\Administrator\Desktop\tablegis')
|
|
32
|
+
# Now it can be imported.
|
|
33
|
+
import tablegis as tg
|
|
34
|
+
```
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
Here is a simple example of how to use `tablegis`:
|
|
38
|
+
|
|
39
|
+
### 1. Find the nearest point (in df2) for each point in df1 and add its ID, longitude, latitude, and distance.
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import pandas as pd
|
|
43
|
+
import tablegis as tg
|
|
44
|
+
|
|
45
|
+
# Create two example DataFrames
|
|
46
|
+
df1 = pd.DataFrame({
|
|
47
|
+
'id': [1, 2, 3],
|
|
48
|
+
'lon1': [116.404, 116.405, 116.406],
|
|
49
|
+
'lat1': [39.915, 39.916, 39.917]
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
df2 = pd.DataFrame({
|
|
53
|
+
'id': ['A', 'B', 'C', 'D'],
|
|
54
|
+
'lon2': [116.403, 116.407, 116.404, 116.408],
|
|
55
|
+
'lat2': [39.914, 39.918, 39.916, 39.919]
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
# Calculate the nearest 1 point
|
|
59
|
+
result = tg.min_distance_twotable(df1, df2, lon1='lon1', lat1='lat1', lon2='lon2', lat2='lat2', df2_id='id', n=1)
|
|
60
|
+
# Calculate the nearest 2 points
|
|
61
|
+
result2 = tg.min_distance_twotable(df1, df2, lon1='lon1', lat1='lat1', lon2='lon2', lat2='lat2', df2_id='id', n=2)
|
|
62
|
+
|
|
63
|
+
print("\nExample result (distance in meters):")
|
|
64
|
+
print(result)
|
|
65
|
+
print(result2)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Result Display:**
|
|
69
|
+
|
|
70
|
+
<table>
|
|
71
|
+
<tr>
|
|
72
|
+
<td style="vertical-align: top; padding-right: 50px;">
|
|
73
|
+
|
|
74
|
+
**Table df1:**
|
|
75
|
+
|
|
76
|
+
| id | lon1 | lat1 |
|
|
77
|
+
|----|-------|------|
|
|
78
|
+
| A | 114.0 | 30.0 |
|
|
79
|
+
| B | 114.1 | 30.1 |
|
|
80
|
+
|
|
81
|
+
</td>
|
|
82
|
+
<td style="vertical-align: top;">
|
|
83
|
+
|
|
84
|
+
**Table df2:**
|
|
85
|
+
|
|
86
|
+
| id | lon2 | lat2 |
|
|
87
|
+
|----|--------|-------|
|
|
88
|
+
| p1 | 114.01 | 30.01 |
|
|
89
|
+
| p2 | 114.05 | 30.05 |
|
|
90
|
+
| p3 | 114.12 | 30.12 |
|
|
91
|
+
|
|
92
|
+
</td>
|
|
93
|
+
</tr>
|
|
94
|
+
</table>
|
|
95
|
+
|
|
96
|
+
**Nearest 1 point:**
|
|
97
|
+
|
|
98
|
+
| id | lon1 | lat1 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance |
|
|
99
|
+
|----|-------|------|-------------|---------------|---------------|-------------------|
|
|
100
|
+
| A | 114.0 | 30.0 | p1 | 114.01 | 30.01 | 1470.515926 |
|
|
101
|
+
| B | 114.1 | 30.1 | p3 | 114.12 | 30.12 | 2939.507557 |
|
|
102
|
+
|
|
103
|
+
**Nearest 2 points:**
|
|
104
|
+
|
|
105
|
+
| id | lon1 | lat1 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance | nearest2_id | nearest2_lon2 | nearest2_lat2 | nearest2_distance | mean_distance |
|
|
106
|
+
|----|-------|------|-------------|---------------|---------------|-------------------|-------------|---------------|---------------|-------------------|---------------|
|
|
107
|
+
| A | 114.0 | 30.0 | p1 | 114.01 | 30.01 | 1470.515926 | p2 | 114.05 | 30.05 | 7351.852775 | 4411.184351 |
|
|
108
|
+
| B | 114.1 | 30.1 | p3 | 114.12 | 30.12 | 2939.507557 | p2 | 114.05 | 30.05 | 7350.037700 | 5144.772629 |
|
|
109
|
+
|
|
110
|
+
### 2. Find the nearest point for each point within the same table and add its ID, longitude, latitude, and distance.
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
import pandas as pd
|
|
114
|
+
import tablegis as tg
|
|
115
|
+
|
|
116
|
+
# Create an example DataFrame
|
|
117
|
+
df2 = pd.DataFrame({
|
|
118
|
+
'id': ['A', 'B', 'C', 'D'],
|
|
119
|
+
'lon2': [116.403, 116.407, 116.404, 116.408],
|
|
120
|
+
'lat2': [39.914, 39.918, 39.916, 39.919]
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
# Calculate the nearest 1 point
|
|
124
|
+
result = tg.min_distance_onetable(df2, 'lon2', 'lat2', idname='id', n=1)
|
|
125
|
+
# Calculate the nearest 2 points
|
|
126
|
+
result2 = tg.min_distance_onetable(df2, 'lon2', 'lat2', idname='id', n=2)
|
|
127
|
+
|
|
128
|
+
print("\nExample result (distance in meters):")
|
|
129
|
+
print(result)
|
|
130
|
+
print(result2)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Result Display:**
|
|
134
|
+
|
|
135
|
+
**Table df2:**
|
|
136
|
+
|
|
137
|
+
| id | lon2 | lat2 |
|
|
138
|
+
|----|--------|-------|
|
|
139
|
+
| p1 | 114.01 | 30.01 |
|
|
140
|
+
| p2 | 114.05 | 30.05 |
|
|
141
|
+
| p3 | 114.12 | 30.12 |
|
|
142
|
+
|
|
143
|
+
**Nearest 1 point:**
|
|
144
|
+
|
|
145
|
+
| | id | lon2 | lat2 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance |
|
|
146
|
+
|---:|----|--------|-------|-------------|---------------|---------------|-------------------|
|
|
147
|
+
| 0 | p1 | 114.01 | 30.01 | p2 | 114.05 | 30.05 | 5881.336911 |
|
|
148
|
+
| 1 | p2 | 114.05 | 30.05 | p1 | 114.01 | 30.01 | 5881.336911 |
|
|
149
|
+
| 2 | p3 | 114.12 | 30.12 | p2 | 114.05 | 30.05 | 10289.545038 |
|
|
150
|
+
|
|
151
|
+
**Nearest 2 points:**
|
|
152
|
+
|
|
153
|
+
| | id | lon2 | lat2 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance | nearest2_id | nearest2_lon2 | nearest2_lat2 | nearest2_distance | mean_distance |
|
|
154
|
+
|---:|----|--------|-------|-------------|---------------|---------------|-------------------|-------------|---------------|---------------|-------------------|---------------|
|
|
155
|
+
| 0 | p1 | 114.01 | 30.01 | p2 | 114.05 | 30.05 | 5881.336911 | p3 | 114.12 | 30.12 | 16170.880987 | 11026.108949 |
|
|
156
|
+
| 1 | p2 | 114.05 | 30.05 | p1 | 114.01 | 30.01 | 5881.336911 | p3 | 114.12 | 30.12 | 10289.545038 | 8085.440974 |
|
|
157
|
+
| 2 | p3 | 114.12 | 30.12 | p2 | 114.05 | 30.05 | 10289.545038 | p1 | 114.01 | 30.01 | 16170.880987 | 13230.213012 |
|
|
158
|
+
|
|
159
|
+
## Contributing
|
|
160
|
+
|
|
161
|
+
Contributions in all forms are welcome, including feature requests, bug reports, and code contributions.
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
This project is licensed under the MIT License.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tablegis"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
keywords = [
|
|
9
|
+
"gis", "geospatial", "pandas", "geopandas",
|
|
10
|
+
"shapefile", "kml", "geojson", "spatial-analysis",
|
|
11
|
+
"geographic", "geometry", "mapping"
|
|
12
|
+
]
|
|
13
|
+
description = "A powerful Python library for geospatial data processing, analysis and conversion - integrating pandas with GIS operations"
|
|
14
|
+
readme = "README_pypi.md"
|
|
15
|
+
authors = [{name = "Non-existent987", email = "jiaqi0425_000@163.com"}]
|
|
16
|
+
license = { file = "LICENSE" }
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Topic :: Scientific/Engineering :: GIS",
|
|
22
|
+
]
|
|
23
|
+
requires-python = ">=3.7"
|
|
24
|
+
dependencies = [
|
|
25
|
+
"geopandas",
|
|
26
|
+
"pandas",
|
|
27
|
+
"numpy",
|
|
28
|
+
"shapely",
|
|
29
|
+
"simplekml",
|
|
30
|
+
"pyshp",
|
|
31
|
+
"geographiclib",
|
|
32
|
+
"kml2geojson",
|
|
33
|
+
"scipy",
|
|
34
|
+
"pyproj",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
"Homepage" = "https://github.com/Non-existent987/tablegis"
|
|
39
|
+
"Bug Tracker" = "https://github.com/Non-existent987/tablegis/issues"
|
|
40
|
+
"Repository" = "https://github.com/Non-existent987/tablegis.git"
|
tablegis-0.0.1/setup.cfg
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
import pkgutil
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
# 获取当前包的路径
|
|
6
|
+
pkg_path = Path(__file__).parent
|
|
7
|
+
|
|
8
|
+
# 自动发现并导出所有模块中的函数
|
|
9
|
+
__all__ = []
|
|
10
|
+
for _, module_name, _ in pkgutil.iter_modules([str(pkg_path)]):
|
|
11
|
+
# 导入模块
|
|
12
|
+
module = __import__(f"{__name__}.{module_name}", fromlist=["*"])
|
|
13
|
+
# 遍历模块中的成员
|
|
14
|
+
for name, obj in inspect.getmembers(module):
|
|
15
|
+
# 只导出函数,并且不是私有函数(不以下划线开头)
|
|
16
|
+
if inspect.isfunction(obj) and not name.startswith('_'):
|
|
17
|
+
# 将函数添加到当前命名空间
|
|
18
|
+
globals()[name] = obj
|
|
19
|
+
# 将函数名添加到 __all__
|
|
20
|
+
if name not in __all__:
|
|
21
|
+
__all__.append(name)
|