GIScience / openrouteservice-r

:globe_with_meridians: query openrouteservice API from R
https://giscience.github.io/openrouteservice-r/
Apache License 2.0
98 stars 23 forks source link

First pass at sf output for #42 #45

Closed Robinlovelace closed 5 years ago

Robinlovelace commented 5 years ago

Heads-up @aoles this is a first pass. Initially I tried adding sf as an option to format like this:

format = c('json', 'geojson', 'gpx', 'sf')

However, that clashed with other things. I toyed with the idea of creating a new wrapper function, but see that you have quite a lean API and did not want to add to it. So this seemed a sensible solution. Please test and provide feedback. Clearly work is needed on the segements, as you say, an interesting challenge that @EricKrg and I discussed ages back, now implemented in the cyclestreets package.

In any case I think this is a first pass, having sf outputs will be useful for many people IMO, and the results are currently:

remotes::install_github("robinlovelace/openrouteservice-r", ref = "sf-directions")
## Skipping install of 'openrouteservice' from a github remote, the SHA1 (796c250b) has not changed since last install.
##   Use `force = TRUE` to force installation
r = openrouteservice::ors_directions(list(c(8.34234, 48.23424), c(8.34423, 48.26424)), output_sf = TRUE)
r
## Simple feature collection with 1 feature and 4 fields
## geometry type:  LINESTRING
## dimension:      XY
## bbox:           xmin: 8.327707 ymin: 48.23195 xmax: 8.345244 ymax: 48.26355
## epsg (SRID):    4326
## proj4string:    +proj=longlat +datum=WGS84 +no_defs
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 segments
## 1 [{"duration":810.6,"distance":5510.5,"steps":[{"duration":61.2,"distance":255,"instruction":"Head south on Benatweg","name":"Benatweg","type":11,"way_points":[0,9]},{"duration":12.6,"distance":52.4,"instruction":"Continue straight onto Benatweg","name":"Benatweg","type":6,"way_points":[9,12]},{"duration":135.1,"distance":1688.7,"instruction":"Turn right onto Hölzle, K 5528","name":"Hölzle, K 5528","type":1,"way_points":[12,63]},{"duration":31.8,"distance":265.2,"instruction":"Keep right","name":"","type":13,"way_points":[63,71]},{"duration":36.3,"distance":302.8,"instruction":"Turn left","name":"","type":0,"way_points":[71,80]},{"duration":64.4,"distance":536.7,"instruction":"Turn left","name":"","type":0,"way_points":[80,92]},{"duration":29.7,"distance":247.6,"instruction":"Keep right","name":"","type":13,"way_points":[92,101]},{"duration":52.9,"distance":293.7,"instruction":"Turn right","name":"","type":1,"way_points":[101,111]},{"duration":45.4,"distance":252.4,"instruction":"Keep left","name":"","type":12,"way_points":[111,117]},{"duration":67.6,"distance":370.6,"instruction":"Keep right","name":"","type":13,"way_points":[117,126]},{"duration":111.9,"distance":572.1,"instruction":"Keep left","name":"","type":12,"way_points":[126,142]},{"duration":9,"distance":37.6,"instruction":"Turn left","name":"","type":0,"way_points":[142,145]},{"duration":112.8,"distance":469.9,"instruction":"Keep left","name":"","type":12,"way_points":[145,159]},{"duration":39.8,"distance":165.9,"instruction":"Turn sharp left","name":"","type":2,"way_points":[159,164]},{"duration":0,"distance":0,"instruction":"Arrive at your destination, on the right","name":"","type":10,"way_points":[164,164]}]}]
##                                      bbox way_points
## 1 [8.327707,48.231946,8.345244,48.263552]    [0,164]
##                                  summary                       geometry
## 1 [{"duration":810.6,"distance":5510.5}] LINESTRING (8.344268 48.233...
plot(r)

image

aoles commented 5 years ago

Resolved via https://github.com/GIScience/openrouteservice-r/pull/49.