Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup(self):
self.points = pygeos.points(np.random.random((10000, 2)))
def setup(self):
self.points = pygeos.points(np.random.random((100000, 2)))
self.polygon = pygeos.polygons(np.random.random((3, 2)))
-------------
polygon : shapely.geometry.Polygon
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