I have polygons (polygon.shp). I want to match the nearest points to the polygons. The link to the file LINK
I am trying to achieve the following task:
- Calculate the distance to the nearest point from the boundary of the polygon (NOT from the centroid of polygons)
- For some polygons I have to match more than one nearest point (see "no_matches" attribute)
In the final output I am planning to achieve the following information: Column: id, no_matches, point_id_1, distance_1, point_id_2, distance_2, point_id_3, distance_3
setwd("~/example")
library(sf)
polygon <- st_read("polygon.shp")
point <- st_read("point.shp")
nearest = try(sf::st_nearest_feature(polygon, point))
ls = sf::st_nearest_points( polygon, point[nearest], pairwise = F)
I get the following error:
Error in `[.data.frame`(x, i) : undefined columns selected
Any idea how could I achieve this task?