0

I have a polygon that I want to merge into an existing polygon. To do this I first need to run symmetrical difference between the two overlapping polygons, and then merge them.

Before symmetrical difference:

enter image description here

After symmetrical difference: enter image description here

The problem is that when I run the symmetrical difference, the values in the properties is changed to 1. I need this value to be the same as before I run the symmetrical difference.

In the code below, I have to set a value in the properties – how can I keep the properties as it is (not edited in the properties.

prop = {'code':1, 'fclass':1, 'fclass_no':1, 'Runoffcoef':1} #By running this code, the properties will be changed to 1. I need the properties not to be changed.

enter image description here enter image description here

import fiona
from shapely.geometry import Polygon, shape, mapping
poly1 = fiona.open("\pol\poly1.shp")
poly2 = fiona.open("\poly2.shp")

geom1 = [shape(feat['geometry']) for feat in poly1][0]
geom2 = [shape(feat['geometry']) for feat in poly2][0]

with fiona.open(r'...\Poly3.shp', 'w',driver='ESRI Shapefile', schema=poly1.schema) as output:
   prop = {'code':1, 'fclass':1, 'fclass_no':1, 'Runoffcoef':1}
   output.write({'geometry': mapping(geom1.symmetric_difference(geom2))'properties':prop})
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.