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: 5.0, y: 7.449113731272519 }))  
#>  [2] Point(Coord { x: 81.0, y: 29.840561191085726 }))
#>  [3] Point(Coord { x: 36.0, y: 4.523327888455242 })) 
#>  [4] Point(Coord { x: 67.0, y: 16.668208139017224 }))
#>  [5] Point(Coord { x: 20.0, y: 11.72312163747847 })) 
#>  [6] Point(Coord { x: 83.0, y: 28.56330905808136 })) 
#>  [7] Point(Coord { x: 14.0, y: 4.244143373798579 })) 
#>  [8] Point(Coord { x: 9.0, y: 30.438028047792614 })) 
#>  [9] Point(Coord { x: 2.0, y: 16.038183497730643 })) 
#> [10] Point(Coord { x: 48.0, y: 11.376974894665182 }))
closest_point_haversine(x, y)
#> <rs_POINT[10]>
#>  [1] Point(Coord { x: 5.0, y: 7.449113731272519 }))  
#>  [2] Point(Coord { x: 81.0, y: 29.840561191085726 }))
#>  [3] Point(Coord { x: 36.0, y: 4.523327888455242 })) 
#>  [4] Point(Coord { x: 67.0, y: 16.668208139017224 }))
#>  [5] Point(Coord { x: 20.0, y: 11.72312163747847 })) 
#>  [6] Point(Coord { x: 83.0, y: 28.56330905808136 })) 
#>  [7] Point(Coord { x: 84.0, y: 84.27560745505616 })) 
#>  [8] Point(Coord { x: 9.0, y: 30.438028047792614 })) 
#>  [9] Point(Coord { x: 92.0, y: 2.127406275831163 })) 
#> [10] Point(Coord { x: 48.0, y: 11.376974894665182 }))