1は、おそらく一度に1つのポリゴンを追加することによって進めることができ、多くのポリゴンが貢献してどのようにそれらのそれぞれにばらばら形状のリストを維持し、覚えている:
import copy
from itertools import groupby
from random import randint, seed
from shapely.geometry import Polygon, box
from shapely.ops import cascaded_union
polygons = [
Polygon([(0, 0), (2, 0), (2, 2), (0, 2), (0, 0)]),
Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]),
Polygon([(1, 1), (2, 1), (2, 2), (1, 2), (1, 1)])
]
def check_shape(s):
return (s.geom_type in ['Polygon', 'MultiPolygon'] and not s.is_empty)
shapes = []
for p in polygons:
polygon = copy.deepcopy(p)
new_shapes = []
for shape_cnt, shape in shapes:
new_shapes.extend([
(shape_cnt, shape.difference(polygon)),
(shape_cnt+1, shape.intersection(polygon))
])
polygon = polygon.difference(shape)
new_shapes.append((1, polygon))
shapes = list(filter(lambda s: check_shape(s[1]), new_shapes))
for p in polygons:
print(p)
for cnt, g in groupby(sorted(shapes, key = lambda s: s[0]), key = lambda s: s[0]):
print(cnt, cascaded_union(list(map(lambda s: s[1], g))))
をこれは、その後生成します。
POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))
POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))
POLYGON ((1 1, 2 1, 2 2, 1 2, 1 1))
1 MULTIPOLYGON (((2 1, 2 0, 1 0, 1 1, 2 1)), ((0 1, 0 2, 1 2, 1 1, 0 1)))
2 MULTIPOLYGON (((1 0, 0 0, 0 1, 1 1, 1 0)), ((1 2, 2 2, 2 1, 1 1, 1 2)))
密度画像のような意味ですか?各ピクセルには、発生回数のカウントがありますか? – armatita
ええ、ちょっとこれのように。まだピクセルはありませんが、私はそれをラスタライズすることができますね。 – Oleksiy
また、すべてのパッチを交差させ、交差点の数をカラーマップすることもできますが、これはsvgのようなイメージを得るために多くのトラブルのように思えます。しかし、さまざまなサイズに拡大縮小したい場合は、それを考慮する必要があります。しかし、個人的に、...ええ、私はラスターを使うつもりです。 – armatita