0
ポリゴンの集合を結合して1つのポリゴンを作成しようとしています。オーバーレイなしでポリゴンに結合する(そしてプロット)
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)
これらのポリゴンを1つのポリゴンに結合するにはどうすればよいですか?
私の現在のコード:
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座標を取得しようとすると、私はできません(uはマルチポリゴンです)。