Skip to contents

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.

Usage

closest_point(x, y)

closest_point_haversine(x, y)

Arguments

x

an object of class rsgeo

y

an object of class rs_POINT

Value

An rs_POINT vector

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: 42.105933494785695, y: 66.06050124702755 }))
#>  [2] Point(Coord { x: 50.04989634195688, y: 74.61122189706461 })) 
#>  [3] Point(Coord { x: 29.0, y: 2.5417980761267245 }))             
#>  [4] Point(Coord { x: 67.0, y: 89.15954707190394 }))              
#>  [5] Point(Coord { x: 10.0, y: 0.10015812702476978 }))            
#>  [6] Point(Coord { x: 21.0, y: 30.82952815806493 }))              
#>  [7] Point(Coord { x: 18.0, y: 77.03447380336002 }))              
#>  [8] Point(Coord { x: 73.0, y: 4.822875838726759 }))              
#>  [9] Point(Coord { x: 4.0, y: 16.481087976135314 }))              
#> [10] Point(Coord { x: 56.0, y: 4.848692351952195 }))              
closest_point_haversine(x, y)
#> <rs_POINT[10]>
#>  [1] Point(Coord { x: 36.84497877613438, y: 67.96936835838562 }))
#>  [2] Point(Coord { x: 68.22521853475159, y: 74.57662287461321 }))
#>  [3] Point(Coord { x: 29.0, y: 2.5417980761267245 }))            
#>  [4] Point(Coord { x: 67.0, y: 89.15954707190394 }))             
#>  [5] Point(Coord { x: 10.0, y: 0.10015812702476978 }))           
#>  [6] Point(Coord { x: 21.0, y: 30.82952815806493 }))             
#>  [7] Point(Coord { x: 98.0, y: 65.52344706840813 }))             
#>  [8] Point(Coord { x: 73.0, y: 4.822875838726759 }))             
#>  [9] Point(Coord { x: 4.0, y: 16.481087976135314 }))             
#> [10] Point(Coord { x: 56.0, y: 4.848692351952195 }))