Calculate distance between two GeoJSON points
Examples
point1 <- '{
"type": "Feature",
"properties": {
"marker-color": "#f00"
},
"geometry": {
"type": "Point",
"coordinates": [-75.343, 39.984]
}
}'
point2 <- '{
"type": "Feature",
"properties": {
"marker-color": "#0f0"
},
"geometry": {
"type": "Point",
"coordinates": [-75.534, 39.123]
}
}'
geo_distance(point1, point2)
#> [1] 97.15958
geo_distance(point1, point2, units = "miles")
#> [1] 60.37218
geo_distance(point1, point2, units = "degrees")
#> [1] 0.8735029
geo_distance(point1, point2, units = "radians")
#> [1] 0.0152455
pt1 <- '{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
0.5,
0.5
]
}
}'
pt2 <- '{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [2, 2]
}
}'
geo_distance(pt1, pt2, units = "miles")
#> [1] 146.5956