मेरे पास दो आकार के मल्टीप्लिगॉन उदाहरण हैं (बनाया गयालोन, लैट पॉइंट्स) जो विभिन्न भागों में छेड़छाड़ करते हैं। मैं "लूप के माध्यम से लूप करने की कोशिश कर रहा हूं, यह निर्धारित करता हूं कि क्या दो बहुभुजों के बीच एक छेड़छाड़ है, और उसके बाद एक नया बहुभुज बनाएं जो उस छेड़छाड़ को छोड़ देता है। संलग्न छवि से, मैं मूल रूप से लाल सर्कल को पीले रंग के समोच्च के साथ ओवरलैप नहीं करना चाहता, मैं चाहता हूं कि धार बिल्कुल ठीक हो जहां पीले रंग का कॉन्टूर शुरू होता है।
मैंने निर्देशों का पालन करने की कोशिश की है यहाँ लेकिन यह मेरे आउटपुट को बिल्कुल भी नहीं बदलता है, साथ ही मैंउन्हें एक कैस्केडिंग यूनियन में विलय नहीं करना चाहते हैं। मुझे कोई त्रुटि संदेश नहीं मिल रहा है, लेकिन जब मैं इन मल्टीपोलिगन्स को केएमएल फ़ाइल में जोड़ता हूं (केवल पाइथन में कच्चे पाठ में हेरफेर, कोई फैंसी प्रोग्राम नहीं) वे अभी भी दिखा रहे हैं बिना किसी संशोधन के मंडल।
# multipol1 and multipol2 are my shapely MultiPolygons
from shapely.ops import cascaded_union
from itertools import combinations
from shapely.geometry import Polygon,MultiPolygon
outmulti = []
for pol in multipoly1:
for pol2 in multipoly2:
if pol.intersects(pol2)==True:
# If they intersect, create a new polygon that is
# essentially pol minus the intersection
intersection = pol.intersection(pol2)
nonoverlap = pol.difference(intersection)
outmulti.append(nonoverlap)
else:
# Otherwise, just keep the initial polygon as it is.
outmulti.append(pol)
finalpol = MultiPolygon(outmulti)
उत्तर:
उत्तर № 1 के लिए 4मुझे लगता है कि आप इसका उपयोग कर सकते हैं symmetric_difference
दो बहुभुजों के बीच, दूसरे बहुभुज के साथ अंतर से संयुक्त जो आप करना चाहते हैं (द सममित अंतर आपको दो बहुभुजों से गैर-ओवरलैपिंग भागों लाएगा, जिन पर बहुभुज 2 के हिस्सों को हटा दिया जाता है अंतर)। मैंने परीक्षण नहीं किया है लेकिन यह ऐसा दिखाई दे सकता है:
# multipol1 and multipol2 are my shapely MultiPolygons
from shapely.ops import cascaded_union
from itertools import combinations
from shapely.geometry import Polygon,MultiPolygon
outmulti = []
for pol in multipoly1:
for pol2 in multipoly2:
if pol.intersects(pol2)==True:
# If they intersect, create a new polygon that is
# essentially pol minus the intersection
nonoverlap = (pol.symmetric_difference(pol2)).difference(pol2)
outmulti.append(nonoverlap)
else:
# Otherwise, just keep the initial polygon as it is.
outmulti.append(pol)
finalpol = MultiPolygon(outmulti)