在Python中使用OGR CreateField()时出现分段错误(segfault)
在Ubuntu中运行这个非常短的脚本时收到segfault在Python中使用OGR CreateField()时出现分段错误(segfault),python,osgeo,Python,Osgeo,在Ubuntu中运行这个非常短的脚本时收到segfault from osgeo import ogr, osr shpfile = 'Census_County_TIGER00_IN.shp' def cust_field(field): '''cust_field(shpfile, field) creates a field definition, which, by calling cust_field(), can be used to create a field usi
from osgeo import ogr, osr
shpfile = 'Census_County_TIGER00_IN.shp'
def cust_field(field):
'''cust_field(shpfile, field) creates a field definition, which, by calling cust_field(), can be used to create a field using the CreateField() function.
cust_field() DOES NOT create a field -- it simply creates a "model" for a field, that can then be called later. It's weird, but that's GDAL/OGR, as far as I can tell.'''
fieldDefn = ogr.FieldDefn(field, ogr.OFTInteger)
fieldDefn.SetWidth(14)
fieldDefn.SetPrecision(6)
return fieldDefn
ds = ogr.Open(shpfile, 1)
lyr = ds.GetLayerByIndex(0)
field = cust_field("Test")
lyr.CreateField(field)
直到最后一行iPython、普通shell Python和空闲命令行都转储为分段错误时,所有操作都会平稳运行。这是我这边的一个错误,还是我没有正确处理底层C的问题
这是我这边的错误还是问题
而我不是
正确寻址
可能两者都有。GDAL/OGR的绑定有时也会出错。虽然这是一个已知的bug,但它不太可能很快被修复
你很有可能找到一种方法来解决这个问题。在Windows XP和以下版本的GDAL/OGR上,我无法使用另一个shapefile复制此错误:
>>> gdal.VersionInfo('')
'GDAL 1.6.0, released 2008/12/04'
您可以暂时尝试将cust\u字段
函数重构到脚本主体中,如下所示:
from osgeo import ogr, osr
shpfile = 'Census_County_TIGER00_IN.shp'
ds = ogr.Open(shpfile, 1)
lyr = ds.GetLayerByIndex(0)
fieldDefn = ogr.FieldDefn("Test", ogr.OFTInteger)
fieldDefn.SetWidth(14)
fieldDefn.SetPrecision(6)
lyr.CreateField(fieldDefn)
让我知道这是否解决了您的问题。针对osgeo提交一个bug。Python程序永远不应该转储内核。不幸的是,它没有。我已尝试手动将每一行输入到iPython,并在lyr.CreateField(fieldDefn)行中输入iPython segfaults。@mattdeboard您能在网上的某个地方发布一个示例形状文件吗?这是我使用的确切形状文件的下载链接。//此外,当我使用GDB运行脚本时,这里还有一个指向调试信息的链接如果有关系的话(我肯定没有),我会在一个虚拟的盒子里在Ubuntu上运行所有这些。@mattdeboard即使使用你的shapefile,我也不能复制这个崩溃。您可能需要检查您的gdal/ogr安装。我已经卸载/重新安装了几次。我想我在卸载时遗漏了一些东西。