Как я могу построить полигоны Shapely с отверстиями? - PullRequest
0 голосов
/ 12 сентября 2018

Я хотел бы иметь функцию plot(shapely_objects), где shapely_objects - это список полигонов, точек и мультиполигонов. У меня что-то чрезвычайно похожее, но оно заполняет дыры от полигонов. Как я могу построить полигоны Shapely с отверстиями?

код

from shapely.geometry import Point, shape


def plot(shapely_objects, figure_path='fig.png'):
    from matplotlib import pyplot as plt
    import geopandas as gpd
    boundary = gpd.GeoSeries(shapely_objects)
    boundary.plot(color=['red', 'green'])
    plt.savefig(figure_path, dpi=300, bbox_inches="tight")


p = Point(12.12, 54.085)
name = ''
multi_poly = {'coordinates': (((12.11, 54.08), (12.11, 54.09),
                               (12.13, 54.09), (12.13, 54.08)),
                              ((12.11, 54.08), (12.11, 54.09),
                               (12.13, 54.09), (12.13, 54.08))),
              'type': 'Polygon'}
multi_poly = shape(multi_poly)
plot([p, multi_poly, p])

print('multi_poly.intersects(p) == {}'.format(multi_poly.intersects(p)))
print('multi_poly.touches(p) == {}'.format(multi_poly.touches(p)))
print('multi_poly.contains(p) == {}'.format(multi_poly.contains(p)))
print('p.within(multi_poly) == {}'.format(p.within(multi_poly)))

p, multi_poly = multi_poly, p
print('multi_poly.intersects(p) == {}'.format(multi_poly.intersects(p)))
print('multi_poly.touches(p) == {}'.format(multi_poly.touches(p)))
print('multi_poly.contains(p) == {}'.format(multi_poly.contains(p)))
print('p.within(multi_poly) == {}'.format(p.within(multi_poly)))

Изображение

Зеленая точка НЕ ​​находится внутри красного многоугольника. Отверстие отсутствует / заполнено.

enter image description here

...