0

I have the following code that takes a series of points from a pandas dataframe (x,y) and a scipy.spatial.qhull.ConvexHull object. This returns all points which are within the hull.

def in_hull(points, hull):
    hulleq = hull.equations
    dist = np.array(points[['x', 'y']]) @ hulleq[:, :2].T + hulleq[:, 2]
    return np.all(dist < 0, axis=1)

I'm trying to do the same for a polygon (see below), I would like to reuse the in_hull() function rather than write a point in polygon function. Is there anyway to convert a polygon into a scipy hull object so it can pretend to be a hull object?

POLYGON ((580994.4751 4275268.0318, 580994.8389 4275267.4381, 580994.8673 4275267.3736, 580994.3239 4275266.9655, 580993.7005 4275266.3116, 580993.5152 4275266.1903, 580991.8844 4275265.1638, 580991.7139 4275265.2946, 580991.5705 4275265.4891, 580990.4452 4275267.2628, 580990.1548 4275267.7447, 580990.0031 4275268.0023, 580989.8736 4275268.2297, 580990.164 4275268.4583, 580990.2375 4275268.5093, 580990.4965 4275268.6763, 580990.826 4275268.8845, 580990.8388 4275268.8923, 580991.3172 4275269.1658, 580991.9052 4275269.5398, 580992.3238 4275269.7897, 580992.3515 4275269.8057, 580992.4967 4275269.889, 580992.6127000001 4275269.9522, 580992.8403 4275270.0501, 580993.03 4275270.0662, 580993.3365 4275269.7995, 580993.6424 4275269.3079, 580994.0201 4275268.7661, 580994.4751 4275268.0318))
Spatial Digger
  • 1,883
  • 1
  • 19
  • 37

0 Answers0