在 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)
一切都运行顺利,直到最后一行,当 iPython、普通 shell Python 和 IDLE 命令行都转储到分段错误时。这是我的错误还是我没有正确解决的底层C问题?