2016-09-12 1 views
1

여러 부분에서 교차하는 2 개의 매끄러운 MultiPolygon 인스턴스 (lon, lat 점으로 이루어짐)가 있습니다. 루프를 통해 두 폴리곤 사이에 교차가 있는지 확인한 다음 해당 교차를 제외하는 새 다각형을 작성하려고합니다. 첨부 된 이미지에서 기본적으로 빨간색 원이 노란색 윤곽선과 겹치지 않게하려면 노란색 윤곽선이 시작되는 가장자리가 정확히 나타나길 원합니다.다른 다각형과의 교점을 빼서 새로운 매끄러운 다각형을 만듭니다.

지침 here을 사용해 보았지만 출력이 전혀 변경되지 않으며, 하나의 계단식 결합으로 병합하고 싶지 않습니다. 어떤 오류 메시지도 표시되지 않지만이 MultiPolygons를 KML 파일 (파이썬에서 원시 텍스트 조작, 멋진 프로그램 없음)에 추가하면 수정없이 원으로 표시됩니다.

# 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) 

Polygon Overlap

답변

2

내가 당신이 원하는 것을 달성하기 위해 두 번째 다각형과의 차이에 의해 결합 된 두 개의 다각형을 논제 사이의 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) 
+0

감사합니다. 오류는 부분적으로 어떻게하면 나중에 코드 내에서 다른 루프를 설정했는지 알았습니다 ... 죄송합니다. – edub

+0

당신이 당신의 결과를 얻을 수있어서 다행! – mgc

관련 문제