python的OGR库获取geometry属性返回None,feature.geometry

python的OGR库获取geometry属性返回None,feature.geometry,第1张

如下代码,如果你去百度谷歌,多数是这么获取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()
	

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/714785.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-24
下一篇 2022-04-24

发表评论

登录后才能评论

评论列表(0条)

保存