verde.inside

verde.inside(coordinates, region, out=None, tmp=None)[source]

Determine which points fall inside a given region.

Points at the boundary are counted as being outsize.

Parameters:
coordinates : tuple of arrays

Arrays with the coordinates of each data point. Should be in the following order: (easting, northing, vertical, …). Only easting and northing will be used, all subsequent coordinates will be ignored.

region : list = [W, E, S, N]

The boundaries of a given region in Cartesian or geographic coordinates.

out : None or array of booleans

Numpy array to be used as output. The contents will be overwritten and the same array will be returned.

tmp : None or tuple

Numpy arrays used to store the outputs of temporary logical operations. Passing in pre-allocated arrays avoids the overhead of allocation when calling this function repeatedly. If not None, then should be a tuple of 4 numpy arrays of boolean type and a shape equal to or broadcast from the input coordinates.

Returns:
are_inside : array of booleans

An array of booleans with the same shape as the input coordinate arrays. Will be True if the respective coordinates fall inside the area, False otherwise.

Examples

>>> import numpy as np
>>> east = np.array([1, 2, 3, 4, 5, 6])
>>> north = np.array([10, 11, 12, 13, 14, 15])
>>> region = [2.5, 5.5, 12, 15]
>>> print(inside((east, north), region))
[False False  True  True  True False]
>>> # This also works for 2D-arrays
>>> east = np.array([[1, 1, 1],
...                  [2, 2, 2],
...                  [3, 3, 3]])
>>> north = np.array([[5, 7, 9],
...                   [5, 7, 9],
...                   [5, 7, 9]])
>>> region = [0.5, 2.5, 6, 9]
>>> print(inside((east, north), region))
[[False  True  True]
 [False  True  True]
 [False False False]]