Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

angle_diff

Calculate the angular difference between lines and a predefined bearing


Description

This function was designed to find lines that are close to parallel and perpendicular to some pre-defined route. It can return results that are absolute (contain information on the direction of turn, i.e. + or - values for clockwise/anticlockwise), bidirectional (which mean values greater than +/- 90 are impossible).

Usage

angle_diff(l, angle, bidirectional = FALSE, absolute = TRUE)

Arguments

l

A spatial lines object

angle

an angle in degrees relative to North, with 90 being East and -90 being West. (direction of rotation is ignored).

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

absolute

If TRUE (the default) only positive values can be returned

Details

Building on the convention used in bearing() and in many applications, North is definied as 0, East as 90 and West as -90.

See Also

Examples

lib_versions <- sf::sf_extSoftVersion()
lib_versions
# fails on some systems (with early versions of PROJ)
if (lib_versions[3] >= "6.3.1") {
  # Find all routes going North-South
  lines_sf <- od2line(od_data_sample, zones = zones_sf)
  angle_diff(lines_sf[2, ], angle = 0)
  angle_diff(lines_sf[2:3, ], angle = 0)
  a <- angle_diff(flowlines, angle = 0, bidirectional = TRUE, absolute = TRUE)
  plot(flowlines)
  plot(flowlines[a < 15, ], add = TRUE, lwd = 3, col = "red")
  # East-West
  plot(flowlines[a > 75, ], add = TRUE, lwd = 3, col = "green")
}

stplanr

Sustainable Transport Planning

v0.8.2
MIT + file LICENSE
Authors
Robin Lovelace [aut, cre] (<https://orcid.org/0000-0001-5679-6536>), Richard Ellison [aut], Malcolm Morgan [aut] (<https://orcid.org/0000-0002-9488-9183>), Barry Rowlingson [ctb], Nick Bearman [ctb], Nikolai Berkoff [ctb], Scott Chamberlain [rev] (Scott reviewed the package for rOpenSci, see https://github.com/ropensci/onboarding/issues/10), Mark Padgham [ctb], Andrea Gilardi [ctb] (<https://orcid.org/0000-0002-9424-7439>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.