python的OGR库获取geometry属性返回None,feature.geometry()
如下代码,如果你去百度谷歌,多数是这么获取geometry属性。实际上一直返回Nonedef create_data_source(gdbFile, **kwargs):gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES")driver = ogr.GetDriverByName("FileGDB")if os.path.exists(gdbFil
·
如下代码,如果你去百度谷歌,多数是这么获取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()

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)