【发布时间】:2021-08-29 05:48:24
【问题描述】:
我对具有多个geometry 类型的列的数据框有此问题。我的数据框如下所示:
New_zone_short_edges =
id vertex_id point1 \
1 A1 2 POINT (119.79008 28.35047)
3 A1 4 POINT (122.85067 44.85106)
5 A2 1 POINT (138.79141 26.48802)
7 A2 3 POINT (141.73386 44.89716)
13 A3 5 POINT (68.47770 44.07370)
11 A3 3 POINT (46.63571 51.16575)
point2 length midpoint
1 POINT (122.85067 28.08433) 3.072140 POINT (121.32038 28.21740)
3 POINT (119.92314 44.71798) 2.930553 POINT (121.38690 44.78452)
5 POINT (141.92247 26.26168) 3.139230 POINT (140.35694 26.37485)
7 POINT (138.79141 44.89716) 2.942450 POINT (140.26263 44.89716)
13 POINT (65.42208 48.14785) 5.092692 POINT (66.94989 46.11078)
11 POINT (46.59798 47.65744) 3.508504 POINT (46.61685 49.41159)
带有以下信息:
<class 'geopandas.geodataframe.GeoDataFrame'>
Int64Index: 206 entries, 1 to 425
Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 id 206 non-null object
1 vertex_id 206 non-null int64
2 point1 206 non-null geometry
3 point2 206 non-null geometry
4 length 206 non-null float64
5 midpoint 206 non-null geometry
dtypes: float64(1), geometry(3), int64(1), object(1)
memory usage: 11.3+ KB
None
现在,如果我的数据框是 pandas 数据框,我可以重命名单个列,例如:
New_zone_short_edges = New_zone_short_edges.rename(columns ={'point1':'new_point'})
但由于我希望重命名几何,我需要执行以下操作:
New_zone_short_edges.rename_geometry('<the new name>', inplace=True)
这是有问题的,因为我无法选择要重命名的几何图形。有没有和 pandas 类似的东西?
如果可以避免的话,将我的数据框一分为三,更改几何名称然后与另一个合并似乎是一件乏味的事情。我到处寻找替代方案,但没有任何运气。我在某处读到过,在一个数据集中包含多个几何图形是不好的做法,但就我的目的而言,至少对于计算而言,必须采用这种方式。
欢迎任何想法。谢谢!
【问题讨论】:
标签: python-3.x pandas geopandas