View source: R/st_distance_along.R
st_distance_along | R Documentation |
Compute Euclidian or great circle distance along a sequence of geometries
st_distance_along(
x,
...,
which = ifelse(isTRUE(sf::st_is_longlat(x)), "Great Circle", "Euclidean"),
par = 0,
tolerance = 0
)
x |
object of class |
... |
passed on to |
which |
character; for Cartesian coordinates only: one of |
par |
for |
tolerance |
ignored if |
For details see st_distance
since
st_distance_along()
is built-on that function.
Returns a numeric vector of length x
starting with 0 for the
first geometry, followed by the cumulative sums of distances between the
geometries along the sequence of x
. If a geometry is empty the
corresponding value and any following value in vector are NA
.
If the coordinate reference system of x
was set, the
distances are returned with corresponding unit of measure; see
set_units
.
library(sf)
library(tmap)
storms <- st_read(system.file("shape", package = "sf"), "storms_xyz", quiet = TRUE)
storms <- st_set_crs(storms, 4326)
st_storm_30 <- storms[30, ]
st_storm_30_pt <- st_cast(st_storm_30, "POINT", warn = FALSE)
dist_along <- st_distance_along(st_storm_30_pt)
st_storm_30_pt$dist_along_km <- units::set_units(dist_along, "km") %>% round() %>% paste("km")
tm_shape(st_storm_30) + tm_lines() +
tm_shape(st_storm_30_pt) + tm_bubbles(size = 0.5, col = "red") +
tm_text("dist_along_km", xmod = 2, ymod = 1) +
tm_layout(inner.margins = 0.1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.