Как я могу получить регион, связанный с данной точкой в ​​функции voronoi_finite_polygons_2d? - PullRequest
2 голосов
/ 21 мая 2019

Я пытаюсь адаптировать этот код Я нашел в stackoverflow для создания ячейки voronoi с конечными границами.

Однако моя проблема в том, что я не знаю, как получить регионсвязан с данной точкой.Это было сделано в обычном Вороном с помощью метода point_region, но здесь это не работает, потому что регионы изменились.

Точки данных, которые я использую:

points = array([[289255.176  , 921667.461  ],
       [289296.31699, 921687.13826],
       [289463.30305, 921770.12504],
       [289725.08002, 921905.75745],
       [289960.48198, 922099.46056],
       [290106.98928, 922361.79529],
       [289255.184  , 921646.244  ],
       [289307.48677, 921627.05485],
       [289500.80493, 921555.50067],
       [289825.14532, 921435.65147],
       [290141.79326, 921322.77935],
       [290454.91721, 921211.09355],
       [289255.187  , 921635.627  ],
       [289327.07776, 921558.85263],
       [289565.21795, 921298.17707],
       [289875.40176, 920978.013  ],
       [290192.86361, 920656.82017],
       [289255.185  , 921630.386  ],
       [289318.54181, 921453.18492],
       [289421.06861, 921167.57934],
       [289565.42462, 920770.1386 ],
       [289701.83141, 920376.28627],
       [289833.6501 , 919990.66467]])

vor = Voronoi(points)

min_x = vor.min_bound[0] - 100
max_x = vor.max_bound[0] + 100
min_y = vor.min_bound[1] - 100
max_y = vor.max_bound[1] + 100

regions, vertices, pts = voronoi_finite_polygons_2d(vor)

1 Ответ

0 голосов
/ 28 июня 2019

Этот код дает вам точку, связанную с данной конечной областью Вороного с использованием точки в анализе многоугольника . Предположим, что мы хотим выяснить, какая точка связана с областью Вороного, которая является второй в списке vor_regions.

vor = Voronoi(points)
vor_regions = vor.regions
vor_vertices = vor.vertices

from shapely.geometry import MultiPoint
from shapely.geometry import Point

region = vor_regions[1]   
coords = tuple(map(tuple, vor_vertices[region]))
poly = MultiPoint(coords).convex_hull
for i in range(0,len(points)):
    pt = Point(tuple(map(tuple, points[i:i+1])))
    if poly.contains(pt) == True:
        print('The input region is ')
        print(region)
        print('Index of the associated point in the vor_vertices list is '+str(i))
        print('The coordinates of the associated point is ')
        print(pt)

Выход:

The input region is 
[6, 2, 1, 0, 5]
Index of the associated point in the vor_vertices list is 4
The coordinates of the associated point is 
POINT (289960.48198 922099.46056)
...