하나가 아마도 한 번에 하나의 다각형을 추가하여 진행할 수 많은 폴리곤이 기여하는 방법들을 각각 분리 된 형태의 목록을 유지하고 기억
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