st_nearest_rcpp: RcppParallel version of 'st_nearest_feature'

View source: R/spatial_functions.R

st_nearest_rcppR Documentation

RcppParallel version of st_nearest_feature

Description

RcppParallel version of st_nearest_feature

Usage

st_nearest_rcpp(x, y = NULL)

Arguments

x

Object of class sf/sfc or a matrix of coordinates. If a matrix of coordinates, use column order from st_coordinates().

y

Object of class sf/sfc or a matrix of coordinates. If a matrix of coordinates, use column order from st_coordinates(). If missing, computes distance to nearest non-self element of x.

Value

Vector. Indices corresponding to row of y that is closest to each element of x.

Examples

library(sf)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source 
#>   `/Users/kbutts/Library/R/arm64/4.4/library/sf/shape/nc.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27
st_nearest_rcpp(nc, nc[4:6,])
#> Warning in st_point_on_surface.sfc(x): st_point_on_surface may not give correct
#> results for longitude/latitude data
#> Warning in st_point_on_surface.sfc(y): st_point_on_surface may not give correct
#> results for longitude/latitude data
#>   [1] 2 2 2 1 2 3 1 3 2 2 2 2 2 2 2 2 1 2 2 1 3 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2
#>  [38] 2 2 2 2 2 2 3 1 2 2 2 2 2 2 2 2 2 2 1 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
#>  [75] 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2

kylebutts/kfbmisc documentation built on April 17, 2025, 5:20 p.m.