Returns how far along each line the closest position to the corresponding point lies, as a fraction between 0 and 1.
Details
0 is the start of the line and 1 its end, so you can multiply the value by
the line's length to get a distance. ga_line_locate_point() locates along
lines and linestrings only, and returns NA for any other geometry type, a
null geometry, a null point, or a zero length line.
See also
Other query:
ga_closest_point(),
ga_interior_point(),
ga_is_convex()
Examples
line <- geoarrow::as_geoarrow_array(sf::st_sfc(
sf::st_linestring(cbind(c(0, 10), c(0, 0)))
))
pt <- geoarrow::as_geoarrow_array(sf::st_sfc(sf::st_point(c(2.5, 0))))
as.vector(ga_line_locate_point(line, pt))
#> [1] 0.25