resqpy.olio.vector_utilities.points_in_polygon

resqpy.olio.vector_utilities.points_in_polygon(points: ndarray, polygon: ndarray, points_xlen: int, polygon_num: int = 0) ndarray[source]

Calculates which points are within a polygon in 2D.

Parameters
  • points (np.ndarray) – array of shape (N, 2 or 3), of the points in 2D (xy, any z values are ignored)

  • polygon (np.ndarray) – list-like array of the polygon’s vertices in 2D

  • points_xlen (int) – the original I extent of the now flattened points, use 1 if not applicable

  • polygon_num (int) – the polygon number, default is 0, for copying to output

Returns

polygon_points (np.ndarray)

list-like 2D array containing only the points within the polygon,

with each row being the polygon number (as input), points J index, and points I index

Note

the polygon is assumed closed, the closing point should not be repeated