tablegis 0.0.11__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.11/LICENSE +21 -0
- tablegis-0.0.11/MANIFEST.in +5 -0
- tablegis-0.0.11/PKG-INFO +390 -0
- tablegis-0.0.11/README.md +337 -0
- tablegis-0.0.11/README_pypi.md +331 -0
- tablegis-0.0.11/pyproject.toml +51 -0
- tablegis-0.0.11/setup.cfg +4 -0
- tablegis-0.0.11/tablegis/__init__.py +38 -0
- tablegis-0.0.11/tablegis/core.py +685 -0
- tablegis-0.0.11/tablegis/tmp.wav +0 -0
- tablegis-0.0.11/tablegis/utils.py +397 -0
- tablegis-0.0.11/tablegis.egg-info/PKG-INFO +390 -0
- tablegis-0.0.11/tablegis.egg-info/SOURCES.txt +15 -0
- tablegis-0.0.11/tablegis.egg-info/dependency_links.txt +1 -0
- tablegis-0.0.11/tablegis.egg-info/requires.txt +10 -0
- tablegis-0.0.11/tablegis.egg-info/top_level.txt +1 -0
- tablegis-0.0.11/tests/test_core.py +499 -0
tablegis-0.0.11/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.11/PKG-INFO
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tablegis
|
|
3
|
+
Version: 0.0.11
|
|
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
|
+
Project-URL: Changelog, https://github.com/Non-existent987/tablegis/blob/main/CHANGELOG.md
|
|
32
|
+
Keywords: gis,tablegeo,pandas,geopandas,shapefile,Nearest,crs
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: Intended Audience :: Science/Research
|
|
36
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
37
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
38
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
39
|
+
Classifier: Programming Language :: Python :: 3
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
44
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
45
|
+
Classifier: Operating System :: OS Independent
|
|
46
|
+
Requires-Python: >=3.8
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
License-File: LICENSE
|
|
49
|
+
Requires-Dist: pandas
|
|
50
|
+
Requires-Dist: numpy
|
|
51
|
+
Requires-Dist: scipy
|
|
52
|
+
Requires-Dist: pyproj
|
|
53
|
+
Requires-Dist: geopandas
|
|
54
|
+
Requires-Dist: shapely
|
|
55
|
+
Provides-Extra: dev
|
|
56
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
57
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
58
|
+
Dynamic: license-file
|
|
59
|
+
|
|
60
|
+
# tablegis
|
|
61
|
+
|
|
62
|
+
`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.
|
|
63
|
+
|
|
64
|
+
## Features
|
|
65
|
+
|
|
66
|
+
* **Distance Calculation**: Efficiently compute the nearest distance between DataFrames.
|
|
67
|
+
* **Spatial Analysis**: Create buffers (input in meters), Voronoi polygons, Delaunay triangulations, etc.
|
|
68
|
+
* **Format Conversion**: Easily convert between `GeoDataFrame` and formats like `Shapefile`, `KML`, etc.
|
|
69
|
+
* **Coordinate Aggregation**: Provides tools for aggregating coordinate points into grids.
|
|
70
|
+
* **Geometric Operations**: Includes merging polygons, calculating centroids, adding sectors, etc.
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
1、You can install `tablegis` from PyPI:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install tablegis
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
2、Or, install the latest version directly from the GitHub repository:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install git+https://github.com/Non-existent987/tablegis.git
|
|
84
|
+
```
|
|
85
|
+
3、After downloading the project, it is convenient to import from local files for modification.
|
|
86
|
+
```bash
|
|
87
|
+
import sys
|
|
88
|
+
import pandas as pd
|
|
89
|
+
# Find the file path of the tablegis you downloaded.
|
|
90
|
+
sys.path.insert(0, r'C:\Users\Administrator\Desktop\tablegis')
|
|
91
|
+
# Now it can be imported.
|
|
92
|
+
import tablegis as tg
|
|
93
|
+
```
|
|
94
|
+
## Quick Start
|
|
95
|
+
|
|
96
|
+
Here is a simple example of how to use `tablegis`:
|
|
97
|
+
|
|
98
|
+
### 1. Find the nearest point (in df2) for each point in df1 and add its ID, longitude, latitude, and distance.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
import pandas as pd
|
|
102
|
+
import tablegis as tg
|
|
103
|
+
|
|
104
|
+
# Create two example DataFrames
|
|
105
|
+
df1 = pd.DataFrame({
|
|
106
|
+
'id': [1, 2, 3],
|
|
107
|
+
'lon1': [116.404, 116.405, 116.406],
|
|
108
|
+
'lat1': [39.915, 39.916, 39.917]
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
df2 = pd.DataFrame({
|
|
112
|
+
'id': ['A', 'B', 'C', 'D'],
|
|
113
|
+
'lon2': [116.403, 116.407, 116.404, 116.408],
|
|
114
|
+
'lat2': [39.914, 39.918, 39.916, 39.919]
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
# Calculate the nearest 1 point
|
|
118
|
+
result = tg.min_distance_twotable(df1, df2, lon1='lon1', lat1='lat1', lon2='lon2', lat2='lat2', df2_id='id', n=1)
|
|
119
|
+
# Calculate the nearest 2 points
|
|
120
|
+
result2 = tg.min_distance_twotable(df1, df2, lon1='lon1', lat1='lat1', lon2='lon2', lat2='lat2', df2_id='id', n=2)
|
|
121
|
+
|
|
122
|
+
print("\nExample result (distance in meters):")
|
|
123
|
+
print(result)
|
|
124
|
+
print(result2)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Result Display:**
|
|
128
|
+
|
|
129
|
+
<table>
|
|
130
|
+
<tr>
|
|
131
|
+
<td style="vertical-align: top; padding-right: 50px;">
|
|
132
|
+
|
|
133
|
+
**Table df1:**
|
|
134
|
+
|
|
135
|
+
| id | lon1 | lat1 |
|
|
136
|
+
|----|-------|------|
|
|
137
|
+
| A | 114.0 | 30.0 |
|
|
138
|
+
| B | 114.1 | 30.1 |
|
|
139
|
+
|
|
140
|
+
</td>
|
|
141
|
+
<td style="vertical-align: top;">
|
|
142
|
+
|
|
143
|
+
**Table df2:**
|
|
144
|
+
|
|
145
|
+
| id | lon2 | lat2 |
|
|
146
|
+
|----|--------|-------|
|
|
147
|
+
| p1 | 114.01 | 30.01 |
|
|
148
|
+
| p2 | 114.05 | 30.05 |
|
|
149
|
+
| p3 | 114.12 | 30.12 |
|
|
150
|
+
|
|
151
|
+
</td>
|
|
152
|
+
</tr>
|
|
153
|
+
</table>
|
|
154
|
+
|
|
155
|
+
**Nearest 1 point:**
|
|
156
|
+
|
|
157
|
+
| id | lon1 | lat1 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance |
|
|
158
|
+
|----|-------|------|-------------|---------------|---------------|-------------------|
|
|
159
|
+
| A | 114.0 | 30.0 | p1 | 114.01 | 30.01 | 1470.515926 |
|
|
160
|
+
| B | 114.1 | 30.1 | p3 | 114.12 | 30.12 | 2939.507557 |
|
|
161
|
+
|
|
162
|
+
**Nearest 2 points:**
|
|
163
|
+
|
|
164
|
+
| id | lon1 | lat1 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance | nearest2_id | nearest2_lon2 | nearest2_lat2 | nearest2_distance | mean_distance |
|
|
165
|
+
|----|-------|------|-------------|---------------|---------------|-------------------|-------------|---------------|---------------|-------------------|---------------|
|
|
166
|
+
| A | 114.0 | 30.0 | p1 | 114.01 | 30.01 | 1470.515926 | p2 | 114.05 | 30.05 | 7351.852775 | 4411.184351 |
|
|
167
|
+
| B | 114.1 | 30.1 | p3 | 114.12 | 30.12 | 2939.507557 | p2 | 114.05 | 30.05 | 7350.037700 | 5144.772629 |
|
|
168
|
+
|
|
169
|
+
### 2. Find the nearest point for each point within the same table and add its ID, longitude, latitude, and distance.
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
import pandas as pd
|
|
173
|
+
import tablegis as tg
|
|
174
|
+
|
|
175
|
+
# Create an example DataFrame
|
|
176
|
+
df2 = pd.DataFrame({
|
|
177
|
+
'id': ['A', 'B', 'C', 'D'],
|
|
178
|
+
'lon2': [116.403, 116.407, 116.404, 116.408],
|
|
179
|
+
'lat2': [39.914, 39.918, 39.916, 39.919]
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
# Calculate the nearest 1 point
|
|
183
|
+
result = tg.min_distance_onetable(df2, 'lon2', 'lat2', idname='id', n=1)
|
|
184
|
+
# Calculate the nearest 2 points
|
|
185
|
+
result2 = tg.min_distance_onetable(df2, 'lon2', 'lat2', idname='id', n=2)
|
|
186
|
+
|
|
187
|
+
print("\nExample result (distance in meters):")
|
|
188
|
+
print(result)
|
|
189
|
+
print(result2)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Result Display:**
|
|
193
|
+
|
|
194
|
+
**Table df2:**
|
|
195
|
+
|
|
196
|
+
| id | lon2 | lat2 |
|
|
197
|
+
|----|--------|-------|
|
|
198
|
+
| p1 | 114.01 | 30.01 |
|
|
199
|
+
| p2 | 114.05 | 30.05 |
|
|
200
|
+
| p3 | 114.12 | 30.12 |
|
|
201
|
+
|
|
202
|
+
**Nearest 1 point:**
|
|
203
|
+
|
|
204
|
+
| | id | lon2 | lat2 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance |
|
|
205
|
+
|---:|----|--------|-------|-------------|---------------|---------------|-------------------|
|
|
206
|
+
| 0 | p1 | 114.01 | 30.01 | p2 | 114.05 | 30.05 | 5881.336911 |
|
|
207
|
+
| 1 | p2 | 114.05 | 30.05 | p1 | 114.01 | 30.01 | 5881.336911 |
|
|
208
|
+
| 2 | p3 | 114.12 | 30.12 | p2 | 114.05 | 30.05 | 10289.545038 |
|
|
209
|
+
|
|
210
|
+
**Nearest 2 points:**
|
|
211
|
+
|
|
212
|
+
| | id | lon2 | lat2 | nearest1_id | nearest1_lon2 | nearest1_lat2 | nearest1_distance | nearest2_id | nearest2_lon2 | nearest2_lat2 | nearest2_distance | mean_distance |
|
|
213
|
+
|---:|----|--------|-------|-------------|---------------|---------------|-------------------|-------------|---------------|---------------|-------------------|---------------|
|
|
214
|
+
| 0 | p1 | 114.01 | 30.01 | p2 | 114.05 | 30.05 | 5881.336911 | p3 | 114.12 | 30.12 | 16170.880987 | 11026.108949 |
|
|
215
|
+
| 1 | p2 | 114.05 | 30.05 | p1 | 114.01 | 30.01 | 5881.336911 | p3 | 114.12 | 30.12 | 10289.545038 | 8085.440974 |
|
|
216
|
+
| 2 | p3 | 114.12 | 30.12 | p2 | 114.05 | 30.05 | 10289.545038 | p1 | 114.01 | 30.01 | 16170.880987 | 13230.213012 |
|
|
217
|
+
|
|
218
|
+
### 3、Replace the longitude and latitude columns in the table with the corresponding values in another coordinate system, and add a new column for longitude and latitude.
|
|
219
|
+
```python
|
|
220
|
+
import pandas as pd
|
|
221
|
+
import tablegis as tg
|
|
222
|
+
|
|
223
|
+
# Create two sample DataFrames
|
|
224
|
+
df = pd.DataFrame({
|
|
225
|
+
'id': ['A', 'B', 'C', 'D'],
|
|
226
|
+
'lon': [116.403, 116.407, 116.404, 116.408],
|
|
227
|
+
'lat': [39.914, 39.918, 39.916, 39.919]
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
# Convert the latitude and longitude in the 84 coordinate system to the latitude and longitude in the web_mercator system.
|
|
231
|
+
result = tg.to_lonlat(df,'lon','lat', from_crs="wgs84", to_crs="web_mercator")
|
|
232
|
+
print(result)
|
|
233
|
+
```
|
|
234
|
+
**Result Display:**
|
|
235
|
+
**Added two columns of "web_mercator":**
|
|
236
|
+
| id | lon | lat | web_mercator_lon | web_mercator_lat |
|
|
237
|
+
| --- | -------- | -------- | ---------------- | ---------------- |
|
|
238
|
+
| A | 116.403 | 39.914 | 12957922.69 | 4853452.853 |
|
|
239
|
+
| B | 116.407 | 39.918 | 12958367.96 | 4854033.408 |
|
|
240
|
+
| C | 116.404 | 39.916 | 12958034.01 | 4853743.126 |
|
|
241
|
+
| D | 116.408 | 39.919 | 12958479.28 | 4854178.552 |
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
### 4、Generate buffers of the specified range based on the longitude and latitude columns in the table and add the geometry.
|
|
245
|
+
```python
|
|
246
|
+
import pandas as pd
|
|
247
|
+
import tablegis as tg
|
|
248
|
+
|
|
249
|
+
df = pd.DataFrame({
|
|
250
|
+
'lon': [116.4074, 121.4737],
|
|
251
|
+
'lat': [39.9042, 31.2304],
|
|
252
|
+
'buffer_size': [500, 1000]
|
|
253
|
+
})
|
|
254
|
+
# Set a 100-meter buffer zone
|
|
255
|
+
res_100 = tg.add_buffer(df,'lon','lat',100)
|
|
256
|
+
# Set the buffer range according to the numbers in the "buffer_size" column.
|
|
257
|
+
res_buffer_size = tg.add_buffer(df,'lon','lat','buffer_size')
|
|
258
|
+
print(res_100)
|
|
259
|
+
print(res_buffer_size)
|
|
260
|
+
```
|
|
261
|
+
**Result Display:**
|
|
262
|
+
## df table
|
|
263
|
+
|
|
264
|
+
| | lon | lat | buffer_size |
|
|
265
|
+
|---|----------|---------|-------------|
|
|
266
|
+
| 0 | 116.4074 | 39.9042 | 500 |
|
|
267
|
+
| 1 | 121.4737 | 31.2304 | 1000 |
|
|
268
|
+
|
|
269
|
+
## Set a 100-meter buffer zone
|
|
270
|
+
|
|
271
|
+
| | lon | lat | buffer_size | geometry |
|
|
272
|
+
|---|----------|---------|-------------|-------------------------------------------------|
|
|
273
|
+
| 0 | 116.4074 | 39.9042 | 500 | POLYGON ((116.40857 39.90421, 116.40856 39.904... |
|
|
274
|
+
| 1 | 121.4737 | 31.2304 | 1000 | POLYGON ((121.47475 31.23036, 121.47474 31.230... |
|
|
275
|
+
|
|
276
|
+
## Set the buffer range according to the numbers in the "buffer_size" column.
|
|
277
|
+
|
|
278
|
+
| | lon | lat | buffer_size | geometry |
|
|
279
|
+
|---|----------|---------|-------------|-------------------------------------------------|
|
|
280
|
+
| 0 | 116.4074 | 39.9042 | 500 | POLYGON ((116.41325 39.90423, 116.41322 39.903... |
|
|
281
|
+
| 1 | 121.4737 | 31.2304 | 1000 | POLYGON ((121.48417 31.23003, 121.48408 31.229... |
|
|
282
|
+
### 5、Convert the latitude and longitude columns in the table into point-shaped geometries and then transform them into a gdf.
|
|
283
|
+
```python
|
|
284
|
+
import pandas as pd
|
|
285
|
+
import tablegis as tg
|
|
286
|
+
|
|
287
|
+
df = pd.DataFrame({
|
|
288
|
+
'lon': [116.4074, 121.4737, 113.2644],
|
|
289
|
+
'lat': [39.9042, 31.2304, 23.1291],
|
|
290
|
+
'city': ['Beijing', 'Shanghai', 'Guangzhou']
|
|
291
|
+
})
|
|
292
|
+
# Generate points based on latitude and longitude
|
|
293
|
+
result1 = tg.add_points(df)
|
|
294
|
+
print(result1)
|
|
295
|
+
```
|
|
296
|
+
**Result Display:**
|
|
297
|
+
|
|
298
|
+
| lon | lat | city | geometry |
|
|
299
|
+
|-----------|------------|-----------|------------------------------|
|
|
300
|
+
| 116.4074 | 39.9042 | Beijing | POINT (116.4074 39.9042) |
|
|
301
|
+
| 121.4737 | 31.2304 | Shanghai | POINT (121.4737 31.2304) |
|
|
302
|
+
| 113.2644 | 23.1291 | Guangzhou | POINT (113.2644 23.1291) |
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
### 6、Concentrate the latitude and longitude data in the table using the method of expansion and recombination, and add the fused id as well as the range geom.
|
|
306
|
+
```python
|
|
307
|
+
import pandas as pd
|
|
308
|
+
import tablegis as tg
|
|
309
|
+
# Prepare test data
|
|
310
|
+
test_data = pd.DataFrame({
|
|
311
|
+
'lon': [116.40, 116.41, 116.50, 116.51],
|
|
312
|
+
'lat': [39.90, 39.91, 39.95, 39.96],
|
|
313
|
+
'name': ['A', 'B', 'C', 'D'],
|
|
314
|
+
'value': [1, 2, 3, 4]
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
# Test 1: Return geometry
|
|
318
|
+
result_no_geom = tg.add_buffer_groupbyid(
|
|
319
|
+
test_data,
|
|
320
|
+
lon='lon',
|
|
321
|
+
lat='lat',
|
|
322
|
+
distance=1000,
|
|
323
|
+
columns_name='group_id',
|
|
324
|
+
id_label_prefix='id_',
|
|
325
|
+
geom=True
|
|
326
|
+
)
|
|
327
|
+
# Test 2: Do not return geometry
|
|
328
|
+
result_geom = tg.add_buffer_groupbyid(
|
|
329
|
+
test_data,
|
|
330
|
+
lon='lon',
|
|
331
|
+
lat='lat',
|
|
332
|
+
distance=1000,
|
|
333
|
+
columns_name='group_id',
|
|
334
|
+
id_label_prefix='id_',
|
|
335
|
+
geom=False
|
|
336
|
+
)
|
|
337
|
+
```
|
|
338
|
+
**Result Display:**
|
|
339
|
+
## no geom
|
|
340
|
+
| lon | lat | name | value | group_id |
|
|
341
|
+
|-------|-------|------|-------|----------|
|
|
342
|
+
| 116.40| 39.90 | A | 1 | id_0 |
|
|
343
|
+
| 116.41| 39.91 | B | 2 | id_0 |
|
|
344
|
+
| 116.50| 39.95 | C | 3 | id_1 |
|
|
345
|
+
| 116.51| 39.96 | D | 4 | id_1 |
|
|
346
|
+
|
|
347
|
+
## geom
|
|
348
|
+
| lon | lat | name | value | group_id | geometry |
|
|
349
|
+
|-------|-------|------|-------|----------|---------|
|
|
350
|
+
| 116.40| 39.90 | A | 1 | id_0 | POLYGON ((116.41149 39.8983, 116.41122 39.8974...) |
|
|
351
|
+
| 116.41| 39.91 | B | 2 | id_0 | POLYGON ((116.41149 39.8983, 116.41122 39.8974...) |
|
|
352
|
+
| 116.50| 39.95 | C | 3 | id_1 | POLYGON ((116.51149 39.94829, 116.51122 39.947...) |
|
|
353
|
+
| 116.51| 39.96 | D | 4 | id_1 | POLYGON ((116.51149 39.94829, 116.51122 39.947...) |
|
|
354
|
+
|
|
355
|
+
### 7. Add a column for area to geopandas. The area is calculated based on the shape's area. The unit of the geographic coordinate system is meters, which is consistent with the units of both the horizontal and vertical planes.
|
|
356
|
+
```python
|
|
357
|
+
import tablegis as tg
|
|
358
|
+
import geopandas as gpd
|
|
359
|
+
polygon = Polygon([(113.343, 29.3434), (113.353, 29.3434), (113.353, 29.3534), (113.343, 29.3534)])
|
|
360
|
+
gdf = gpd.GeoDataFrame({'id': [1], 'geometry': [polygon]}, crs="epsg:4326")
|
|
361
|
+
# Test 1: Add Area Column (Automatically Select Coordinate System)
|
|
362
|
+
result_gdf = tg.add_area(gdf, 'area')
|
|
363
|
+
print('area:',result_gdf['area'].astype(int)[0])
|
|
364
|
+
|
|
365
|
+
# Test 2: Add column name for area and coordinate system
|
|
366
|
+
result_gdf = tg.add_area(gdf, 'area', crs_epsg=32650)
|
|
367
|
+
print('area:',result_gdf['area'].astype(int)[0])
|
|
368
|
+
|
|
369
|
+
```
|
|
370
|
+
结果展示:
|
|
371
|
+
## Add Area Column (Automatically Select Coordinate System)
|
|
372
|
+
```
|
|
373
|
+
Center: (113.3480, 29.3484) → UTM Zone 49 N → EPSG:32649
|
|
374
|
+
area: 1076905
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
## Add column names for area and coordinate system
|
|
378
|
+
```
|
|
379
|
+
area: 1078867
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
## Contributing
|
|
385
|
+
|
|
386
|
+
Contributions in all forms are welcome, including feature requests, bug reports, and code contributions.
|
|
387
|
+
|
|
388
|
+
## License
|
|
389
|
+
|
|
390
|
+
This project is licensed under the MIT License.
|