Is there a way to convert a dataframe to geojson file to import it in the QGIS vector layer?

266 Views Asked by At

How to write dataframe contains list of multipolygon data to geojson file in order to import in QGIS?

enter image description here

enter image description here

I'm trying to convert this pandas dataframe to a geojson file (to import into QGIS to see the polygons there). But I don't know how to convert a df that contains list of multipolygon data for each gid. How could I do this?

1

There are 1 best solutions below

4
On BEST ANSWER

The simple way is to use geopandas and gdf.to_file()

import geopandas as gpd

# Convert DataFrame to GeoDataFrame
gdf = gpd.GeoDataFrame(df, geometry='my_geo_column')

# Export data to GeoJSON
gdf.to_file('output.geojson')