Search code examples
pythongeojsongeopandasshapely

Convert a column of GeoJSON-like strings to geometry objects in GeoPandas


I have a column in a GeoPandas dataframe with strings like this one '{type=Point, coordinates=[37.55, 55.71]}' or this '{type=MultiPoint, coordinates=[[37.6, 55.4]]}'. It can be a polygon or any other geometry as well. Then there are a few points in the form of nested list. How can I transform it to the ordinary GeoPandas geometry objects?


Solution

  • Use shapely.geometry.shape to convert geojson strings to shapely geometry.

    from shapely.geometry import shape
    
    df['geometry'] = df.apply(lambda: row: shape(row['jsoncolumn']), axis=1)