GeoDataFrames can be exported to many different standard formats using the geopandas.GeoDataFrame.to_file()
method. For a full list of supported formats, type import fiona; fiona.supported_drivers
.
可以使用 geopandas.GeoDataFrame.to_file() 方法将 GeoDataFrames 导出为许多不同的标准格式。要获得受支持格式的完整列表,请键入 import fiona; fiona.supported_drivers
。
In addition, GeoDataFrames can be uploaded to PostGIS database (starting with GeoPandas 0.8) by using the geopandas.GeoDataFrame.to_postgis()
method.
此外,可以使用 geopandas.GeoDataFrame.to_postgis() 方法将 GeoDataFrames 上传到 PostGIS 数据库(从 GeoPandas 0.8 开始)。
Note:
GeoDataFrame can contain more field types than supported by most of the file formats. For example tuples or lists can be easily stored in the GeoDataFrame, but saving them to e.g. GeoPackage or Shapefile will raise a ValueError. Before saving to a file, they need to be converted to a format supported by a selected driver.
GeoDataFrame 可以包含比大多数文件格式支持的字段类型更多的字段类型。例如,元组或列表可以很容易地存储在 GeoDataFrame 中,但将它们保存到例如GeoPackage 或 Shapefile 将引发 ValueError。在保存到文件之前,需要将它们转换为所选驱动程序支持的格式。
Writing to Shapefile:
countries_gdf.to_file("countries.shp")
Writing to GeoJSON:
countries_gdf.to_file("countries.geojson", driver='GeoJSON')
Writing to GeoPackage:
countries_gdf.to_file("package.gpkg", layer='countries', driver="GPKG")
cities_gdf.to_file("package.gpkg", layer='cities', driver="GPKG")