【问题标题】:Converting GeoJSON object to shapely object将 GeoJSON 对象转换为 shapely 对象
【发布时间】:2021-10-27 18:22:55
【问题描述】:

我有一个地理数据框:

gdf
                              name  ...                                           geometry
0     INET_PL_273_EE_0_Seg_0_Seg_0  ...  {'type': 'LineString', 'coordinates': [[23.896...
1     INET_PL_273_EE_1_Seg_0_Seg_0  ...  {'type': 'LineString', 'coordinates': [[22.241...
2          INET_PL_357_Seg_0_Seg_0  ...  {'type': 'LineString', 'coordinates': [[13.592...
3          INET_PL_359_Seg_0_Seg_0  ...  {'type': 'LineString', 'coordinates': [[13.592...
4          INET_PL_361_Seg_0_Seg_0  ...  {'type': 'LineString', 'coordinates': [[13.592...
...                            ...  ...                                                ...
6318       EntsoG_Map__ST_25_Seg_0  ...  {'type': 'LineString', 'coordinates': [[13.887...
6319       EntsoG_Map__ST_26_Seg_0  ...  {'type': 'LineString', 'coordinates': [[23.080...
6320       EntsoG_Map__ST_26_Seg_0  ...  {'type': 'LineString', 'coordinates': [[6.7552...
6321      EntsoG_Map__ST_448_Seg_0  ...  {'type': 'LineString', 'coordinates': [[25.348...
6322      EntsoG_Map__ST_449_Seg_0  ...  {'type': 'LineString', 'coordinates': [[25.348...
[6323 rows x 7 columns]

我通过gdf['geometry'] = gdf['geometry'].apply(lambda x: shapely.geometry.mapping(x)) 创建了几何列。现在我想把它转换回来。

有什么简单的技巧吗?

【问题讨论】:

    标签: python dataframe geojson geopandas shapely


    【解决方案1】:

    shape() 函数将其转换回来:

    gdf['geometry'] = gdf['geometry'].apply(lambda x: shapely.geometry.shape(x))
    

    【讨论】:

      猜你喜欢
      • 2014-11-25
      • 2021-10-25
      • 2016-05-19
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2020-05-10
      • 1970-01-01
      • 2020-06-15
      相关资源
      最近更新 更多