This is a simple wrapper around the geosphere function bearing() to return the bearing (in degrees relative to north) of lines.

line_bearing(l, bidirectional = FALSE)

Arguments

l

A spatial lines object

bidirectional

Should the result be returned in a bidirectional format? Default is FALSE. If TRUE, the same line in the oposite direction would have the same bearing

Details

Returns a boolean vector. TRUE means that the associated line is in fact a point (has no distance). This can be useful for removing data that will not be plotted.

See also

Examples

lib_versions <- sf::sf_extSoftVersion() lib_versions
#> GEOS GDAL proj.4 GDAL_with_GEOS USE_PROJ_H #> "3.8.0" "3.0.4" "6.3.1" "true" "true" #> PROJ #> "6.3.1"
# fails on some systems (with early versions of PROJ) if (lib_versions[3] >= "6.3.1") { bearings_sf_1_9 <- line_bearing(flowlines_sf[1:5, ]) bearings_sf_1_9 # lines of 0 length have NaN bearing bearings_sp_1_9 <- line_bearing(flowlines[1:5, ]) bearings_sp_1_9 plot(bearings_sf_1_9, bearings_sp_1_9) line_bearing(flowlines_sf[1:5, ], bidirectional = TRUE) line_bearing(flowlines[1:5, ], bidirectional = TRUE) }
#> [1] 0.000000 87.950582 77.554344 36.163396 6.668455