栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/822630.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号