st_azimuth | R Documentation |

Calculates the (planar!) azimuth between pairs in two sequences of points `x`

and `y`

. When point sequence length doesn't match, the shorter one is recycled.

st_azimuth(x, y)

`x` |
Object of class |

`y` |
Object of class |

A `numeric`

vector, of the same length as (the longer of) `x`

and `y`

, with the azimuth values from `x`

to `y`

(in decimal degrees, ranging between 0 and 360 clockwise from north). For identical points, an azimuth of `NA`

is returned.

The function currently calculates planar azimuth, ignoring CRS information. For bearing on a sphere, given points in lon-lat, see function `geosphere::bearing`

.

https://en.wikipedia.org/wiki/Azimuth#Cartographical_azimuth

# Two points x = st_point(c(0, 0)) y = st_point(c(1, 1)) st_azimuth(x, y) # Center and all other points on a 5*5 grid library(stars) m = matrix(1, ncol = 5, nrow = 5) m[(nrow(m)+1)/2, (ncol(m)+1)/2] = 0 s = st_as_stars(m) s = st_set_dimensions(s, 2, offset = ncol(m), delta = -1) names(s) = "value" pnt = st_as_sf(s, as_points = TRUE) ctr = pnt[pnt$value == 0, ] az = st_azimuth(ctr, pnt) plot(st_geometry(pnt), col = NA) plot(st_connect(ctr, pnt, k = nrow(pnt), progress = FALSE), col = "grey", add = TRUE) plot(st_geometry(pnt), col = "grey", add = TRUE) text(st_coordinates(pnt), as.character(round(az)), col = "red")

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.