GIScience / openrouteservice-r

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

Add classic TSP example to the vignette #47

Open aoles opened 5 years ago

aoles commented 5 years ago

Enable ors_optimization endpoint to the vroom-based route optimization engine.

TimMcCauley commented 5 years ago

@aoles let us please wait for this until we have tested it throughly, thanks a lot

aoles commented 5 years ago

@TimMcCauley Exactly, don't you think that previewing in here would be a good real-life test? As the package is considered a "beta" product I'm positive on exposing some of the experimental features, and I'm pretty sure users won't mind either even if things break.

TimMcCauley commented 5 years ago

@aoles we haven't load tested this service yet and have no idea how the box will react to load. Once this is done, we can definitely go ahead. Stay tuned ;)

aoles commented 5 years ago

As an example provide the classic TSP example.


library(openrouteservice)
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.1.3, PROJ 4.9.3

capitals <- data.frame(locality = c("Warsaw", "Berlin", "Rome", "Paris"),
                       country = c("Poland", "Germany", "Italy", "France"))

## query for geocoordiantes
res = apply(capitals, 1, ors_geocode, size = 1, output = "sf") 

## combine results into a single sf object
capitals_sf <- do.call(rbind, lapply(res, function(x) x[c("locality", "country")]))

## extract coordinate matrix
st_coordinates(capitals_sf)
#>          X        Y
#> 1 21.01178 52.22977
#> 2 13.40732 52.52045
#> 3 12.51133 41.89193
#> 4  2.34444 48.86000

Created on 2019-05-24 by the reprex package (v0.2.1)