Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Polygon to query
points : (n, 2) float
2D points
Returns
------------
distance : (n,) float
Minimum distance from each point to polygon boundary
"""
try:
import pygeos
# the pygeos way is 5-10x faster
pg_points = pygeos.points(*points.T)
pg_boundary = pygeos.boundary(pygeos.Geometry(polygon.wkt))
distance = pygeos.distance(pg_boundary, pg_points)
except BaseException:
# in pure shapely we have to loop
inverse = polygon.boundary
distance = np.array([
inverse.distance(i) for i in MultiPoint(points)])
return distance
def time_distance(self):
pygeos.distance(self.points, self.polygon)