面矢量
点矢量
代码
from osgeo import ogr, osr
def poly2point(shpPath, outPath):
"""
:param shpPath: 输入shp路径
:param outPath: 输出shp路径
:return:
"""
driver = ogr.GetDriverByName("ESRI Shapefile")
dataSource = driver.Open(shpPath, 1)
layer = dataSource.GetLayer()
# 新建DataSource,Layer
out_ds = driver.CreateDataSource(outPath)
out_lyr = out_ds.CreateLayer('Point', layer.GetSpatialRef(), geom_type=ogr.wkbPoint)
oFeatureTriangle = ogr.Feature(layer.GetLayerDefn())
for feature in layer:
geom = feature.GetGeometryRef()
center = geom.Centroid()
oFeatureTriangle.SetGeometry(center)
out_lyr.CreateFeature(oFeatureTriangle)
out_ds.Destroy()