Quantcast
Channel: Question and Answer » gdal
Viewing all articles
Browse latest Browse all 397

How to save changes in Feature-Geometry with GDAL/OGR and Python? (Segmentation fault)

$
0
0

I have a problem with my code:

driver = ogr.GetDriverByName('ESRI Shapefile')
dataSource = driver.Open('merge.shp', 0)
if dataSource is None:
    print 'Could not open file'
    sys.exit(1)
layer = dataSource.GetLayer() #layer = Shapefile

numFeatures = layer.GetFeatureCount()
i = 0
intersec_count=0
while i < (numFeatures-2):
    feature1 = layer.GetFeature(i)
    geom1 = feature1.GetGeometryRef()
    j = i+1
    while j < numFeatures:
        feature2 = layer.GetFeature(j)
        geom2 = feature2.GetGeometryRef()   
           if geom1.Distance(geom2)<0.0001 and geom1.Distance(geom2)!=0:
              buff = geom1.Buffer(0.0001)
              linkline = geom2.Intersection(buff)
              linkpoint = linkline.GetPoint(0)
              geom1.AddPoint(linkpoint[0],linkpoint[1])
              feature1.SetGeometry(geom1)
        j = j+1
    i = i+1
dataSource.SyncToDisk()
dataSource = None

When running this script the folloging Message appears:
“Segmentation fault (core dumped)”

All I’m trying to do, is to add a Point (linkpoint) to a LineString (geom1) and save these changes.

I hope someone can help me :)


Viewing all articles
Browse latest Browse all 397

Trending Articles