Converting a column of Polygons from string to GeoPandas geometry

后端 未结 1 463
清酒与你
清酒与你 2021-02-04 08:53

I have a dataframe stored as csv file, one column of which is Polygon object. However, this column is stored as strings instead of GeoPandas geometry object. How can I convert t

相关标签:
1条回答
  • 2021-02-04 09:37

    The format of your polygon is WKT, so you have to convert it to shapely Polygon. Following Geopandas docs (https://geopandas.readthedocs.io/en/latest/gallery/create_geopandas_from_pandas.html) do following

    from shapely import wkt
    
    df['geometry'] = df['geometry'].apply(wkt.loads)
    my_geo_df = gpd.GeoDataFrame(my_df, geometry='geometry')
    
    0 讨论(0)
提交回复
热议问题