lair.transects.snap_to_route#
- lair.transects.snap_to_route(xy, route_xy, max_dist)[source]#
Find the nearest route point of each sample, within
max_dist.- Parameters:
xy (np.ndarray) – Sample positions,
(n, 2), in projected meters.route_xy (np.ndarray) – Route points,
(m, 2), in the same projected meters.max_dist (float) – Distance (meters) beyond which a sample is off the route.
- Returns:
tuple[np.ndarray, np.ndarray] –
(index, distance): the route point of each sample (-1 beyondmax_dist) and its distance. A sample with a NaN position (e.g. no time inlag_positions()) gets index -1 and distance NaN.- Return type:
See also
transect_matrixAverages the samples onto
[transit, point].lag_positionsGives the positions to snap.
merge_route_pointsJoins the points of several routes.
Examples
Six route points 500 m apart along x; the sample at 700 m is 200 m from the nearest, beyond
max_dist:>>> import numpy as np >>> from lair.transects import snap_to_route >>> route = np.column_stack([np.arange(0, 2501, 500.0), np.zeros(6)]) >>> xy = np.array([[10.0, 0.0], [1010.0, 5.0], [700.0, 0.0]]) >>> index, distance = snap_to_route(xy, route, max_dist=100) >>> index array([ 0, 2, -1]) >>> distance.round(1) array([ 10. , 11.2, 200. ])