2016-08-25 6 views
0

단일 폴리곤을 만들기 위해 폴리곤 세트에 조인하려고합니다.오버레이없이 폴리곤 조인 (및 플롯)

poly1 = [(0,0), (1,0), (1,0.25), (1, 0.5), (1,0.75), (1,1), (0,1)] 
poly2 = [(2,0), (2,0.25), (1,0.25), (1,0.5), (1,0.75), (2,1)] 

다각형에서 "연결"것을 볼 수 있습니다 :이 다각형 (그들은 첫 번째와 동일하고 마지막 점에로 폐쇄되지 않음), 가장자리는 어떤 시점에서 정확히 동일한 (1,0.25), (1,0), (1,0.75)

어떻게이 폴리곤을 단일 폴리곤에 결합합니까?

내 현재 코드 : 나는 위의 코드를 실행하면

from __future__ import division 
import pandas as pd 
from shapely.geometry import Polygon,MultiPolygon 
import os 
import glob 
from shapely.ops import cascaded_union 
import matplotlib.pyplot as plt 
from descartes import PolygonPatch 

basePath = os.path.dirname(os.path.realpath(__file__)) # defines the directory where the current file resides 

files = glob.glob(os.path.join(basePath, '*.txt')) 

polygons = [] 

for f in files: 
    data = pd.read_csv(f, sep=';') # file containing a list of x and y points 

    points = [] 
    for index, point in data.iterrows(): 
     points.append((point['x'], point['y'])) 
    polygons.append(Polygon(points)) 

u = cascaded_union(polygons) 
fig2 = plt.figure(2, figsize=(10,10), dpi=90) 
ax2 = fig2.add_subplot(111) 
patch2b = PolygonPatch(u, fc=BLUE, ec=BLUE, alpha=1, zorder=2) 
ax2.add_patch(patch2b) 

가 작동하지 않습니다. x, y 좌표를 얻으려고하면 (다중 다각형입니다)

답변

0

두 번째 다각형에 자체 조인이 있다고 생각합니다. 그런 다음

poly1 = Polygon([(0,0), (1,0), (1,0.25), (1, 0.5), (1,0.75), (1,1), (0,1)]) 
poly2 = Polygon([(2,0), (2,0.25), (1,0.25), (1,0.5), (1,0.75), (2,1)]) 
poly2_corrected = Polygon([(2,0), (1,0.25), (1,0.5), (1,0.75), (2,1)]) 

, 우리는이 :

poly1 

enter image description here

poly2 

enter image description here

poly2_corrected 

enter image description here

우리는 우리가하려고하면 오류가 발생합니다 :

u = cascaded_union([poly1, poly2]) 

하지만하지 않는 :

u_corrected = cascaded_union([poly1, poly2_corrected]) 
u_corrected 

enter image description here

print u 

POLYGON ((1 0.25, 1 0, 0 0 0 1, 1, 1, 0.75, 2 1, 2 0, 1 0.25))