Skip to content

Commit d33e1ca

Browse files
authored
Merge pull request #82 from GIScience/feat/add_snap_endpoint
feat: Add snapping endpoint
2 parents b840b4a + 75563d7 commit d33e1ca

20 files changed

+154
-25
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: openrouteservice
22
Title: Openrouteservice API Client
3-
Version: 0.4.2
4-
Authors@R: person("Andrzej", "Oleś", email = "andrzej@openrouteservice.org", comment = c(ORCID = "0000-0003-0285-2787"), role = c("aut", "cre"))
3+
Version: 0.5.0
4+
Authors@R: person("Andrzej", "Oleś", email = "andrzej.oles@gmail.com", comment = c(ORCID = "0000-0003-0285-2787"), role = c("aut", "cre"))
55
Description: The package streamlines access to the services provided by openrouteservice.org.
66
It allows you to painlessly query for directions, geocoding, isochrones, time-distance matrices, and POIs.
77
URL: https://github.com/GIScience/openrouteservice-r
@@ -13,4 +13,4 @@ Encoding: UTF-8
1313
LazyData: true
1414
VignetteBuilder: knitr
1515
Roxygen: list(markdown = TRUE)
16-
RoxygenNote: 7.2.3
16+
RoxygenNote: 7.3.1

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export(ors_matrix)
1212
export(ors_optimization)
1313
export(ors_pois)
1414
export(ors_profile)
15+
export(ors_snap)
1516
export(vehicles)
1617
importFrom(V8,v8)
1718
importFrom(geojsonsf,geojson_sf)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# openrouteservice 0.5.0
2+
3+
## NEW FEATURES
4+
5+
- Enable snap endpoint.
6+
17
# openrouteservice 0.4.0
28

39
## NEW FEATURES

R/api_call.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ ors_path <- function(endpoint) {
8282
geocode = "geocode",
8383
pois = "pois",
8484
elevation = "elevation",
85-
optimization = "optimization"
85+
optimization = "optimization",
86+
snap = "v2/snap"
8687
)
8788
if (missing(endpoint))
8889
return(default_paths)

R/doc_utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
doc_url <- function(service) {
22
url_template <- switch(service,
3-
directions =, isochrones =, matrix = "https://openrouteservice.org/dev/#/api-docs/v2/%s/{profile}/post",
3+
directions =, isochrones =, matrix =, snap = "https://openrouteservice.org/dev/#/api-docs/v2/%s/{profile}/post",
44
pois =, optimization = "https://openrouteservice.org/dev/#/api-docs/%s/post",
55
"https://openrouteservice.org/dev/#/api-docs/%s")
66
sprintf(url_template, service)

R/snap.R

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#' Openrouteservice Snapping
2+
#'
3+
#' Snap coordinates to road network
4+
#'
5+
#' @template param-coordinates
6+
#' @templateVar argname locations
7+
#' @template param-profile
8+
#' @param radius Maximum radius in meters around given coordinates to search for graph edges
9+
#' @param format Response format, defaults to `"geojson"`
10+
#' @template param-common
11+
#' @templateVar dotsargs parameters
12+
#' @templateVar endpoint snap
13+
#' @template return
14+
#' @templateVar return Coordinates of snapped location(s) and distance to the original point(s)
15+
#' @template return-text
16+
#' @template return-parsed
17+
#' @examples
18+
#' locations = list(
19+
#' c(8.669629, 49.413025),
20+
#' c(8.675841, 49.418532),
21+
#' c(8.665144, 49.415594)
22+
#' )
23+
#'
24+
#' # query for duration and distance in km
25+
#' res = ors_snap(locations, radius = 350)
26+
#'
27+
#' @template author
28+
#' @export
29+
ors_snap <- function(locations,
30+
profile = ors_profile(),
31+
radius,
32+
format = c('geojson', 'json'),
33+
...,
34+
api_key = ors_api_key(),
35+
output = c("parsed", "text")) {
36+
## required arguments with no default value
37+
if (missing(locations))
38+
stop('Missing argument "locations"')
39+
if (missing(radius))
40+
stop('Missing argument "radius"')
41+
42+
## required arguments with defaults
43+
profile <- match.arg(profile)
44+
format <- match.arg(format)
45+
output <- match.arg(output)
46+
47+
names(locations) <- NULL
48+
49+
## request parameters
50+
body <- list(locations = locations, radius = radius, ...)
51+
52+
api_call(
53+
path = c("v2/snap", profile, format),
54+
api_key = api_key,
55+
body = body,
56+
encode = "json",
57+
output = output
58+
)
59+
}

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ allows you to painlessly consume the following services:
1212

1313
- [directions](https://openrouteservice.org/dev/#/api-docs/v2/directions/%7Bprofile%7D/post)
1414
(routing)
15-
- [geocode](https://openrouteservice.org/dev/#/api-docs/geocode)
15+
- [geocoding](https://openrouteservice.org/dev/#/api-docs/geocode)
1616
powered by [Pelias](https://pelias.io)
1717
- [isochrones](https://openrouteservice.org/dev/#/api-docs/v2/isochrones/%7Bprofile%7D/post)
1818
(accessibility)
1919
- time-distance
2020
[matrix](https://openrouteservice.org/dev/#/api-docs/v2/matrix/%7Bprofile%7D/post)
21+
- [snapping](https://openrouteservice.org/dev/#/api-docs/snap) to ways
2122
- [pois](https://openrouteservice.org/dev/#/api-docs/pois/post)
2223
(points of interest)
2324
- SRTM
@@ -68,11 +69,18 @@ defaults are equivalent of having
6869
geocode = "geocode",
6970
pois = "pois",
7071
elevation = "elevation",
71-
optimization = "optimization"))
72+
optimization = "optimization",
73+
snap = "v2/snap"))
7274

7375
Package News
7476
------------
7577

78+
### version 0.5.0
79+
80+
#### NEW FEATURES
81+
82+
- Enable snap endpoint.
83+
7684
### version 0.4.0
7785

7886
#### NEW FEATURES
@@ -84,9 +92,3 @@ Package News
8492
#### BUG FIXES
8593

8694
- Fixed resolving of URL paths to endpoints.
87-
88-
### version 0.3.2
89-
90-
#### NEW FEATURES
91-
92-
- More descriptive messages for API response errors.

man-roxygen/author.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#' @author Andrzej Oleś <andrzej@@openrouteservice.org>
1+
#' @author Andrzej Oleś <andrzej.oles@@gmail.com>

man/fitBBox.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ors_api_key.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)