在Ubuntu中运行这个非常短的脚本时接收段错误.
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)
Run Code Online (Sandbox Code Playgroud)
一切顺利运行直到最后一行,当iPython,普通shell Python和IDLE命令行全部转储到分段错误时.这是我的错误或基础C的问题,我没有正确解决?
这是我的错误或基础C的问题,我没有正确解决?
可能两者都有.GDAL/OGR的绑定也倾向于偶尔段错误,当对象超出范围,且垃圾回收.虽然这是一个已知的错误,但不太可能很快修复.
你有机会找到解决这个问题的方法.我无法在Windows XP上使用另一个shapefile以及以下版本的GDAL/OGR重现此段错误:
>>> gdal.VersionInfo('')
'GDAL 1.6.0, released 2008/12/04'
Run Code Online (Sandbox Code Playgroud)
您可以尝试暂时将cust_field函数重构为脚本体,如下所示:
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)
Run Code Online (Sandbox Code Playgroud)
如果这可以解决您的问题,请告诉我.