In generating Voronoi Tesselations from a set of lat/lon points, I am getting an error that seems to occur when a certain point is used as part of the inputs.
To isolate the problem, I removed and added these points into the input one by one, and found the error to be exactly reproducible when the "PROBLEM POINT" is added back.
ip = [[31.249566 , 30.0458139],
[31.2496667, 30.0460511],
[31.2497362, 30.0462148],
[31.2498083, 30.0463844],
[31.2499063, 30.0466152],
[31.2497861, 30.0457439],
[31.2493217, 30.0458917],
[31.249051 , 30.0459779],
[31.2485747, 30.0461295],
[31.2487919, 30.0460604],
[31.2494149, 30.0461318],
[31.2491506, 30.0462165],
[31.249482 , 30.0463046],
[31.2495479, 30.0464743],
[31.2496453, 30.0467251],
[31.2488556, 30.0467515],
[31.2489719, 30.047009 ],
[31.2493148, 30.0466096],
[31.2492253, 30.0463954],
[31.2492947, 30.0465617],
[31.2494044, 30.0468267],
[31.2497576, 30.0466778],
[31.2500132, 30.0465702], # PROBLEM POINT
[31.2495429, 30.0470592],
[31.2497817, 30.0474367],
[31.2490658, 30.0472466]]
Code:
import libpysal
from libpysal.cg.voronoi import voronoi, voronoi_frames
regions_s, vertices_s = voronoi(ip)
Error Trace:
libpysal/cg/voronoi.py in voronoi_regions(vor, radius)
97 continue
98
---> 99 ridges = all_ridges[p1]
100 new_region = [v for v in vertices if v >= 0]
101
KeyError: 5
What could be happening here? For context, these are all projected points ("EPSG:4326") in Egypt, and I have made sure there are no duplicates. Under the hood, the library uses scipy.
from scipy.spatial import Voronoi