python - Create new shapely polygon by subtracting the intersection with another polygon -


i have 2 shapely multipolygon instances (made of lon,lat points) intersect @ various parts. i'm trying loop through, determine if there's intersection between 2 polygons, , create new polygon excludes intersection. attached image, don't want red circle overlap yellow contour, want edge yellow contour starts.

i've tried following instructions here doesn't change output @ all, plus don't want merge them 1 cascading union. i'm not getting error messages, when add these multipolygons kml file (just raw text manipulation in python, no fancy program) they're still showing circles without modifications.

# multipol1 , multipol2 shapely multipolygons shapely.ops import cascaded_union itertools import combinations shapely.geometry import polygon,multipolygon  outmulti = [] pol in multipoly1:     pol2 in multipoly2:         if pol.intersects(pol2)==true:             # if intersect, create new polygon             # pol minus intersection             intersection = pol.intersection(pol2)             nonoverlap = pol.difference(intersection)             outmulti.append(nonoverlap)          else:             # otherwise, keep initial polygon is.             outmulti.append(pol)  finalpol = multipolygon(outmulti) 

polygon overlap

i guess can use symmetric_difference between theses 2 polygons, combined difference second polygon achieve want (the symmetric difference brings non-overlapping parts 2 polygons, on removed parts of polygon 2 difference). haven't tested might :

# multipol1 , multipol2 shapely multipolygons shapely.ops import cascaded_union itertools import combinations shapely.geometry import polygon,multipolygon  outmulti = [] pol in multipoly1:     pol2 in multipoly2:         if pol.intersects(pol2)==true:             # if intersect, create new polygon             # pol minus intersection             nonoverlap = (pol.symmetric_difference(pol2)).difference(pol2)             outmulti.append(nonoverlap)          else:             # otherwise, keep initial polygon is.             outmulti.append(pol)  finalpol = multipolygon(outmulti) 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -