def ShapefileMultiplePartSplit(inputShapefile, splitedShapefileSaveFolder):
"""
拆分矢量文件为多个单要素矢量文件,注意拆分后的fid需要重置
:param inputShapefile: 要拆分的矢量文件
:param splitedShapefileSaveFolder: 拆分后矢量文件保存目录
:return:
"""
driver = ogr.GetDriverByName("ESRI Shapefile")
ds = ogr.Open(inputShapefile)
lyr = ds.GetLayer()
# featNumber = lyr.GetFeatureCount()
feat = lyr.GetFeature(0)
geoms = feat.GetGeometryRef()
spa = lyr.GetSpatialRef()
name = os.path.basename(inputShapefile).split(".")[0]
for i, geom in enumerate(geoms):
temName = "".join([name, "_", str(i + 1), '_split.shp'])
output_shpfile = os.path.join(splitedShapefileSaveFolder, temName)
if os.path.exists(output_shpfile):
driver.DeleteDataSource(output_shpfile)
outds = driver.CreateDataSource(output_shpf
基于OSGEO的矢量文件多部件拆分(不使用arcpy)
于 2022-09-23 11:42:49 首次发布