매끈한 polygon.buffer (0) "잃어버린"절반 내 나비 넥타이
-
22-12-2019 - |
문제
Online 버퍼 (0)는 "수정"을 보았습니다.Shaply는 Bowtie의 교차점을 찾지만 오른쪽 상단 부분 만 유지합니다.해결 방법을 찾으려면 내 포인트의 순서를 반전 시도했습니다.놀랍게도 (나에게) Bowtie의 동일한 오른쪽상의 부분은 여전히 보관했습니다.나는 이해하지 못한다.어떤 도움이 감사드립니다.
전체 Bowtie를 두 개의 삼각형으로 유지하고 싶습니다 (Ore 1 6면 다각형 - 유용 할 수 있습니다).이 "문제"에 대한 해결 방법을 찾고 있습니다.
#!/usr/bin/env python3
from shapely.geometry.polygon import Polygon
bowtie_plot = [(1, 0), (0, 1), (0, -1), (-1, 0)]
bowties = [
Polygon(bowtie_plot),
Polygon(bowtie_plot[::-1])
]
cleaned = [
bowties[0].buffer(0),
bowties[1].buffer(0)
]
print('cleaned[0] exterior = {}'.format(list(cleaned[0].exterior.coords)))
# cleaned[0] exterior = [(0.0, 0.0), (-1.0, 1.0), (1.0, 1.0), (0.0, 0.0)]
print('cleaned[1] exterior = {}'.format(list(cleaned[1].exterior.coords)))
# cleaned[1] exterior = [(0.0, 0.0), (-1.0, 1.0), (1.0, 1.0), (0.0, 0.0)]
# ADDITIONAL INFORMATION BELOW
# here's what shapely *can* do with intersecting lines:
# a star shape made of five intersecting lines and five points
from math import sin, cos, pi
star = Polygon(
[(cos(x*pi*4/5), sin(x*pi*4/5)) for x in range(5)]
).buffer(0)
# after buffering, becomes a star shape made out of ten lines and ten points
# shapely found all intersections and corrected the polygon.
print('list exterior = {}'.format(list(star.exterior.coords)))
.
그것에 대해 생각한 후에, 나는 이유를 이해할 수 있습니다 은 보우츠가 별과 다르게 대우받을 수 있지만 해결 방법을 찾는 데 관심이 있습니다.
해결책
Bowtie는 유효하게 균미하지 않습니다 다각형 . (Polygon
문서 바로 위에)에 대한 문서와 문서를 읽으십시오.특히 유효하고 잘못된 LinearRing
의 예를 기록하십시오.
In [46]: bt = [(1,0), (0,1), (0,0), (-1,0), (0, -1), (0,0)]
In [47]: poly = Polygon(bt)
.
를 반환합니다.
In [48]: poly.buffer(0)
Out[48]: <shapely.geometry.multipolygon.MultiPolygon at 0x4a40050>
. 다른 팁
buffer(0)
가 항상 다중 폴리곤을 생성하는 것은 아닙니다 :
from shapely.wkt import loads
bt = loads('POLYGON ((0 0, 2 2, 2 0, 0 2, 0 0))')<br>
bt.buffer(0).wkt
produces 'POLYGON ((1 1, 2 2, 2 0, 1 1))'
. 제휴하지 않습니다 StackOverflow