/
pois.R
executable file
·90 lines (84 loc) · 2.74 KB
/
pois.R
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#' Openrouteservice POIs
#'
#' Search for points of interest around points or in geometries.
#'
#' There are three different request types: `pois`, `stats` and `list`.
#'
#' `pois` returns a GeoJSON FeatureCollection in the bounding box specified in
#' `geometry$bbox` or a GeoJSON geometry provided in `geometry$geojson`. `stats`
#' does the same but groups by categories, ultimately returning a JSON object
#' with the absolute numbers of POIs of a certain group.
#'
#' `list` returns a list of category groups and their ids.
#' @param request One of the following: `"pois"`, `"stats"` or `"list"`
#' @param geometry named list containing either a `geojson` geometry object
#' (GeoJSON Point, LineString or Polygon) or a `bbox`, optionally buffered by
#' a value provided `buffer`
#' @template param-common
#' @templateVar dotsargs request attributes
#' @templateVar endpoint pois
#' @template return
#' @templateVar return A list of points of interest in the area specified in `geometry`
#' @template return-text
#' @template return-parsed
#' @examples
#' # POI categories list
#' ors_pois('list')
#'
#' # POIs around a buffered point
#' geometry = list(geojson = list(type = "Point",
#' coordinates = c(8.8034, 53.0756)),
#' buffer = 100)
#' ors_pois(geometry = geometry)
#'
#' # alternative specification via bounding box
#' ors_pois(geometry = list(bbox = list(c(8.8034, 53.0756), c(8.8034, 53.0756)),
#' buffer = 100))
#'
#' # POIs of given categories
#' ors_pois(geometry = geometry,
#' limit = 200,
#' sortby = "distance",
#' filters = list(
#' category_ids = c(180, 245)
#' ))
#'
#' # POIs of given category groups
#' ors_pois(geometry = geometry,
#' limit = 200,
#' sortby = "distance",
#' filters = list(
#' category_group_ids = 160
#' ))
#'
#' # POI Statistics
#' ors_pois("stats", geometry = geometry)
#' @template author
#' @export
ors_pois <- function(request = c('pois', 'stats', 'list'),
geometry,
...,
api_key = ors_api_key(),
output = c("parsed", "text", "sf")) {
request <- match.arg(request)
output <- match.arg(output)
if (request!="pois" && output=="sf")
stop('"sf" output available only for request type "pois"')
dots <- list(...)
if (!is.null(dots[["filters"]]))
dots[["filters"]] <- protect(dots[["filters"]])
body <- c(request = request, dots)
if (request!="list") {
if (missing(geometry))
stop('Missing argument "geometry"')
else
body$geometry <- geometry
}
api_call(
"pois",
api_key = api_key,
body = body,
encode = "json",
output = output
)
}