我有一些海上的地理点和一张瑞典海域的 map .我想知道每个点位于哪个海域,对于海域以外的点,我想知道到最近海域的距离,包括最近海域的ID.
library(terra)
#> terra 1.7.71
map <- vect("/vsizip//vsicurl/https://www.smhi.se/polopoly_fs/1.140307!/Havsomr_SVAR_2016_3b.zip")
pts <- data.frame(id = 11:25,
lon = c(15.29416656, 15.10333347, 15.27083302, 15.27250004, 15.1291666,
15.31333351, 15.24166679, 15.30716705, 15.32333374, 15.38833332,
15.41416645, 15.40666676, 15.27166653, 15.26083374, 15.1916666),
lat = c(56.1566658, 56.15000153, 56.15250015, 56.13999939, 56.16383362,
56.15333176, 56.1558342, 56.17416763, 56.12366486, 56.14250183,
56.15916824, 56.17666626, 56.17666626, 56.17300034, 56.1570015)) |>
vect(geom = c("lon", "lat"), crs = "EPSG:4326") |>
project("EPSG:3006")
当你运行这个简单的代码时,你可以看到,to_id
总是NA
,并且是逻辑类型.我希望在列to_id
中有列"HID"
从map
(或其他ID从map).我能换个方式吗?
npol <- nearest(pts, map[, "HID"], centroids = FALSE)
npol
#> class : SpatVector
#> geometry : points
#> dimensions : 15, 5 (geometries, attributes)
#> extent : 506419.7, 525716.6, 6219890, 6225817 (xmin, xmax, ymin, ymax)
#> coord. ref. : SWEREF99 TM (EPSG:3006)
#> names : from_id from_x from_y to_id distance
#> type : <int> <num> <num> <logical> <num>
#> values : 1 5.183e+05 6.224e+06 <NA> 0
#> 2 5.064e+05 6.223e+06 <NA> 0
#> 3 5.168e+05 6.223e+06 <NA> 0