You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
st_distance(x,y) returns the full matrix of distances from all x to all y. Sometimes we might have two geometry vector - maybe source and destination - and want to compute the distance from each source to its corresponding destination.
This can be done with sapply(1:length(g1),function(i)st_distance(g1[[i]],g2[[i]])) if g1 and g2 are geometry vectors with the same length, and returns a vector of the same length. But maybe a "element_wise" parameter to st_distance that changes its behaviour might be a nice thing to have.
Would ideally use R's usual vector recycling rules if lengths don't match, with the usual warnings on vectors that don't repeat nicely.
I think this is even easier:
> mapply(st_distance, g1, g2)
[1] 152687.52 192552.37 297678.52 262699.58 76465.13
Warning message:
In mapply(st_distance, g1, g2) :
longer argument not a multiple of length of shorter
st_distance(x,y)
returns the full matrix of distances from allx
to ally
. Sometimes we might have two geometry vector - maybe source and destination - and want to compute the distance from each source to its corresponding destination.This can be done with
sapply(1:length(g1),function(i)st_distance(g1[[i]],g2[[i]]))
ifg1
andg2
are geometry vectors with the same length, and returns a vector of the same length. But maybe a"element_wise"
parameter tost_distance
that changes its behaviour might be a nice thing to have.Would ideally use R's usual vector recycling rules if lengths don't match, with the usual warnings on vectors that don't repeat nicely.
I think this is even easier:
Seems easy enough, maybe not worth adding the complexity of a new argument, but people will try things like this: https://gis.stackexchange.com/questions/249762/is-there-a-convenient-way-to-calculate-distances-between-two-geometry-columns if there's no way documented.
The text was updated successfully, but these errors were encountered: