For a given geometry, find the closest point on that geometry to a point. The closest point may be an intersection, a single point, or unable to be determined.
Examples
x <- geom_linestring(1:100, runif(100, 0, 90), rep.int(1:10, 10))
y <- geom_point(runif(10, 0, 90), rnorm(10, 1, 90))
closest_point(x, y)
#> <rs_POINT[10]>
#> [1] Point(Coord { x: 45.20038162505294, y: 42.52502082047619 }))
#> [2] Point(Coord { x: 92.0, y: 12.961679510772228 }))
#> [3] Point(Coord { x: 43.72580651292919, y: 14.714065723836708 }))
#> [4] Point(Coord { x: 84.0, y: 5.564558221958578 }))
#> [5] Point(Coord { x: 47.21014832204954, y: 18.85557568561327 }))
#> [6] Point(Coord { x: 36.0, y: 80.16882274998352 }))
#> [7] Point(Coord { x: 56.09390007711945, y: 67.00533302322205 }))
#> [8] Point(Coord { x: 88.0, y: 10.999530816916376 }))
#> [9] Point(Coord { x: 39.0, y: 82.63939855853096 }))
#> [10] Point(Coord { x: 65.7788219896774, y: 66.29865566668514 }))
closest_point_haversine(x, y)
#> <rs_POINT[10]>
#> [1] Point(Coord { x: 41.73156577482473, y: 43.26463054944654 }))
#> [2] Point(Coord { x: 92.0, y: 12.961679510772228 }))
#> [3] Point(Coord { x: 43.01097116492144, y: 14.434168573293213 }))
#> [4] Point(Coord { x: 84.0, y: 5.564558221958578 }))
#> [5] Point(Coord { x: 45.36637903454789, y: 18.690145306311504 }))
#> [6] Point(Coord { x: 86.0, y: 4.3817520956508815 }))
#> [7] Point(Coord { x: 54.52434224864567, y: 67.15620066334344 }))
#> [8] Point(Coord { x: 98.0, y: 65.93228774378076 }))
#> [9] Point(Coord { x: 89.0, y: 88.89900405658409 }))
#> [10] Point(Coord { x: 70.0, y: 74.07823369838297 }))