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 the value multiplied by the
line's length gives a distance. Only lines and linestrings can be located
along; any other geometry type, a null geometry, a null point, or a
zero length line becomes NA.
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