如何将shapfiles生成到专用文件夹中



我使用的是geopandas包,在下面的代码中,我想修改以下行:

LIDARGDF.to_file(filename='LIDAR-Data.shp', driver="ESRI Shapefile")

以便将生成的.shp文件放置在例如称为CCD_ 1的特定文件夹中。为了实现这一点,我做了以下事情:

LIDARGDF.to_file(filename='/out/LIDAR-Data.shp', driver="ESRI Shapefile")

但是,python生成了一个错误,不允许创建文件夹out请让我知道如何修改下面发布的代码,以便它将.shp文件生成到特定的文件夹中

代码

featuresAsPolygonCoordinates3DInEPSG25832 = getFeaturesAsPolygonCoordinatesInEPSG25831(featuresAsPolygonCoordinates3DInEPSG4326)
LIDARAsPolygonGeometry = bindPolygonCoordinates(getPolygonsLongitudeValuesArray(), getPolygonsLatitudeValuesArray())
LIDARGDF = buildGeoDataFrameForGeometry(LIDARAsPolygonGeometry)
LIDARGDF.to_file(filename='LIDAR-Data.shp', driver="ESRI Shapefile")

您有两个选项:

  • 手动创建文件夹
  • 在导出形状文件之前创建它:
import os
try:
os.mkdir('./out')
except FileExistsError:
print('folder already exists!')
LIDARGDF.to_file(filename='out/LIDAR-Data.shp', driver="ESRI Shapefile")

最新更新