如下代码,如果你去百度谷歌,多数是这么获取geometry属性。实际上一直返回None
def create_data_source(gdbFile, **kwargs):
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES")
driver = ogr.GetDriverByName("FileGDB")
if os.path.exists(gdbFile):
data_source = driver.Open(gdbFile, 1)
else:
data_source = driver.CreateDataSource(gdbFile)
return data_source
data_source = create_data_source('C:\xxx.gdb')
layer = data_source.GetLayerByName(layerName)
feature = ogr.Feature(layer.GetLayerDefn())
# geom的值为None
geom = feature.geometry()
修改代码:
这时候会发现,geom的值是一个Geometry对象
def create_data_source(gdbFile, **kwargs):
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES")
driver = ogr.GetDriverByName("FileGDB")
if os.path.exists(gdbFile):
data_source = driver.Open(gdbFile, 1)
else:
data_source = driver.CreateDataSource(gdbFile)
return data_source
data_source = create_data_source('C:\xxx.gdb')
layer = data_source.GetLayerByName(layerName)
nextLayer = layer.GetNextFeature()
while nextLayer:
geom = nextLayer.geometry()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)