geo_distance: Calculate distance between two GeoJSON points

Description Usage Arguments Value Examples

View source: R/distance.R

Description

Calculate distance between two GeoJSON points

Usage

1
geo_distance(from, to, units = "kilometers")

Arguments

from

Origin Feature<Point>

to

Destination Feature<Point>

units

(character) Can be degrees, radians, miles, or kilometers (default)

Value

the distance, a single numeric value, in units given in units parameter

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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)
geo_distance(point1, point2, units = "miles")
geo_distance(point1, point2, units = "degrees")
geo_distance(point1, point2, units = "radians")

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")

ropenscilabs/geoops documentation built on Jan. 1, 2021, 4:03 p.m.