Skip to content

Commit

Permalink
First pass at sf output for GIScience#42
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Mar 26, 2019
1 parent 87a03dd commit 796c250
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
13 changes: 11 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ Description: The package streamlines access to the services provided by openrout
It allows you to painlessly query for directions, geocoding, isochrones, time-distance matrices, and POIs.
URL: https://github.com/GIScience/openrouteservice-r
BugReports: https://github.com/GIScience/openrouteservice-r/issues
Imports: geojson, geojsonlint, httr, jsonlite, keyring, leaflet, utils, xml2
Imports:
geojson,
geojsonlint,
httr,
jsonlite,
keyring,
leaflet,
utils,
xml2,
geojsonsf
Suggests: covr, ggplot2, knitr, pkgdown, RColorBrewer, rmarkdown, roxygen2, sp, testthat
License: Apache License 2.0 | file LICENSE
Encoding: UTF-8
LazyData: true
VignetteBuilder: knitr
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.0.1
RoxygenNote: 6.1.1
24 changes: 18 additions & 6 deletions R/directions.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#'
#' # simple call
#' ors_directions(coordinates, preference="fastest")
#'
#' #customized options

#' # sf output
#' ors_directions(coordinates, preference="fastest", output_sf = TRUE)

#' # customized options
#' ors_directions(coordinates, profile="cycling-mountain", elevation=TRUE, format="geojson")
#' @template author
#' @export
Expand All @@ -26,18 +29,27 @@ ors_directions <- function(coordinates,
format = c('json', 'geojson', 'gpx'),
...,
api_key = ors_api_key(),
parse_output = NULL) {
parse_output = NULL,
output_sf = FALSE) {
if (missing(coordinates))
stop('Missing argument "coordinates"')

profile = match.arg(profile)

format = match.arg(format)
if(output_sf) {
format = "geojson"
} else {
format = match.arg(format)
}
response_format = switch(format, 'gpx'='xml', 'json')

params = list(coordinates = coordinates, profile = profile, format = format, ...)

query = api_query(api_key, params)

api_call("directions", "GET", query, response_format = response_format, parse_output = parse_output)
if(output_sf) {
a = api_call("directions", "GET", query, response_format = response_format, parse_output = FALSE)
geojsonsf::geojson_sf(a)
} else {
api_call("directions", "GET", query, response_format = response_format, parse_output = parse_output)
}
}
7 changes: 4 additions & 3 deletions man/ors_directions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 796c250

Please sign in to comment.