The distanceto
package is designed to quickly sample distances from points
features to other vector layers. Normally the approach for calculating distance
to (something) involves generating distance surfaces using raster based approaches
eg. raster::distance
or gdal_proximity
and subsequently point sampling these
surfaces. Since raster based approaches are a costly method that frequently leads
to memory issues or long and slow run times with high resolution data or large
study sites, we have opted to compute these distances using vector based
approaches. As a helper, there's a decidedly low-res raster based approach for
visually inspecting your region's distance surface. But the workhorse is
distance_to
. See the Example.
install.packages('distanceto', repos = 'https://robitalec.r-universe.dev')
library(distanceto) library(sf) # Load nc data nc <- st_read(system.file("shape/nc.shp", package="sf")) # Set number of sampling points npts <- 1e3 # Sample points in nc ncpts <- st_sample(nc, npts) # Select first 5 of nc ncsub <- nc[1:5,] # Measure distance from ncpts to first 5 of nc dists <- distance_to(ncpts, ncsub, measure = 'geodesic') head(dists, 30) # Add to ncpts ncpts$dist <- dists
nngeo::st_nn
gdal_proximity
raster::distance
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.