In GeoPandas, you can save a GeoDataFrame as a Shapefile using the to_file
method. Here's how to do it:
import geopandas as gpd
# Create or load a GeoDataFrame (gdf) that you want to save
# ...
# Specify the path and name for the Shapefile (e.g., 'output.shp')
output_shapefile = 'output.shp'
# Save the GeoDataFrame as a Shapefile
gdf.to_file(output_shapefile)
In the code above:
- Import the
geopandas
library. - Create or load the GeoDataFrame (
gdf
) that you want to save as a Shapefile. - Specify the path and name for the output Shapefile in the
output_shapefile
variable. - Use the
to_file
method of the GeoDataFrame to save it as a Shapefile, with the specified name and location.
The to_file
method will create a set of files with extensions like .shp
, .shx
, .dbf
, and others in the specified directory. These files collectively make up the Shapefile format, which is a common format for geospatial data storage.