Projects points to linear distances along a route shape.
Source:R/gtfs_helpers.R
project_onto_route.RdThis function takes spatial points and projects them onto a route, returning the linear distance from the beginning terminal of the route.
Arguments
- shape_geometry
The SF object to project onto. Must include the field
shape_id. Seeget_shape_geometry().- points
Can be either: a dataframe representing point coordinates, with fields
longitudeandlatitude; or, an SF or SFC point object.- original_crs
Optional. A numeric EPSG identifier. If a dataframe is provided for
points, this will be used to define the coordinate system of the longitude / latitude values. Default is 4326 (WGS 84 ellipsoid).- project_crs
Optional. A numeric EPSG identifer indicating the coordinate system to use for spatial calculations. Consider setting to a Euclidian projection, such as the appropriate UTM zone. Default is 4326 (WGS 84 ellipsoid).
Value
The points input (either dataframe or SF) with an appended column
for the linear distance along the route. If points is an SFC, a vector of
numeric distances is returned. Units are those of the spatial projection
used (e.g., meters if using UTM).
Examples
# Set my parameters
my_crs <- 32618
# Get shape data
c53_shape <- new_transittraj_data("get_shape_geometry")
# Set points of interest
my_points <- data.frame(longitude = c(-76.990038, -77.036289),
latitude = c(38.871335, 38.917054),
poi_name = c("11th St Bridge", "16th & U"))
# Run project_onto_route
my_points_proj <- project_onto_route(shape_geometry = c53_shape,
points = my_points,
project_crs = my_crs)
head(my_points_proj)
#> longitude latitude poi_name distance
#> 1 -76.99004 38.87134 11th St Bridge 5422.615
#> 2 -77.03629 38.91705 16th & U 13402.281