Skip to content

Commit 91803ee

Browse files
committed
Add examples of input query as character strings
1 parent 27606ce commit 91803ee

11 files changed

+214
-15
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Mention key-only feature requests in README (#342 thanks to @joostschouppe)
1414
- Merge any columns in `osmdata_sf()` with mixed-case duplicated names (#348)
1515
- Set encoding to UTF-8 for tags and user names (#347)
16+
- Document the use of the input query as character strings for `osmdata_*()` (#349)
1617

1718

1819
0.2.5

R/get-osmdata-df.R

+21-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#'
44
#' @inheritParams osmdata_sp
55
#' @param q An object of class `overpass_query` constructed with
6-
#' \link{opq} and \link{add_osm_feature} or a string with a valid query.
6+
#' \link{opq} and \link{add_osm_feature} or a string with a valid query, such
7+
#' as `"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"`.
78
#' May be be omitted, in which case the attributes of the \link{data.frame}
8-
#' will not include the query.
9+
#' will not include the query. See examples below.
910
#' @param stringsAsFactors Should character strings in the 'data.frame' be
1011
#' coerced to factors?
1112
#' @return A `data.frame` with id, type and tags of the the objects from the
@@ -27,6 +28,24 @@
2728
#' attr (hampi_df, "bbox")
2829
#' attr (hampi_df, "overpass_call")
2930
#' attr (hampi_df, "meta")
31+
#'
32+
#' # Complex query as a string (not possible with regular osmdata functions)
33+
#' q <- '[out:csv(::type, ::id, "name:ca", "wikidata")][timeout:50];
34+
#' area["name"="Països Catalans"][boundary=political]->.boundaryarea;
35+
#'
36+
#' rel(area.boundaryarea)[admin_level=8][boundary=administrative];
37+
#' map_to_area -> .all_level_8_areas;
38+
#'
39+
#' ( nwr(area.boundaryarea)["amenity"="townhall"];>;);
40+
#' is_in;
41+
#' area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall;
42+
#'
43+
#' (.all_level_8_areas; - .level_8_areas_with_townhall;);
44+
#' rel(pivot);
45+
#' out tags;'
46+
#'
47+
#' no_townhall <- osmdata_data_frame (q)
48+
#' no_townhall
3049
#' }
3150
osmdata_data_frame <- function (q,
3251
doc,

R/get-osmdata-sc.R

+20-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@
1616
#' hampi_sf <- opq ("hampi india") %>%
1717
#' add_osm_feature (key = "historic", value = "ruins") %>%
1818
#' osmdata_sc ()
19+
#'
20+
#' # Complex query as a string (not possible with regular osmdata functions)
21+
#' q <- '[out:xml][timeout:50];
22+
#' area["name"="Països Catalans"][boundary=political]->.boundaryarea;
23+
#'
24+
#' rel(area.boundaryarea)[admin_level=8][boundary=administrative];
25+
#' map_to_area -> .all_level_8_areas;
26+
#'
27+
#' ( nwr(area.boundaryarea)["amenity"="townhall"];>;);
28+
#' is_in;
29+
#' area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall;
30+
#'
31+
#' (.all_level_8_areas; - .level_8_areas_with_townhall;);
32+
#' rel(pivot);
33+
#' (._;>;);
34+
#' out;'
35+
#'
36+
#' no_townhall <- osmdata_sc (q)
37+
#' no_townhall
1938
#' }
2039
osmdata_sc <- function (q, doc, quiet = TRUE) {
2140

@@ -76,7 +95,7 @@ osmdata_sc <- function (q, doc, quiet = TRUE) {
7695
)
7796

7897
has_tags <- c ("nodes", "relation_properties", "object")
79-
obj [has_tags] <- lapply(obj [has_tags], function (x) {
98+
obj [has_tags] <- lapply (obj [has_tags], function (x) {
8099
x [, c ("key", "value")] <- setenc_utf8 (x [, c ("key", "value")])
81100
x
82101
})

R/get-osmdata-sf.R

+19
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@
1515
#' hampi_sf <- opq ("hampi india") %>%
1616
#' add_osm_feature (key = "historic", value = "ruins") %>%
1717
#' osmdata_sf ()
18+
#'
19+
#' # Complex query as a string (not possible with regular osmdata functions)
20+
#' q <- '[out:xml][timeout:50];
21+
#' area["name"="Països Catalans"][boundary=political]->.boundaryarea;
22+
#'
23+
#' rel(area.boundaryarea)[admin_level=8][boundary=administrative];
24+
#' map_to_area -> .all_level_8_areas;
25+
#'
26+
#' ( nwr(area.boundaryarea)["amenity"="townhall"];>;);
27+
#' is_in;
28+
#' area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall;
29+
#'
30+
#' (.all_level_8_areas; - .level_8_areas_with_townhall;);
31+
#' rel(pivot);
32+
#' (._;>;);
33+
#' out;'
34+
#'
35+
#' no_townhall <- osmdata_sf (q)
36+
#' no_townhall
1837
#' }
1938
osmdata_sf <- function (q, doc, quiet = TRUE, stringsAsFactors = FALSE) { # nolint
2039

R/get-osmdata-sp.R

+23-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#' format.
33
#'
44
#' @param q An object of class `overpass_query` constructed with
5-
#' \link{opq} and \link{add_osm_feature} or a string with a valid query.
5+
#' \link{opq} and \link{add_osm_feature} or a string with a valid query, such
6+
#' as `"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"`.
7+
#' 39.4712701,-0.3841326,39.4713799,-0.3839475
68
#' May be be omitted, in which case the \link{osmdata} object will not
7-
#' include the query.
9+
#' include the query. See examples below.
810
#' @param doc If missing, `doc` is obtained by issuing the overpass query,
911
#' `q`, otherwise either the name of a file from which to read data,
1012
#' or an object of class \pkg{xml2} returned from \link{osmdata_xml}.
@@ -21,6 +23,25 @@
2123
#' hampi_sp <- opq ("hampi india") %>%
2224
#' add_osm_feature (key = "historic", value = "ruins") %>%
2325
#' osmdata_sp ()
26+
#'
27+
#' # Complex query as a string (not possible with regular osmdata functions)
28+
#' q <- '[out:xml][timeout:50];
29+
#' area["name"="Països Catalans"][boundary=political]->.boundaryarea;
30+
#'
31+
#' rel(area.boundaryarea)[admin_level=8][boundary=administrative];
32+
#' map_to_area -> .all_level_8_areas;
33+
#'
34+
#' ( nwr(area.boundaryarea)["amenity"="townhall"];>;);
35+
#' is_in;
36+
#' area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall;
37+
#'
38+
#' (.all_level_8_areas; - .level_8_areas_with_townhall;);
39+
#' rel(pivot);
40+
#' (._;>;);
41+
#' out;'
42+
#'
43+
#' no_townhall <- osmdata_sp (q)
44+
#' no_townhall
2445
#' }
2546
osmdata_sp <- function (q, doc, quiet = TRUE) {
2647

R/get-osmdata-xml.R

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#' or a raw vector.
44
#'
55
#' @param q An object of class `overpass_query` constructed with
6-
#' \link{opq} and \link{add_osm_feature} or a string with a valid query.
6+
#' \link{opq} and \link{add_osm_feature} or a string with a valid query, such
7+
#' as `"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"`. See examples below.
78
#' @param filename If given, OSM data are saved to the named file
89
#' @param quiet suppress status messages.
910
#' @param encoding Unless otherwise specified XML documents are assumed to be
@@ -23,6 +24,24 @@
2324
#' q <- opq ("hampi india")
2425
#' q <- add_osm_feature (q, key = "historic", value = "ruins")
2526
#' osmdata_xml (q, filename = "hampi.osm")
27+
#'
28+
#' # Complex query as a string (not possible with regular osmdata functions)
29+
#' q <- '[out:xml][timeout:50];
30+
#' area["name"="Països Catalans"][boundary=political]->.boundaryarea;
31+
#'
32+
#' rel(area.boundaryarea)[admin_level=8][boundary=administrative];
33+
#' map_to_area -> .all_level_8_areas;
34+
#'
35+
#' ( nwr(area.boundaryarea)["amenity"="townhall"];>;);
36+
#' is_in;
37+
#' area._[admin_level=8][boundary=administrative] -> .level_8_areas_with_townhall;
38+
#'
39+
#' (.all_level_8_areas; - .level_8_areas_with_townhall;);
40+
#' rel(pivot);
41+
#' out tags;'
42+
#'
43+
#' no_townhall <- osmdata_xml (q)
44+
#' no_townhall
2645
#' }
2746
osmdata_xml <- function (q, filename, quiet = TRUE, encoding) {
2847

man/osmdata_data_frame.Rd

+21-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/osmdata_sc.Rd

+23-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/osmdata_sf.Rd

+23-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/osmdata_sp.Rd

+23-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/osmdata_xml.Rd

+20-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)