View source: R/spatial_functions.R
st_nearest_distance_rcpp | R Documentation |
RcppParallel distance to nearest point
st_nearest_distance_rcpp(x, y = NULL, unit = "mi")
x |
Object of class sf/sfc or a matrix of coordinates. If a
matrix of coordinates, use column order from |
y |
Object of class sf/sfc or a matrix of coordinates. If a
matrix of coordinates, use column order from |
unit |
Either "mi", "km", or "m". Sets the output distance. |
Matrix of two columns. First column is index corresponding to the closest row of y. The second column is the distance to that element.
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_distance_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] "Distance in miles. To use kilometers use option `unit == 'km'`" #> [,1] [,2] #> [1,] 2 229.73605 #> [2,] 2 209.60042 #> [3,] 2 185.08250 #> [4,] 1 0.00000 #> [5,] 2 0.00000 #> [6,] 3 0.00000 #> [7,] 1 14.14835 #> [8,] 3 18.02233 #> [9,] 2 41.72334 #> [10,] 2 159.57142 #> [11,] 2 109.53959 #> [12,] 2 133.84909 #> [13,] 2 71.85292 #> [14,] 2 89.53327 #> [15,] 2 57.74066 #> [16,] 2 18.96815 #> [17,] 1 21.04779 #> [18,] 2 211.99947 #> [19,] 2 241.47884 #> [20,] 1 29.20456 #> [21,] 3 25.73479 #> [22,] 2 254.56215 #> [23,] 2 183.87038 #> [24,] 2 57.68215 #> [25,] 2 161.54421 #> [26,] 2 135.55211 #> [27,] 2 116.34562 #> [28,] 3 26.59132 #> [29,] 2 101.73244 #> [30,] 2 86.27160 #> [31,] 2 44.81515 #> [32,] 2 266.65497 #> [33,] 2 30.10878 #> [34,] 2 235.60231 #> [35,] 2 277.30770 #> [36,] 2 35.45618 #> [37,] 2 79.67621 #> [38,] 2 298.50068 #> [39,] 2 201.00005 #> [40,] 2 179.12565 #> [41,] 2 215.08451 #> [42,] 2 166.39281 #> [43,] 2 244.61906 #> [44,] 3 46.50057 #> [45,] 1 40.58824 #> [46,] 2 264.67018 #> [47,] 2 143.89706 #> [48,] 2 114.93850 #> [49,] 2 54.39784 #> [50,] 2 183.36085 #> [51,] 2 54.25093 #> [52,] 2 219.93620 #> [53,] 2 293.76230 #> [54,] 2 78.88295 #> [55,] 2 318.34166 #> [56,] 1 37.37779 #> [57,] 3 59.08642 #> [58,] 2 353.02825 #> [59,] 2 61.61206 #> [60,] 2 119.26415 #> [61,] 2 263.17224 #> [62,] 2 75.20343 #> [63,] 2 107.00198 #> [64,] 2 244.20464 #> [65,] 2 223.86813 #> [66,] 2 331.06570 #> [67,] 2 138.89912 #> [68,] 2 208.22132 #> [69,] 2 191.16795 #> [70,] 2 158.36184 #> [71,] 2 175.89807 #> [72,] 2 294.66099 #> [73,] 2 368.02148 #> [74,] 2 81.57910 #> [75,] 2 313.29691 #> [76,] 2 225.75525 #> [77,] 2 279.17074 #> [78,] 2 352.39499 #> [79,] 2 113.17929 #> [80,] 3 87.59381 #> [81,] 2 384.58393 #> [82,] 2 123.42840 #> [83,] 2 92.68169 #> [84,] 2 201.60596 #> [85,] 2 179.70678 #> [86,] 2 140.43951 #> [87,] 1 56.01964 #> [88,] 2 102.05836 #> [89,] 2 162.28763 #> [90,] 2 368.99577 #> [91,] 2 77.65407 #> [92,] 2 158.09390 #> [93,] 2 111.38300 #> [94,] 2 155.49374 #> [95,] 1 105.01184 #> [96,] 2 137.75615 #> [97,] 2 130.73635 #> [98,] 2 164.67485 #> [99,] 2 150.66982 #> [100,] 2 163.86719
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.