Title: | An R Package for (Re-)Routing Paths Around Barriers |
---|---|
Description: | The `pathroutr` package aims to provide a set of tools for routing marine animal tracks around land barriers based on the shortest path through a visibility graph network. The foundation of the package is a graph network created from a Delaunay Triangle mesh created from the vertices of land polygons within the study area. Any network edges that cross or fall completely within the land (barrier) polygons are removed. |
Authors: | Josh London [aut, cre] |
Maintainer: | Josh London <[email protected]> |
License: | CC0 |
Version: | 0.2.1 |
Built: | 2024-11-10 05:40:27 UTC |
Source: | https://github.com/jmlondon/pathroutr |
Alaska 1:250000 coastal data polygon. This is provided by the Alaska Department of Natural Resources and was obtained from their open data portal (https://gis.data.alaska.gov/datasets/alaska-1250000). Note, only those polygons that intersect with the bounding box of our harbor seal movement are included.
akcoast
akcoast
Simple feature collection with 273 features and 5 fields:
POLYGON
https://gis.data.alaska.gov/datasets/alaska-1250000
This function identifies the segments of consecutive points that intersect with the
barrier polygon feature. The result is a data frame of segment records that identify
portions of the track that will need to be re-routed. The result from this function
can be directly passed into the prt_nearestnode()
.
get_barrier_segments(trkpts, barrier)
get_barrier_segments(trkpts, barrier)
trkpts |
Simple Feature points ('sf', 'sfc_POINT'/'sfc_MULTIPOINT') that represent track points. Order is accepted as is and the bounding box of trkpts should be within the bounding box of the barrier polygon. |
barrier |
Simple Feature polygon ('sf', 'sfc_POLYGON'/'sfc_MULTIPOLYGON')
representing the barrier feature. Should be the same barrier as supplied to the
|
data.frame representing segments of consecutive points that intersect with barrier feature. the start_pt and end_pt geometry columns represent the bookend points for each segment that do not intersect with the barrier feature. The n_pts column is the number of points to be re-routed.
A polygon dataset used to test and demonstrate package functions for routing paths around barriers
land_barrier
land_barrier
Simple feature collection with 19 features and 0 fields:
MULTIPOLYGON
geopackage file available in extData
A point dataset used to test and demonstrate package functions for routing paths around barriers
poi
poi
Simple feature collection with 67 features and 0 fields:
MULTIPOINT
geopackage file available in extData
Extend a path to include given start and end points
prt_extend_path(l_geom, start_pt, end_pt)
prt_extend_path(l_geom, start_pt, end_pt)
l_geom |
geometry passed from inside prt_shortpath() |
start_pt |
start point |
end_pt |
end point |
linestring
Find the nearest node for start and end points in segs_tbl
prt_nearestnode(segs_tbl, vis_graph)
prt_nearestnode(segs_tbl, vis_graph)
segs_tbl |
output from |
vis_graph |
sfnetwork output from |
data frame with updated columns for nearest start and end nodes
This is a convenience wrapper, and the suggested function, for re-routing a trkpts
series of ordered POINT features around a barrier polygon via vis_graph built with
the prt_visgraph()
function. The output can be used as a starting point for a custom
process to replace the original geometry. Or, provide the output tibble directly to
prt_update_points()
along with trkpts for simply updating in place.
prt_reroute(trkpts, barrier, vis_graph, blend = TRUE)
prt_reroute(trkpts, barrier, vis_graph, blend = TRUE)
trkpts |
Simple Feature points ('sf', 'sfc_POINT'/'sfc_MULTIPOINT') that represent track points. Order is accepted as is and the bounding box of trkpts should be within the bounding box of the barrier polygon. |
barrier |
Simple Feature polygon ('sf', 'sfc_POLYGON'/'sfc_MULTIPOLYGON')
representing the barrier feature. Should be the same barrier as supplied to the
|
vis_graph |
sfnetwork from prt_visgraph() |
blend |
boolean whether to blend start/end points into network |
a two-column tibble with column fid representing the row index in trkpts to be replaced by the new geometry in geometry column. If trkpts and barrier do not spatially intersect and empty tibble is returned.
Calculate the shortest path through a visibility network between two points
prt_shortpath(segs_tbl, vis_graph, blend = TRUE)
prt_shortpath(segs_tbl, vis_graph, blend = TRUE)
segs_tbl |
tbl from |
vis_graph |
sfnetwork from prt_visgraph() |
blend |
boolean whether to blend start/end points into network |
segs_tbl data frame with added geometry column for shortest path LINESTRING that connects the start_pt and end_pt coordinates
Trim tracks to start and end outside barrier
prt_trim(trkpts, barrier)
prt_trim(trkpts, barrier)
trkpts |
Simple Feature points ('sf', 'sfc_POINT'/'sfc_MULTIPOINT') that represent track points. Order is accepted as is and the bounding box of trkpts should be within the bounding box of the barrier polygon. |
barrier |
Simple Feature polygon ('sf', 'sfc_POLYGON'/'sfc_MULTIPOLYGON')
representing the barrier feature. Should be the same barrier as supplied to the
|
Original geometry is updated in place and (currently) no record of those points that were updated is provided.
prt_update_points(rrt_pts, trkpts)
prt_update_points(rrt_pts, trkpts)
rrt_pts |
output from |
trkpts |
original trkpts Simple Features Collection |
trkpts with updated geometry
Create a visibility graph
prt_visgraph( barrier, buffer = 0, centroids = FALSE, centroid_limit = 1e+07, aug_points = NULL )
prt_visgraph( barrier, buffer = 0, centroids = FALSE, centroid_limit = 1e+07, aug_points = NULL )
barrier |
simple feature 'POLYGON' or 'MULTIPOLYGON' that can be cast into 'POLYGON' |
buffer |
integer specifying buffer distance for barrier |
centroids |
logical whether to include centroids in the mesh |
centroid_limit |
integer minimum size (m^2) for adding centroid to triangles |
aug_points |
simple feature 'POINT' or 'MULTIPOINT' as additional nodes |
SpatialLinesNetwork
These are custom spatial predicate functions that are negated versions
of the spatial predicates st_within()
, st-crosses()
, and st_intersects
not_crosses(x, y) not_within(x, y) not_intersects(x, y)
not_crosses(x, y) not_within(x, y) not_intersects(x, y)
x , y
|
simple features. |