![](../logo.png)
For points that are not within polygons, find the nearest polygon edge
Source:R/assign_points_to_nearest_polygon.R
assign_points_to_nearest_polygon.Rd
For points that are not within polygons, find the nearest polygon edge
Source
https://stackoverflow.com/questions/72561812/return-polygon-nearest-to-a-point-using-terra-in-r
Examples
v <- terra::vect(system.file("ex/lux.shp", package="terra"))
pts <- matrix(c(5.812,6.577,5.864,50.126,49.774,49.488), ncol=2)
assign_points_to_nearest_polygon(pts[,1],pts[,2],v,'NAME_2')
#> x y NAME_2 n$distance
#> 1 5.812 50.126 Clervaux 6691.933
#> 2 6.577 49.774 Echternach 4290.021
#> 3 5.864 49.488 Esch-sur-Alzette 1473.792