[936] Save a GeoDataFrame as a Shapefile

发布时间 2023-11-06 12:00:43作者: McDelfino

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:

  1. Import the geopandas library.
  2. Create or load the GeoDataFrame (gdf) that you want to save as a Shapefile.
  3. Specify the path and name for the output Shapefile in the output_shapefile variable.
  4. 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.