Sf: Spatial join based on proximity (closest)

Created on 31 Jan 2017  路  6Comments  路  Source: r-spatial/sf

ArcMap allows for a spatial join with the parameter CLOSEST.

Would it be possible to implement this as a feature via something like st_closest(x, y, ...)?

Most helpful comment

Update: I've been using the nabor package and it works great on 2 sets of matrices: https://cran.r-project.org/package=nabor

That would be my default strategy and, having used it in stplanr I guess it would be fast and scalable, and really useful, either as st_nearest(x, y) which could go straight into st_join() or as a closest parameter as the original post suggested.

All 6 comments

There is, afaics, not a function in GEOS that we can use for this, so the implementation would have to use st_distance, and then select the closest. So possible yes, but it wouldn't scale nicely, nor be efficient.

I believe an equivalent to postgis st_dwithin could be useful for a spatial join based on proximity, but it doesn't solve your immediate problem. I'd be interested to know how k-NN packages scale that problem?

If two sets of points are represented as matrices I guess that would work. There are loads of options including knn() in base R and this one: https://github.com/davpinto/fastknn

Appreciate this is closed and not asking as a feature request but just out of curiosity would that be possible?

Update: I've been using the nabor package and it works great on 2 sets of matrices: https://cran.r-project.org/package=nabor

That would be my default strategy and, having used it in stplanr I guess it would be fast and scalable, and really useful, either as st_nearest(x, y) which could go straight into st_join() or as a closest parameter as the original post suggested.

I think this would be a great feature (see, this question and this question)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dpprdan picture dpprdan  路  4Comments

Nowosad picture Nowosad  路  3Comments

ekarsten picture ekarsten  路  4Comments

tiernanmartin picture tiernanmartin  路  3Comments

jmsigner picture jmsigner  路  4Comments