From 0955f0a37f6317e50bd3b3ded547f9757ee09fbf Mon Sep 17 00:00:00 2001 From: Joan Maspons Date: Wed, 18 Mar 2026 11:16:13 +0100 Subject: [PATCH 1/5] Update function names in tests All tests passed without changes before this commit. Old functions still work --- DESCRIPTION | 2 +- NAMESPACE | 2 + NEWS.md | 1 + R/opq.R | 50 ++++++++++++++++--- man/{add_osm_features.Rd => add_osm_tags.Rd} | 7 ++- man/bbox_to_string.Rd | 4 +- ...{add_osm_feature.Rd => filter_osm_tags.Rd} | 15 +++++- man/filter_osm_user.Rd | 4 +- man/getbb.Rd | 4 +- man/opq.Rd | 4 +- man/opq_around.Rd | 4 +- man/opq_csv.Rd | 4 +- man/opq_enclosing.Rd | 4 +- man/opq_osm_id.Rd | 4 +- man/opq_string.Rd | 4 +- man/overpass_status.Rd | 4 +- 16 files changed, 86 insertions(+), 31 deletions(-) rename man/{add_osm_features.Rd => add_osm_tags.Rd} (95%) rename man/{add_osm_feature.Rd => filter_osm_tags.Rd} (95%) diff --git a/DESCRIPTION b/DESCRIPTION index dcfe6bd0..2a83b83c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: osmdata Title: Import 'OpenStreetMap' Data as Simple Features or Spatial Objects -Version: 0.3.0.9026 +Version: 0.3.0.9027 Authors@R: c( person("Joan", "Maspons", , "joanmaspons@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2286-8727")), diff --git a/NAMESPACE b/NAMESPACE index 2fdc51ae..ecbc56b7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,9 +15,11 @@ S3method(trim_osmdata,osmdata_sf) S3method(trim_osmdata,osmdata_sp) export(add_osm_feature) export(add_osm_features) +export(add_osm_tags) export(available_features) export(available_tags) export(bbox_to_string) +export(filter_osm_tags) export(filter_osm_user) export(get_overpass_url) export(getbb) diff --git a/NEWS.md b/NEWS.md index 60fb2594..84267005 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ - `getbb()` can query wikidata ids for OSM relations properties (P402) (idea from @mhpob in #401, implemented in #403). - Add `filter_osm_user()` to add user filter to `overpass_queries` objects (#414). +- Rename `add_osm_feature()` -> `filter_osm_tags()` and `add_osm_features()` -> `add_osm_tags()`. Keep the alias silent for now, the old names will be DEPRECATED in a future version (#417). ## Minor changes diff --git a/R/opq.R b/R/opq.R index 65fa6fe5..23d769d8 100644 --- a/R/opq.R +++ b/R/opq.R @@ -327,7 +327,7 @@ paste_features <- function (key, value, key_pre = "", bind = "=", #' add_osm_feature (key = "name") #' cat (opq_string (q_keys)) #' } -add_osm_feature <- function (opq, +filter_osm_tags <- function (opq, key, value, key_exact = TRUE, @@ -385,6 +385,27 @@ add_osm_feature <- function (opq, opq } +#' @rdname filter_osm_tags +#' @export +add_osm_feature <- function (opq, # TODO: DEPRECATE + key, + value, + key_exact = TRUE, + value_exact = TRUE, + match_case = TRUE, + bbox = NULL) { + filter_osm_tags ( + opq = opq, + key = key, + value = value, + key_exact = key_exact, + value_exact = value_exact, + match_case = match_case, + bbox = bbox + ) +} + + #' Get conditional operator/prefix values based on value_exact and key_exact #' #' @param bind Operator used to combine key and value. Options include "=" @@ -529,11 +550,11 @@ check_bind_key_pre <- function (bind = "=", key_pre = "") { #' add_osm_feature (key = "name") #' cat (opq_string (q_keys)) #' } -add_osm_features <- function (opq, - features, - bbox = NULL, - key_exact = TRUE, - value_exact = TRUE) { +add_osm_tags <- function (opq, + features, + bbox = NULL, + key_exact = TRUE, + value_exact = TRUE) { if (is.null (bbox) && is.null (opq$bbox)) { stop ("Bounding box has to either be set in opq or must be set here") } @@ -582,6 +603,23 @@ add_osm_features <- function (opq, opq } +#' @rdname add_osm_tags +#' @export +add_osm_features <- function (opq, # TODO: DEPRECATE + features, + bbox = NULL, + key_exact = TRUE, + value_exact = TRUE) { + add_osm_tags ( + opq = opq, + features = features, + bbox = bbox, + key_exact = key_exact, + value_exact = value_exact + ) +} + + #' Is features a named list or character vector? #' #' @noRd diff --git a/man/add_osm_features.Rd b/man/add_osm_tags.Rd similarity index 95% rename from man/add_osm_features.Rd rename to man/add_osm_tags.Rd index ce5941fd..44ad81d9 100644 --- a/man/add_osm_features.Rd +++ b/man/add_osm_tags.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/opq.R -\name{add_osm_features} +\name{add_osm_tags} +\alias{add_osm_tags} \alias{add_osm_features} \title{Add multiple features to an Overpass query} \usage{ +add_osm_tags(opq, features, bbox = NULL, key_exact = TRUE, value_exact = TRUE) + add_osm_features( opq, features, @@ -87,8 +90,8 @@ cat (opq_string (q_keys)) \link{add_osm_feature} Other queries: -\code{\link{add_osm_feature}()}, \code{\link{bbox_to_string}()}, +\code{\link{filter_osm_tags}()}, \code{\link{filter_osm_user}()}, \code{\link{getbb}()}, \code{\link{opq}()}, diff --git a/man/bbox_to_string.Rd b/man/bbox_to_string.Rd index 60bf4a07..ae472e0c 100644 --- a/man/bbox_to_string.Rd +++ b/man/bbox_to_string.Rd @@ -38,8 +38,8 @@ bbox_to_string (getbb ("València", format_out = "data.frame")) } \seealso{ Other queries: -\code{\link{add_osm_feature}()}, -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, +\code{\link{filter_osm_tags}()}, \code{\link{filter_osm_user}()}, \code{\link{getbb}()}, \code{\link{opq}()}, diff --git a/man/add_osm_feature.Rd b/man/filter_osm_tags.Rd similarity index 95% rename from man/add_osm_feature.Rd rename to man/filter_osm_tags.Rd index 857427b8..c682eea5 100644 --- a/man/add_osm_feature.Rd +++ b/man/filter_osm_tags.Rd @@ -1,9 +1,20 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/opq.R -\name{add_osm_feature} +\name{filter_osm_tags} +\alias{filter_osm_tags} \alias{add_osm_feature} \title{Add a feature to an Overpass query} \usage{ +filter_osm_tags( + opq, + key, + value, + key_exact = TRUE, + value_exact = TRUE, + match_case = TRUE, + bbox = NULL +) + add_osm_feature( opq, key, @@ -108,7 +119,7 @@ cat (opq_string (q_keys)) \code{\link[=add_osm_features]{add_osm_features()}} Other queries: -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, \code{\link{bbox_to_string}()}, \code{\link{filter_osm_user}()}, \code{\link{getbb}()}, diff --git a/man/filter_osm_user.Rd b/man/filter_osm_user.Rd index 834f04b1..130f7ec8 100644 --- a/man/filter_osm_user.Rd +++ b/man/filter_osm_user.Rd @@ -61,9 +61,9 @@ d_touched } \seealso{ Other queries: -\code{\link{add_osm_feature}()}, -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, \code{\link{bbox_to_string}()}, +\code{\link{filter_osm_tags}()}, \code{\link{getbb}()}, \code{\link{opq}()}, \code{\link{opq_around}()}, diff --git a/man/getbb.Rd b/man/getbb.Rd index b31144c7..7a9803f8 100644 --- a/man/getbb.Rd +++ b/man/getbb.Rd @@ -137,9 +137,9 @@ if (nchar (key) == 32) { } \seealso{ Other queries: -\code{\link{add_osm_feature}()}, -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, \code{\link{bbox_to_string}()}, +\code{\link{filter_osm_tags}()}, \code{\link{filter_osm_user}()}, \code{\link{opq}()}, \code{\link{opq_around}()}, diff --git a/man/opq.Rd b/man/opq.Rd index cc16e0c6..f7e54680 100644 --- a/man/opq.Rd +++ b/man/opq.Rd @@ -125,9 +125,9 @@ opqa2 <- osmdata_sf (qa2) } \seealso{ Other queries: -\code{\link{add_osm_feature}()}, -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, \code{\link{bbox_to_string}()}, +\code{\link{filter_osm_tags}()}, \code{\link{filter_osm_user}()}, \code{\link{getbb}()}, \code{\link{opq_around}()}, diff --git a/man/opq_around.Rd b/man/opq_around.Rd index 024607c3..1ec9145c 100644 --- a/man/opq_around.Rd +++ b/man/opq_around.Rd @@ -42,9 +42,9 @@ x <- opq_around (lon, lat, radius, key, value) |> } \seealso{ Other queries: -\code{\link{add_osm_feature}()}, -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, \code{\link{bbox_to_string}()}, +\code{\link{filter_osm_tags}()}, \code{\link{filter_osm_user}()}, \code{\link{getbb}()}, \code{\link{opq}()}, diff --git a/man/opq_csv.Rd b/man/opq_csv.Rd index 056e89ad..80dc8e19 100644 --- a/man/opq_csv.Rd +++ b/man/opq_csv.Rd @@ -51,9 +51,9 @@ cities <- osmdata_data_frame (qid) } \seealso{ Other queries: -\code{\link{add_osm_feature}()}, -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, \code{\link{bbox_to_string}()}, +\code{\link{filter_osm_tags}()}, \code{\link{filter_osm_user}()}, \code{\link{getbb}()}, \code{\link{opq}()}, diff --git a/man/opq_enclosing.Rd b/man/opq_enclosing.Rd index 7549421a..25ad6ccb 100644 --- a/man/opq_enclosing.Rd +++ b/man/opq_enclosing.Rd @@ -50,9 +50,9 @@ x <- opq_enclosing (lon, lat, key, value) |> } \seealso{ Other queries: -\code{\link{add_osm_feature}()}, -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, \code{\link{bbox_to_string}()}, +\code{\link{filter_osm_tags}()}, \code{\link{filter_osm_user}()}, \code{\link{getbb}()}, \code{\link{opq}()}, diff --git a/man/opq_osm_id.Rd b/man/opq_osm_id.Rd index 000ca25a..b6d246a9 100644 --- a/man/opq_osm_id.Rd +++ b/man/opq_osm_id.Rd @@ -93,9 +93,9 @@ datAiO <- opq_osm_id (id = id, type = type) |> } \seealso{ Other queries: -\code{\link{add_osm_feature}()}, -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, \code{\link{bbox_to_string}()}, +\code{\link{filter_osm_tags}()}, \code{\link{filter_osm_user}()}, \code{\link{getbb}()}, \code{\link{opq}()}, diff --git a/man/opq_string.Rd b/man/opq_string.Rd index 236af6d6..5ece3c24 100644 --- a/man/opq_string.Rd +++ b/man/opq_string.Rd @@ -25,9 +25,9 @@ opq_string (q) } \seealso{ Other queries: -\code{\link{add_osm_feature}()}, -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, \code{\link{bbox_to_string}()}, +\code{\link{filter_osm_tags}()}, \code{\link{filter_osm_user}()}, \code{\link{getbb}()}, \code{\link{opq}()}, diff --git a/man/overpass_status.Rd b/man/overpass_status.Rd index 5a573cc2..1660f548 100644 --- a/man/overpass_status.Rd +++ b/man/overpass_status.Rd @@ -24,9 +24,9 @@ overpass_status () } \seealso{ Other queries: -\code{\link{add_osm_feature}()}, -\code{\link{add_osm_features}()}, +\code{\link{add_osm_tags}()}, \code{\link{bbox_to_string}()}, +\code{\link{filter_osm_tags}()}, \code{\link{filter_osm_user}()}, \code{\link{getbb}()}, \code{\link{opq}()}, From 66f323f89a3e506e42f7e787c9bfcd2764e3d18f Mon Sep 17 00:00:00 2001 From: Joan Maspons Date: Tue, 17 Mar 2026 12:02:41 +0100 Subject: [PATCH 2/5] Update comments and docs with the new function names --- R/elevation.R | 2 +- R/get-osmdata-df.R | 6 +- R/get-osmdata-sc.R | 2 +- R/get-osmdata-sf.R | 4 +- R/get-osmdata-sp.R | 2 +- R/get-osmdata-xml.R | 4 +- R/opq.R | 130 ++++++++++++++++--------------- R/osm-extract.R | 10 +-- R/osmdata-package.R | 4 +- R/poly2line.R | 2 +- R/trim-osmdata.R | 4 +- R/unique-osmdata.R | 2 +- R/utils.R | 2 +- README.Rmd | 39 +++++----- README.md | 32 ++++---- data-raw/hex-script.Rmd | 10 +-- man/add_osm_tags.Rd | 38 ++++----- man/filter_osm_tags.Rd | 44 +++++------ man/filter_osm_user.Rd | 4 +- man/opq.Rd | 14 ++-- man/opq_around.Rd | 2 +- man/opq_csv.Rd | 7 +- man/opq_enclosing.Rd | 2 +- man/opq_osm_id.Rd | 4 +- man/osm_elevation.Rd | 2 +- man/osm_lines.Rd | 4 +- man/osm_multilines.Rd | 2 +- man/osm_multipolygons.Rd | 2 +- man/osm_poly2line.Rd | 2 +- man/osm_polygons.Rd | 2 +- man/osmdata-package.Rd | 4 +- man/osmdata_data_frame.Rd | 6 +- man/osmdata_sc.Rd | 4 +- man/osmdata_sf.Rd | 4 +- man/osmdata_sp.Rd | 4 +- man/osmdata_xml.Rd | 4 +- man/trim_osmdata.Rd | 4 +- man/unique_osmdata.Rd | 2 +- man/unname_osmdata_sf.Rd | 2 +- src/osmdata-sf.cpp | 2 +- vignettes/osm-sf-translation.Rmd | 2 +- vignettes/osmdata-sc.Rmd | 2 +- vignettes/osmdata.Rmd | 86 ++++++++++---------- vignettes/query-split.Rmd | 6 +- 44 files changed, 264 insertions(+), 252 deletions(-) diff --git a/R/elevation.R b/R/elevation.R index cc8bf2c5..f48bded1 100644 --- a/R/elevation.R +++ b/R/elevation.R @@ -17,7 +17,7 @@ #' @examples #' \dontrun{ #' query <- opq ("omaha nebraska") |> -#' add_osm_feature (key = "highway") +#' filter_osm_tags (key = "highway") #' # Elevation can only be applied to \pkg{silicate} 'SC'-class data: #' dat <- osmdata_sc (query) #' dat$vertex diff --git a/R/get-osmdata-df.R b/R/get-osmdata-df.R index c97d3df7..5a19d52d 100644 --- a/R/get-osmdata-df.R +++ b/R/get-osmdata-df.R @@ -3,7 +3,7 @@ #' #' @inheritParams osmdata_sf #' @param q An object of class `overpass_query` constructed with -#' [opq()] and [add_osm_feature()] or a string with a valid query, such +#' [opq()] and [filter_osm_tags()] or a string with a valid query, such #' as `"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"`. #' May be be omitted, in which case the attributes of the [data.frame] #' will not include the query. See examples below. @@ -13,7 +13,7 @@ #' and tags of the the objects from the query. #' #' @details If you are not interested in the geometries of the results, it's a -#' good option to query for objects that match the features only and forget +#' good option to query for objects that match the statements only and forget #' about members of the ways and relations. You can achieve this by passing #' the parameter `body = "tags"` to [opq()]. #' @@ -23,7 +23,7 @@ #' @examples #' \dontrun{ #' query <- opq ("hampi india") |> -#' add_osm_feature (key = "historic", value = "ruins") +#' filter_osm_tags (key = "historic", value = "ruins") #' # Then extract data from 'Overpass' API #' hampi_df <- osmdata_data_frame (query) #' attr (hampi_df, "bbox") diff --git a/R/get-osmdata-sc.R b/R/get-osmdata-sc.R index 285ea767..83be4f67 100644 --- a/R/get-osmdata-sc.R +++ b/R/get-osmdata-sc.R @@ -14,7 +14,7 @@ #' @examples #' \dontrun{ #' query <- opq ("hampi india") |> -#' add_osm_feature (key = "historic", value = "ruins") +#' filter_osm_tags (key = "historic", value = "ruins") #' # Then extract data from 'Overpass' API #' hampi_sc <- osmdata_sc (query) #' } diff --git a/R/get-osmdata-sf.R b/R/get-osmdata-sf.R index 284f0bcb..ddcaad72 100644 --- a/R/get-osmdata-sf.R +++ b/R/get-osmdata-sf.R @@ -5,7 +5,7 @@ #' the \pkg{sf} package into the current workspace with 'library(sf)'. #' #' @param q An object of class `overpass_query` constructed with -#' [opq()] and [add_osm_feature()] or a string with a valid query, such +#' [opq()] and [filter_osm_tags()] or a string with a valid query, such #' as `"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"`. #' May be be omitted, in which case the [osmdata] object will not #' include the query. See examples below. @@ -24,7 +24,7 @@ #' @examples #' \dontrun{ #' query <- opq ("hampi india") |> -#' add_osm_feature (key = "historic", value = "ruins") +#' filter_osm_tags (key = "historic", value = "ruins") #' # Then extract data from 'Overpass' API #' hampi_sf <- osmdata_sf (query) #' } diff --git a/R/get-osmdata-sp.R b/R/get-osmdata-sp.R index b8bb5748..6b2fc227 100644 --- a/R/get-osmdata-sp.R +++ b/R/get-osmdata-sp.R @@ -12,7 +12,7 @@ #' @examples #' \dontrun{ #' query <- opq ("hampi india") |> -#' add_osm_feature (key = "historic", value = "ruins") +#' filter_osm_tags (key = "historic", value = "ruins") #' # Then extract data from 'Overpass' API #' hampi_sp <- osmdata_sp (query) #' } diff --git a/R/get-osmdata-xml.R b/R/get-osmdata-xml.R index 5fae5e59..66453e56 100644 --- a/R/get-osmdata-xml.R +++ b/R/get-osmdata-xml.R @@ -3,7 +3,7 @@ #' or a raw vector. #' #' @param q An object of class `overpass_query` constructed with -#' [opq()] and [add_osm_feature()] or a string with a valid query, such as +#' [opq()] and [filter_osm_tags()] or a string with a valid query, such as #' `"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"`. See #' examples below. #' @param filename If given, OSM data are saved to the named file @@ -23,7 +23,7 @@ #' @examples #' \dontrun{ #' query <- opq ("hampi india") |> -#' add_osm_feature (key = "historic", value = "ruins") +#' filter_osm_tags (key = "historic", value = "ruins") #' # Then extract data from 'Overpass' API and save to local file: #' osmdata_xml (query, filename = "hampi.osm") #' } diff --git a/R/opq.R b/R/opq.R index 23d769d8..20292683 100644 --- a/R/opq.R +++ b/R/opq.R @@ -70,33 +70,33 @@ #' \dontrun{ #' q <- getbb ("portsmouth", display_name_contains = "United States") |> #' opq () |> -#' add_osm_feature ("amenity", "restaurant") |> -#' add_osm_feature ("amenity", "pub") +#' filter_osm_tags ("amenity", "restaurant") |> +#' filter_osm_tags ("amenity", "pub") #' osmdata_sf (q) # all objects that are restaurants AND pubs (there are none!) #' q1 <- getbb ("portsmouth", display_name_contains = "United States") |> #' opq () |> -#' add_osm_feature ("amenity", "restaurant") +#' filter_osm_tags ("amenity", "restaurant") #' q2 <- getbb ("portsmouth", display_name_contains = "United States") |> #' opq () |> -#' add_osm_feature ("amenity", "pub") +#' filter_osm_tags ("amenity", "pub") #' c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs #' #' # Use `osm_types = "node"` to retrieve single point data only, such as for central #' # locations of cities. #' opq <- opq (bbox, osm_types = "node") |> -#' add_osm_feature (key = "place", value = "city") |> +#' filter_osm_tags (key = "place", value = "city") |> #' osmdata_sf (quiet = FALSE) #' #' # Filter by a search area #' qa1 <- getbb ("Catalan Countries", format_out = "osm_type_id") |> #' opq (osm_types = "node") |> -#' add_osm_feature (key = "capital", value = "4") +#' filter_osm_tags (key = "capital", value = "4") #' opqa1 <- osmdata_sf (qa1) #' # Filter by a multiple search areas #' bb <- getbb ("Vilafranca", format_out = "data.frame") #' qa2 <- bbox_to_string (bb [bb$osm_type != "node", ]) |> #' opq (osm_types = "node") |> -#' add_osm_feature (key = "place") +#' filter_osm_tags (key = "place") #' opqa2 <- osmdata_sf (qa2) #' } opq <- function (bbox = NULL, nodes_only, @@ -205,7 +205,7 @@ opq <- function (bbox = NULL, nodes_only, return (res) } -# used in the following add_osm_feature fn +# used in the following filter_osm_tags fn paste_features <- function (key, value, key_pre = "", bind = "=", match_case = FALSE, value_exact = FALSE) { if (is.null (value)) { @@ -248,12 +248,12 @@ paste_features <- function (key, value, key_pre = "", bind = "=", return (feature) } -#' Add a feature to an Overpass query +#' Add tags to all current statements of an Overpass query #' #' @param opq An `overpass_query` object -#' @param key feature key; can be negated with an initial exclamation mark, +#' @param key tag key; can be negated with an initial exclamation mark, #' `key = "!this"`, and can also be a vector if `value` is missing. -#' @param value value for feature key; can be negated with an initial +#' @param value value for tag key; can be negated with an initial #' exclamation mark, `value = "!this"`, and can also be a vector, #' `value = c ("this", "that")`. #' @param key_exact If FALSE, `key` is not interpreted exactly; see @@ -261,7 +261,7 @@ paste_features <- function (key, value, key_pre = "", bind = "=", #' @param value_exact If FALSE, `value` is not interpreted exactly #' @param match_case If FALSE, matching for both `key` and `value` is #' not sensitive to case -#' @param bbox optional bounding box for the feature query; must be set if no +#' @param bbox optional bounding box for the query; must be set if no #' opq query bbox has been set #' @return An [opq] object. #' @@ -274,18 +274,18 @@ paste_features <- function (key, value, key_pre = "", bind = "=", #' [opq_string()]. #' #' @references -#' @seealso [add_osm_features()] +#' @seealso [add_osm_tags()] #' -#' @section `add_osm_feature` vs `add_osm_features`: -#' Features defined within an [add_osm_features()] call are combined with a +#' @section `filter_osm_tags` vs `add_osm_tags`: +#' Tags defined within an [add_osm_tags()] call are combined with a #' logical OR. #' -#' Chained calls to either `add_osm_feature()` or [add_osm_features()] combines -#' features from these calls in a logical AND; this is analagous to chaining +#' Chained calls to either `filter_osm_tags()` or [add_osm_tags()] combines +#' tags from these calls in a logical AND; this is analagous to chaining #' `dplyr::filter()` on a data frame. #' -#' `add_osm_features()` with only one feature is logically equivalent to -#' `add_osm_feature()`. +#' `add_osm_tags()` with only one tag is logically equivalent to +#' `filter_osm_tags()`. #' #' @family queries #' @export @@ -293,38 +293,38 @@ paste_features <- function (key, value, key_pre = "", bind = "=", #' @examples #' \dontrun{ #' q <- opq ("portsmouth usa") |> -#' add_osm_feature ( +#' filter_osm_tags ( #' key = "amenity", #' value = "restaurant" #' ) |> -#' add_osm_feature (key = "amenity", value = "pub") +#' filter_osm_tags (key = "amenity", value = "pub") #' osmdata_sf (q) # all objects that are restaurants AND pubs (there are none!) #' q1 <- opq ("portsmouth usa") |> -#' add_osm_feature ( +#' filter_osm_tags ( #' key = "amenity", #' value = "restaurant" #' ) #' q2 <- opq ("portsmouth usa") |> -#' add_osm_feature (key = "amenity", value = "pub") +#' filter_osm_tags (key = "amenity", value = "pub") #' c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs #' #' # Use of negation to extract all non-primary highways #' q <- opq ("portsmouth uk") |> -#' add_osm_feature (key = "highway", value = "!primary") +#' filter_osm_tags (key = "highway", value = "!primary") #' #' # key negation without warnings #' q3 <- opq ("Vinçà", osm_type = "node") |> -#' add_osm_feature (key = c ("name", "!name:ca")) +#' filter_osm_tags (key = c ("name", "!name:ca")) #' cat (opq_string (q3)) #' q4 <- opq ("el Carxe", osm_type = "node") |> -#' add_osm_feature (key = "natural", value = "peak") |> -#' add_osm_feature (key = "!ele") +#' filter_osm_tags (key = "natural", value = "peak") |> +#' filter_osm_tags (key = "!ele") #' cat (opq_string (q4)) #' #' # Get objects with keys (`natural` OR `waterway`) AND `name` #' q_keys <- opq ("Badia del Vallès", osm_types = "nwr", out = "tags") |> -#' add_osm_features (features = list (natural = NULL, waterway = NULL)) |> -#' add_osm_feature (key = "name") +#' add_osm_tags (features = list (natural = NULL, waterway = NULL)) |> +#' filter_osm_tags (key = "name") #' cat (opq_string (q_keys)) #' } filter_osm_tags <- function (opq, @@ -369,9 +369,10 @@ filter_osm_tags <- function (opq, warning ( "The query will request objects whith only a negated key (", paste (opq$features [w], collapse = ", "), ") , which can be quite ", - "expensive for overpass servers. Add other features or be shure ", + "expensive for overpass servers. Add other tags or be shure ", "that that is what you want. To avoid this warning, reorder your ", - "calls to add_osm_feature/s and leave key negations at the end." + "calls to filter_osm_tags() / add_osm_tags() and leave key ", + "negations at the end." ) } @@ -386,6 +387,9 @@ filter_osm_tags <- function (opq, } #' @rdname filter_osm_tags +#' +#' @description `add_osm_feature()` will be DEPRECATED in future versions. +#' #' @export add_osm_feature <- function (opq, # TODO: DEPRECATE key, @@ -497,25 +501,25 @@ check_bind_key_pre <- function (bind = "=", key_pre = "") { } } -#' Add multiple features to an Overpass query +#' Add multiple tags to an Overpass query as independent statements #' -#' Alternative version of [add_osm_feature()] for creating single queries -#' with multiple features. Key-value matching may be controlled by using the -#' filter symbols described in +#' Alternative version of [filter_osm_tags()] for creating single queries +#' with multiple tags in independent statements. Key-value matching may be +#' controlled by using the filter symbols described in #' \url{https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#By_tag_.28has-kv.29}. #' -#' @inheritParams add_osm_feature -#' @inheritSection add_osm_feature `add_osm_feature` vs `add_osm_features` +#' @inheritParams filter_osm_tags +#' @inheritSection filter_osm_tags `filter_osm_tags` vs `add_osm_tags` #' @param features A named list or vector with the format `list("" = #' "")` or `c("" = "")` or a character vector of #' key-value pairs with keys and values enclosed in escape-formatted #' quotations. See examples for details. -#' @param bbox optional bounding box for the feature query; must be set if no +#' @param bbox optional bounding box for the query; must be set if no #' opq query bbox has been set. #' @return An [opq] object. #' #' @references \url{https://wiki.openstreetmap.org/wiki/Map_Features} -#' @seealso [add_osm_feature] +#' @seealso [filter_osm_tags] #' #' @family queries #' @export @@ -523,31 +527,31 @@ check_bind_key_pre <- function (bind = "=", key_pre = "") { #' @examples #' \dontrun{ #' q <- opq ("portsmouth usa") |> -#' add_osm_features (features = list ( +#' add_osm_tags (features = list ( #' "amenity" = "restaurant", #' "amenity" = "pub" #' )) #' #' q <- opq ("portsmouth usa") |> -#' add_osm_features (features = c ( +#' add_osm_tags (features = c ( #' "\"amenity\"=\"restaurant\"", #' "\"amenity\"=\"pub\"" #' )) #' cat (opq_string (q)) #' # This extracts in a single query the same result as the following: #' q1 <- opq ("portsmouth usa") |> -#' add_osm_feature ( +#' filter_osm_tags ( #' key = "amenity", #' value = "restaurant" #' ) #' q2 <- opq ("portsmouth usa") |> -#' add_osm_feature (key = "amenity", value = "pub") +#' filter_osm_tags (key = "amenity", value = "pub") #' c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs #' #' # Get objects with keys (`natural` OR `waterway`) AND `name` #' q_keys <- opq ("Badia del Vallès", osm_types = "nwr", out = "tags") |> -#' add_osm_features (features = list (natural = NULL, waterway = NULL)) |> -#' add_osm_feature (key = "name") +#' add_osm_tags (features = list (natural = NULL, waterway = NULL)) |> +#' filter_osm_tags (key = "name") #' cat (opq_string (q_keys)) #' } add_osm_tags <- function (opq, @@ -604,6 +608,9 @@ add_osm_tags <- function (opq, } #' @rdname add_osm_tags +#' +#' @description `add_osm_features()` will be DEPRECATED in future versions. +#' #' @export add_osm_features <- function (opq, # TODO: DEPRECATE features, @@ -620,21 +627,21 @@ add_osm_features <- function (opq, # TODO: DEPRECATE } -#' Is features a named list or character vector? +#' Is tags a named list or character vector? #' #' @noRd is_named <- function (x) { !is.null (names (x)) && !any ("" %in% names (x)) } -#' Is features an escape-delimited string? +#' Is tags an escape-delimited string? #' #' @noRd is_escape_delimited <- function (x) { length (which (!grepl ("\\\"", x))) > 0L } -#' Check if features is provided and uses the required class and formatting +#' Check if tags is provided and uses the required class and formatting #' #' @noRd check_features <- function (features) { @@ -688,7 +695,7 @@ check_features <- function (features) { #' # Notice the "::user" and "::uid" fields in the oqp_csv() #' q_csv <- opq (bbox = "relation(id:11755232)", out = "meta", osm_type = "node") |> #' filter_osm_user (user = "jmaspons") |> -#' add_osm_feature (key = "name") |> +#' filter_osm_tags (key = "name") |> #' opq_csv (c ("::type", "::id", "name", "name:ca", "::user", "::uid")) #' cat (opq_string (q_csv)) #' # Warning: csv queries can fail without errors in long running queries. For timeouts, @@ -703,7 +710,7 @@ check_features <- function (features) { #' osm_type = "node", timeout = 100 #' ) |> #' filter_osm_user (user = "jmaspons", touched = TRUE) |> -#' add_osm_feature (key = "name") +#' filter_osm_tags (key = "name") #' cat (opq_string (q_touched)) #' \dontrun{ #' d_touched <- osmdata_data_frame (q_touched) @@ -735,7 +742,7 @@ filter_osm_user <- function (opq, user, touched = FALSE, is_uid) { } -#' Add a feature specified by OSM ID to an Overpass query +#' Add features specified by OSM ID to an Overpass query #' #' @inheritParams opq #' @param id One or more official OSM identifiers (long-form integers), which @@ -839,7 +846,7 @@ opq_osm_id <- function (id = NULL, type = NULL, open_url = FALSE, #' #' Find all features which enclose a given point, and optionally match specific #' 'key'-'value' pairs. This function is \emph{not} intended to be combined with -#' [add_osm_feature()], rather is only to be used in the sequence +#' [filter_osm_tags()], rather is only to be used in the sequence #' [opq_enclosing()] -> [opq_string()] -> [osmdata_xml()] (or other #' extraction function). See examples for how to use. #' @@ -906,7 +913,7 @@ opq_enclosing <- function (lon = NULL, lat = NULL, #' #' Find all features around a given point, and optionally match specific #' 'key'-'value' pairs. This function is \emph{not} intended to be combined with -#' [add_osm_feature()], rather is only to be used in the sequence +#' [filter_osm_tags()], rather is only to be used in the sequence #' [opq_around()] -> [osmdata_xml()] (or other extraction function). See #' examples for how to use. #' @@ -958,7 +965,8 @@ opq_around <- function (lon, lat, radius = 15, #' Transform an Overpass query to return the result in a csv format #' #' @param q A opq string or an object of class `overpass_query` constructed with -#' [opq()] or alternative opq builders (+ [add_osm_feature()]/s). +#' [opq()] or alternative opq builders (+ [filter_osm_tags()], +#' [add_osm_tags()], [filter_osm_user()]). #' @param fields a character vector with the field names. #' @param header if \code{FALSE}, do not ask for column names. #' @@ -980,8 +988,8 @@ opq_around <- function (lon, lat, radius = 15, #' \dontrun{ #' q <- getbb ("Catalan Countries", format_out = "osm_type_id") |> #' opq (out = "tags center", osm_type = "relation", timeout = 100) |> -#' add_osm_feature ("admin_level", "7") |> -#' add_osm_feature ("boundary", "administrative") |> +#' filter_osm_tags ("admin_level", "7") |> +#' filter_osm_tags ("boundary", "administrative") |> #' opq_csv (fields = c ("name", "::type", "::id", "::lat", "::lon")) #' comarques <- osmdata_data_frame (q) # without timeout parameter, 0 rows #' @@ -1049,7 +1057,7 @@ opq_string <- function (opq) { } # The quiet param is not exposed here, but is passed through by the various -# `osmdata_s*` functions, to issue messages when neither features nor ID +# `osmdata_s*` functions, to issue messages when neither tags nor ID # specified. opq_string_intern <- function (opq, quiet = TRUE) { @@ -1058,11 +1066,11 @@ opq_string_intern <- function (opq, quiet = TRUE) { map_to_area <- grepl ("(node|way|relation|rel)\\(id:[0-9, ]+\\)", opq$bbox) res <- NULL - if (!is.null (opq$features)) { # opq with add_osm_feature + if (!is.null (opq$features)) { # opq with filter_osm_tags filters <- opq$features - if (length (filters) > 1L) { # from add_osm_features() + if (length (filters) > 1L) { # from add_osm_tags() filters <- vapply (filters, function (i) { paste (i, collapse = "") @@ -1079,7 +1087,7 @@ opq_string_intern <- function (opq, quiet = TRUE) { if (!is.null (attr (opq, "enclosing"))) { if (length (filters) > 1) { - stop ("enclosing queries can only accept one feature") + stop ("enclosing queries can only accept one tag") } lat <- strsplit (opq$bbox, ",") [[1]] [1] @@ -1149,7 +1157,7 @@ opq_string_intern <- function (opq, quiet = TRUE) { "The overpass server is intended to be used to extract ", "specific features;\nthis query may place an undue ", "burden on server resources.\nPlease consider specifying ", - "features via 'add_osm_feature' or 'opq_osm_id'." + "tags via 'filter_osm_tags' or 'opq_osm_id'." ) } diff --git a/R/osm-extract.R b/R/osm-extract.R index 6e5aef53..f4b7af98 100644 --- a/R/osm-extract.R +++ b/R/osm-extract.R @@ -296,7 +296,7 @@ osm_points <- function (dat, id) { #' @examples #' \dontrun{ #' dat <- opq ("hengelo nl") |> -#' add_osm_feature (key = "highway") |> +#' filter_osm_tags (key = "highway") |> #' osmdata_sf () #' bus <- dat$osm_points [which (dat$osm_points$highway == "bus_stop"), ] |> #' rownames () # all OSM IDs of bus stops @@ -304,7 +304,7 @@ osm_points <- function (dat, id) { #' #' # All lines which intersect with Piccadilly Circus in London, UK #' dat <- opq ("Fitzrovia London") |> -#' add_osm_feature (key = "highway") |> +#' filter_osm_tags (key = "highway") |> #' osmdata_sf () #' i <- which (dat$osm_polygons$name == "Piccadilly Circus") #' id <- rownames (dat$osm_polygons [i, ]) @@ -353,7 +353,7 @@ osm_lines <- function (dat, id) { #' # Extract polygons which intersect Conway Street in London #' \dontrun{ #' dat <- opq ("Marylebone London") |> -#' add_osm_feature (key = "highway") |> +#' filter_osm_tags (key = "highway") |> #' osmdata_sf () #' conway <- which (dat$osm_lines$name == "Conway Street") #' id <- rownames (dat$osm_lines [conway, ]) @@ -401,7 +401,7 @@ osm_polygons <- function (dat, id) { #' @examples #' \dontrun{ #' dat <- opq ("London UK") |> -#' add_osm_feature (key = "name", value = "Thames", exact = FALSE) |> +#' filter_osm_tags (key = "name", value = "Thames", exact = FALSE) |> #' osmdata_sf () #' # Get ids of lines called "The Thames": #' id <- rownames (dat$osm_lines [which (dat$osm_lines$name == "The Thames"), ]) @@ -454,7 +454,7 @@ osm_multilines <- function (dat, id) { #' # "Chiswick Eyot" (which is an island). #' \dontrun{ #' dat <- opq ("London UK") |> -#' add_osm_feature (key = "name", value = "Thames", exact = FALSE) |> +#' filter_osm_tags (key = "name", value = "Thames", exact = FALSE) |> #' osmdata_sf () #' index <- which (dat$osm_multipolygons$name == "Chiswick Eyot") #' id <- rownames (dat$osm_polygons [id, ]) diff --git a/R/osmdata-package.R b/R/osmdata-package.R index a9b36740..dddadb16 100644 --- a/R/osmdata-package.R +++ b/R/osmdata-package.R @@ -16,8 +16,8 @@ #' unnamed vector) return a string #' \item [overpass_status()]: Retrieve status of the overpass API #' \item [opq()]: Build an overpass query -#' \item [add_osm_feature()]: Add a feature to an overpass query -#' \item [add_osm_features()]: Add multiple features to an Overpass query +#' \item [filter_osm_tags()]: Add tags to all current statements of an Overpass query +#' \item [add_osm_tags()]: Add multiple tags to independent statments of an Overpass query #' \item [filter_osm_user()]: Add an user filter to an Overpass query #' \item [opq_string()]: Convert an osmdata query to overpass API string #' } diff --git a/R/poly2line.R b/R/poly2line.R index 98dcab40..e022ce22 100644 --- a/R/poly2line.R +++ b/R/poly2line.R @@ -16,7 +16,7 @@ #' @examples #' \dontrun{ #' query <- opq ("colchester uk") |> -#' add_osm_feature (key = "highway") +#' filter_osm_tags (key = "highway") #' # Then extract data from 'Overpass' API #' dat <- osmdata_sf (query) #' # colchester has lots of roundabouts, and these are stored in 'osm_polygons' diff --git a/R/trim-osmdata.R b/R/trim-osmdata.R index 0b2fcee8..0392a4d1 100644 --- a/R/trim-osmdata.R +++ b/R/trim-osmdata.R @@ -31,7 +31,7 @@ #' \dontrun{ #' bb <- getbb ("colchester uk") #' query <- opq (bb) |> -#' add_osm_feature (key = "highway") +#' filter_osm_tags (key = "highway") #' # Then extract data from 'Overpass' API #' dat <- osmdata_sf (query, quiet = FALSE) #' # Then get bounding *polygon* for Colchester, as opposed to rectangular @@ -49,7 +49,7 @@ #' # Server-side trimming equivalent #' bb <- getbb ("colchester uk", format_out = "osm_type_id") #' query <- opq (bb) |> -#' add_osm_feature (key = "highway") +#' filter_osm_tags (key = "highway") #' dat <- osmdata_sf (query, quiet = FALSE) #' } #' @export diff --git a/R/unique-osmdata.R b/R/unique-osmdata.R index 2439aac7..25669321 100644 --- a/R/unique-osmdata.R +++ b/R/unique-osmdata.R @@ -16,7 +16,7 @@ #' @examples #' \dontrun{ #' query <- opq ("colchester uk") |> -#' add_osm_feature (key = "highway") +#' filter_osm_tags (key = "highway") #' # Then extract data from 'Overpass' API #' dat <- osmdata_sf (query) #' dat diff --git a/R/utils.R b/R/utils.R index 1bce9ad6..cac31920 100644 --- a/R/utils.R +++ b/R/utils.R @@ -21,7 +21,7 @@ is_datetime <- function (x) { #' @examples #' \dontrun{ #' query <- opq ("hampi india") |> -#' add_osm_feature (key = "historic", value = "ruins") +#' filter_osm_tags (key = "historic", value = "ruins") #' # Then extract data from 'Overpass' API #' hampi_sf <- osmdata_sf (query) #' # Remove rownames from all geometry metrices: diff --git a/README.Rmd b/README.Rmd index 325cb8ec..5778a7c6 100644 --- a/README.Rmd +++ b/README.Rmd @@ -95,7 +95,7 @@ packageVersion ("osmdata") ## Usage [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API) queries can be -built from a base query constructed with `opq` followed by `add_osm_feature`. The +built from a base query constructed with `opq` followed by `filter_osm_tags`. The corresponding OSM objects are then downloaded and converted to [Simple Feature (`sf`)](https://cran.r-project.org/package=sf) objects with `osmdata_sf()`, [Spatial (`sp`)](https://cran.r-project.org/package=sp) @@ -104,7 +104,7 @@ objects with `osmdata_sc()`. For example, ```{r query-thames, eval=FALSE} x <- opq (bbox = c (-0.27, 51.47, -0.20, 51.50)) |> # Chiswick Eyot in London, U.K. - add_osm_feature (key = "name", value = "Thames", value_exact = FALSE) |> + filter_osm_tags (key = "name", value = "Thames", value_exact = FALSE) |> osmdata_sf () x ``` @@ -152,26 +152,27 @@ class (b) str (b) ``` -### Features +### Tags -The next step is to define features of interest using the [`add_osm_feature()` -function](https://docs.ropensci.org/osmdata/reference/add_osm_feature.html). -This function accepts `key` and `value` parameters specifying desired features -in the [OSM key-vale schema](https://wiki.openstreetmap.org/wiki/Map_Features). -Multiple `add_osm_feature()` calls may be combined as illustrated below, with +The next step is to define features of interest using the [`filter_osm_tags()` +function](https://docs.ropensci.org/osmdata/reference/filter_osm_tags.html). +This function accepts `key` and `value` parameters specifying the tags of the +desired features in the +[OSM key-vale schema](https://wiki.openstreetmap.org/wiki/Map_Features). +Multiple `filter_osm_tags()` calls may be combined as illustrated below, with the result being a logical AND operation, thus returning all amenities that are labelled both as restaurants and also as pubs: ```{r key-val1} q <- opq ("portsmouth usa") |> - add_osm_feature (key = "amenity", value = "restaurant") |> - add_osm_feature (key = "amenity", value = "pub") # There are none of these + filter_osm_tags (key = "amenity", value = "restaurant") |> + filter_osm_tags (key = "amenity", value = "pub") # There are none of these ``` Features can also be requested by key only, in which case features with any values for the specified key will be returned: ```{r key-val2} q <- opq ("portsmouth usa") |> - add_osm_feature (key = "amenity") + filter_osm_tags (key = "amenity") ``` Such key-only queries can, however, translate into requesting very large data sets, and should generally be avoided in favour of more precise key-value @@ -182,30 +183,30 @@ following requests all amenities that are NOT labelled as restaurants and that are not labelled as pubs: ```{r key-val3} q <- opq ("portsmouth usa") |> - add_osm_feature (key = "amenity", value = "!restaurant") |> - add_osm_feature (key = "amenity", value = "!pub") # There are a lot of these + filter_osm_tags (key = "amenity", value = "!restaurant") |> + filter_osm_tags (key = "amenity", value = "!pub") # There are a lot of these ``` Additional arguments allow for more refined matching, such as the following request for all pubs with "irish" in the name: ```{r key-val4} q <- opq ("washington dc") |> - add_osm_feature (key = "amenity", value = "pub") |> - add_osm_feature ( + filter_osm_tags (key = "amenity", value = "pub") |> + filter_osm_tags ( key = "name", value = "irish", value_exact = FALSE, match_case = FALSE ) ``` Logical OR combinations can be constructed using the separate -[`add_osm_features()` -function](https://docs.ropensci.org/osmdata/reference/add_osm_features.html). +[`add_osm_tags()` +function](https://docs.ropensci.org/osmdata/reference/add_osm_tags.html). The first of the above examples requests all features that are both restaurants AND pubs. The following query will request data on restaurants OR pubs: ```{r features} q <- opq ("portsmouth usa") |> - add_osm_features (features = c ( + add_osm_tags (features = c ( "\"amenity\"=\"restaurant\"", "\"amenity\"=\"pub\"" )) @@ -225,7 +226,7 @@ and ### Data Formats -An overpass query constructed with the `opq()` and `add_osm_feature()` +An overpass query constructed with the `opq()` and `filter_osm_tags()` functions is then sent to the [overpass server](https://overpass-turbo.eu) to request data. These data may be returned in a variety of formats, currently including: diff --git a/README.md b/README.md index d4d43900..01f3884c 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ packageVersion ("osmdata") [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API) queries can be built from a base query constructed with `opq` followed by -`add_osm_feature`. The corresponding OSM objects are then downloaded and +`filter_osm_tags`. The corresponding OSM objects are then downloaded and converted to [Simple Feature (`sf`)](https://cran.r-project.org/package=sf) objects with `osmdata_sf()`, [Spatial (`sp`)](https://cran.r-project.org/package=sp) @@ -92,7 +92,7 @@ objects with `osmdata_sp()` (DEPRECATED) or [Silicate ``` r x <- opq (bbox = c (-0.27, 51.47, -0.20, 51.50)) |> # Chiswick Eyot in London, U.K. - add_osm_feature (key = "name", value = "Thames", value_exact = FALSE) |> + filter_osm_tags (key = "name", value = "Thames", value_exact = FALSE) |> osmdata_sf () x ``` @@ -153,19 +153,19 @@ str (b) ### Features The next step is to define features of interest using the -[`add_osm_feature()` -function](https://docs.ropensci.org/osmdata/reference/add_osm_feature.html). +[`filter_osm_tags()` +function](https://docs.ropensci.org/osmdata/reference/filter_osm_tags.html). This function accepts `key` and `value` parameters specifying desired features in the [OSM key-vale schema](https://wiki.openstreetmap.org/wiki/Map_Features). Multiple -`add_osm_feature()` calls may be combined as illustrated below, with the +`filter_osm_tags()` calls may be combined as illustrated below, with the result being a logical AND operation, thus returning all amenities that are labelled both as restaurants and also as pubs: ``` r q <- opq ("portsmouth usa") |> - add_osm_feature (key = "amenity", value = "restaurant") |> - add_osm_feature (key = "amenity", value = "pub") # There are none of these + filter_osm_tags (key = "amenity", value = "restaurant") |> + filter_osm_tags (key = "amenity", value = "pub") # There are none of these ``` Features can also be requested by key only, in which case features with @@ -173,7 +173,7 @@ any values for the specified key will be returned: ``` r q <- opq ("portsmouth usa") |> - add_osm_feature (key = "amenity") + filter_osm_tags (key = "amenity") ``` Such key-only queries can, however, translate into requesting very large @@ -186,8 +186,8 @@ restaurants and that are not labelled as pubs: ``` r q <- opq ("portsmouth usa") |> - add_osm_feature (key = "amenity", value = "!restaurant") |> - add_osm_feature (key = "amenity", value = "!pub") # There are a lot of these + filter_osm_tags (key = "amenity", value = "!restaurant") |> + filter_osm_tags (key = "amenity", value = "!pub") # There are a lot of these ``` Additional arguments allow for more refined matching, such as the @@ -195,23 +195,23 @@ following request for all pubs with “irish” in the name: ``` r q <- opq ("washington dc") |> - add_osm_feature (key = "amenity", value = "pub") |> - add_osm_feature ( + filter_osm_tags (key = "amenity", value = "pub") |> + filter_osm_tags ( key = "name", value = "irish", value_exact = FALSE, match_case = FALSE ) ``` Logical OR combinations can be constructed using the separate -[`add_osm_features()` -function](https://docs.ropensci.org/osmdata/reference/add_osm_features.html). +[`add_osm_tags()` +function](https://docs.ropensci.org/osmdata/reference/add_osm_tags.html). The first of the above examples requests all features that are both restaurants AND pubs. The following query will request data on restaurants OR pubs: ``` r q <- opq ("portsmouth usa") |> - add_osm_features (features = c ( + add_osm_tags (features = c ( "\"amenity\"=\"restaurant\"", "\"amenity\"=\"pub\"" )) @@ -231,7 +231,7 @@ and ### Data Formats -An overpass query constructed with the `opq()` and `add_osm_feature()` +An overpass query constructed with the `opq()` and `filter_osm_tags()` functions is then sent to the [overpass server](https://overpass-turbo.eu) to request data. These data may be returned in a variety of formats, currently including: diff --git a/data-raw/hex-script.Rmd b/data-raw/hex-script.Rmd index 47387ae9..2a556d39 100644 --- a/data-raw/hex-script.Rmd +++ b/data-raw/hex-script.Rmd @@ -10,26 +10,26 @@ bb <- getbb ("kichijoji japan") bb [2, 1] <- bb [2, 1] - 0.2 * diff (bb [2, ]) bb [2, 2] <- mean (bb [2, ]) hw <- opq (bb) |> - add_osm_feature (key = "highway") |> + filter_osm_tags (key = "highway") |> osmdata_sf (quiet = FALSE) |> osm_poly2line () |> extract2 ("osm_lines") b <- opq (bb) |> - add_osm_feature (key = "building") |> + filter_osm_tags (key = "building") |> osmdata_sf (quiet = FALSE) |> extract2 ("osm_polygons") g1 <- opq (bb) |> - add_osm_feature (key = "landuse", value = "grass") |> + filter_osm_tags (key = "landuse", value = "grass") |> osmdata_sf (quiet = FALSE) |> extract2 ("osm_polygons") g2 <- opq (bb) |> - add_osm_feature (key = "leisure", value = "park") |> + filter_osm_tags (key = "leisure", value = "park") |> osmdata_sf (quiet = FALSE) |> extract2 ("osm_polygons") g <- sf::st_sf (osm_id = c (g1$osm_id, g2$osm_id), geometry = c (g1$geometry, g2$geometry)) w <- opq (bb) |> - add_osm_feature (key = "natural", value = "water") |> + filter_osm_tags (key = "natural", value = "water") |> osmdata_sf (quiet = FALSE) |> extract2 ("osm_polygons") diff --git a/man/add_osm_tags.Rd b/man/add_osm_tags.Rd index 44ad81d9..38ca0c91 100644 --- a/man/add_osm_tags.Rd +++ b/man/add_osm_tags.Rd @@ -3,7 +3,7 @@ \name{add_osm_tags} \alias{add_osm_tags} \alias{add_osm_features} -\title{Add multiple features to an Overpass query} +\title{Add multiple tags to an Overpass query as independent statements} \usage{ add_osm_tags(opq, features, bbox = NULL, key_exact = TRUE, value_exact = TRUE) @@ -22,7 +22,7 @@ add_osm_features( key-value pairs with keys and values enclosed in escape-formatted quotations. See examples for details.} -\item{bbox}{optional bounding box for the feature query; must be set if no +\item{bbox}{optional bounding box for the query; must be set if no opq query bbox has been set.} \item{key_exact}{If FALSE, \code{key} is not interpreted exactly; see @@ -34,52 +34,54 @@ opq query bbox has been set.} An \link{opq} object. } \description{ -Alternative version of \code{\link[=add_osm_feature]{add_osm_feature()}} for creating single queries -with multiple features. Key-value matching may be controlled by using the -filter symbols described in +Alternative version of \code{\link[=filter_osm_tags]{filter_osm_tags()}} for creating single queries +with multiple tags in independent statements. Key-value matching may be +controlled by using the filter symbols described in \url{https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#By_tag_.28has-kv.29}. + +\code{add_osm_features()} will be DEPRECATED in future versions. } -\section{\code{add_osm_feature} vs \code{add_osm_features}}{ +\section{\code{filter_osm_tags} vs \code{add_osm_tags}}{ -Features defined within an \code{\link[=add_osm_features]{add_osm_features()}} call are combined with a +Tags defined within an \code{\link[=add_osm_tags]{add_osm_tags()}} call are combined with a logical OR. -Chained calls to either \code{add_osm_feature()} or \code{\link[=add_osm_features]{add_osm_features()}} combines -features from these calls in a logical AND; this is analagous to chaining +Chained calls to either \code{filter_osm_tags()} or \code{\link[=add_osm_tags]{add_osm_tags()}} combines +tags from these calls in a logical AND; this is analagous to chaining \code{dplyr::filter()} on a data frame. -\code{add_osm_features()} with only one feature is logically equivalent to -\code{add_osm_feature()}. +\code{add_osm_tags()} with only one tag is logically equivalent to +\code{filter_osm_tags()}. } \examples{ \dontrun{ q <- opq ("portsmouth usa") |> - add_osm_features (features = list ( + add_osm_tags (features = list ( "amenity" = "restaurant", "amenity" = "pub" )) q <- opq ("portsmouth usa") |> - add_osm_features (features = c ( + add_osm_tags (features = c ( "\"amenity\"=\"restaurant\"", "\"amenity\"=\"pub\"" )) cat (opq_string (q)) # This extracts in a single query the same result as the following: q1 <- opq ("portsmouth usa") |> - add_osm_feature ( + filter_osm_tags ( key = "amenity", value = "restaurant" ) q2 <- opq ("portsmouth usa") |> - add_osm_feature (key = "amenity", value = "pub") + filter_osm_tags (key = "amenity", value = "pub") c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs # Get objects with keys (`natural` OR `waterway`) AND `name` q_keys <- opq ("Badia del Vallès", osm_types = "nwr", out = "tags") |> - add_osm_features (features = list (natural = NULL, waterway = NULL)) |> - add_osm_feature (key = "name") + add_osm_tags (features = list (natural = NULL, waterway = NULL)) |> + filter_osm_tags (key = "name") cat (opq_string (q_keys)) } } @@ -87,7 +89,7 @@ cat (opq_string (q_keys)) \url{https://wiki.openstreetmap.org/wiki/Map_Features} } \seealso{ -\link{add_osm_feature} +\link{filter_osm_tags} Other queries: \code{\link{bbox_to_string}()}, diff --git a/man/filter_osm_tags.Rd b/man/filter_osm_tags.Rd index c682eea5..5add696b 100644 --- a/man/filter_osm_tags.Rd +++ b/man/filter_osm_tags.Rd @@ -3,7 +3,7 @@ \name{filter_osm_tags} \alias{filter_osm_tags} \alias{add_osm_feature} -\title{Add a feature to an Overpass query} +\title{Add tags to all current statements of an Overpass query} \usage{ filter_osm_tags( opq, @@ -28,10 +28,10 @@ add_osm_feature( \arguments{ \item{opq}{An \code{overpass_query} object} -\item{key}{feature key; can be negated with an initial exclamation mark, +\item{key}{tag key; can be negated with an initial exclamation mark, \code{key = "!this"}, and can also be a vector if \code{value} is missing.} -\item{value}{value for feature key; can be negated with an initial +\item{value}{value for tag key; can be negated with an initial exclamation mark, \code{value = "!this"}, and can also be a vector, \code{value = c ("this", "that")}.} @@ -43,14 +43,14 @@ exclamation mark, \code{value = "!this"}, and can also be a vector, \item{match_case}{If FALSE, matching for both \code{key} and \code{value} is not sensitive to case} -\item{bbox}{optional bounding box for the feature query; must be set if no +\item{bbox}{optional bounding box for the query; must be set if no opq query bbox has been set} } \value{ An \link{opq} object. } \description{ -Add a feature to an Overpass query +\code{add_osm_feature()} will be DEPRECATED in future versions. } \note{ \code{key_exact} should generally be \code{TRUE}, because OSM uses a @@ -61,54 +61,54 @@ of regular expressions on OSM keys, as described in Section 6.1.5 of query submitted to the overpass API can be obtained from \code{\link[=opq_string]{opq_string()}}. } -\section{\code{add_osm_feature} vs \code{add_osm_features}}{ +\section{\code{filter_osm_tags} vs \code{add_osm_tags}}{ -Features defined within an \code{\link[=add_osm_features]{add_osm_features()}} call are combined with a +Tags defined within an \code{\link[=add_osm_tags]{add_osm_tags()}} call are combined with a logical OR. -Chained calls to either \code{add_osm_feature()} or \code{\link[=add_osm_features]{add_osm_features()}} combines -features from these calls in a logical AND; this is analagous to chaining +Chained calls to either \code{filter_osm_tags()} or \code{\link[=add_osm_tags]{add_osm_tags()}} combines +tags from these calls in a logical AND; this is analagous to chaining \code{dplyr::filter()} on a data frame. -\code{add_osm_features()} with only one feature is logically equivalent to -\code{add_osm_feature()}. +\code{add_osm_tags()} with only one tag is logically equivalent to +\code{filter_osm_tags()}. } \examples{ \dontrun{ q <- opq ("portsmouth usa") |> - add_osm_feature ( + filter_osm_tags ( key = "amenity", value = "restaurant" ) |> - add_osm_feature (key = "amenity", value = "pub") + filter_osm_tags (key = "amenity", value = "pub") osmdata_sf (q) # all objects that are restaurants AND pubs (there are none!) q1 <- opq ("portsmouth usa") |> - add_osm_feature ( + filter_osm_tags ( key = "amenity", value = "restaurant" ) q2 <- opq ("portsmouth usa") |> - add_osm_feature (key = "amenity", value = "pub") + filter_osm_tags (key = "amenity", value = "pub") c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs # Use of negation to extract all non-primary highways q <- opq ("portsmouth uk") |> - add_osm_feature (key = "highway", value = "!primary") + filter_osm_tags (key = "highway", value = "!primary") # key negation without warnings q3 <- opq ("Vinçà", osm_type = "node") |> - add_osm_feature (key = c ("name", "!name:ca")) + filter_osm_tags (key = c ("name", "!name:ca")) cat (opq_string (q3)) q4 <- opq ("el Carxe", osm_type = "node") |> - add_osm_feature (key = "natural", value = "peak") |> - add_osm_feature (key = "!ele") + filter_osm_tags (key = "natural", value = "peak") |> + filter_osm_tags (key = "!ele") cat (opq_string (q4)) # Get objects with keys (`natural` OR `waterway`) AND `name` q_keys <- opq ("Badia del Vallès", osm_types = "nwr", out = "tags") |> - add_osm_features (features = list (natural = NULL, waterway = NULL)) |> - add_osm_feature (key = "name") + add_osm_tags (features = list (natural = NULL, waterway = NULL)) |> + filter_osm_tags (key = "name") cat (opq_string (q_keys)) } } @@ -116,7 +116,7 @@ cat (opq_string (q_keys)) \url{https://wiki.openstreetmap.org/wiki/Map_Features} } \seealso{ -\code{\link[=add_osm_features]{add_osm_features()}} +\code{\link[=add_osm_tags]{add_osm_tags()}} Other queries: \code{\link{add_osm_tags}()}, diff --git a/man/filter_osm_user.Rd b/man/filter_osm_user.Rd index 130f7ec8..5d80150d 100644 --- a/man/filter_osm_user.Rd +++ b/man/filter_osm_user.Rd @@ -37,7 +37,7 @@ for details. # Notice the "::user" and "::uid" fields in the oqp_csv() q_csv <- opq (bbox = "relation(id:11755232)", out = "meta", osm_type = "node") |> filter_osm_user (user = "jmaspons") |> - add_osm_feature (key = "name") |> + filter_osm_tags (key = "name") |> opq_csv (c ("::type", "::id", "name", "name:ca", "::user", "::uid")) cat (opq_string (q_csv)) # Warning: csv queries can fail without errors in long running queries. For timeouts, @@ -52,7 +52,7 @@ q_touched <- opq ( osm_type = "node", timeout = 100 ) |> filter_osm_user (user = "jmaspons", touched = TRUE) |> - add_osm_feature (key = "name") + filter_osm_tags (key = "name") cat (opq_string (q_touched)) \dontrun{ d_touched <- osmdata_data_frame (q_touched) diff --git a/man/opq.Rd b/man/opq.Rd index f7e54680..0bfc755c 100644 --- a/man/opq.Rd +++ b/man/opq.Rd @@ -93,33 +93,33 @@ are likely to be rejected. \dontrun{ q <- getbb ("portsmouth", display_name_contains = "United States") |> opq () |> - add_osm_feature ("amenity", "restaurant") |> - add_osm_feature ("amenity", "pub") + filter_osm_tags ("amenity", "restaurant") |> + filter_osm_tags ("amenity", "pub") osmdata_sf (q) # all objects that are restaurants AND pubs (there are none!) q1 <- getbb ("portsmouth", display_name_contains = "United States") |> opq () |> - add_osm_feature ("amenity", "restaurant") + filter_osm_tags ("amenity", "restaurant") q2 <- getbb ("portsmouth", display_name_contains = "United States") |> opq () |> - add_osm_feature ("amenity", "pub") + filter_osm_tags ("amenity", "pub") c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs # Use `osm_types = "node"` to retrieve single point data only, such as for central # locations of cities. opq <- opq (bbox, osm_types = "node") |> - add_osm_feature (key = "place", value = "city") |> + filter_osm_tags (key = "place", value = "city") |> osmdata_sf (quiet = FALSE) # Filter by a search area qa1 <- getbb ("Catalan Countries", format_out = "osm_type_id") |> opq (osm_types = "node") |> - add_osm_feature (key = "capital", value = "4") + filter_osm_tags (key = "capital", value = "4") opqa1 <- osmdata_sf (qa1) # Filter by a multiple search areas bb <- getbb ("Vilafranca", format_out = "data.frame") qa2 <- bbox_to_string (bb [bb$osm_type != "node", ]) |> opq (osm_types = "node") |> - add_osm_feature (key = "place") + filter_osm_tags (key = "place") opqa2 <- osmdata_sf (qa2) } } diff --git a/man/opq_around.Rd b/man/opq_around.Rd index 1ec9145c..fa40dbdf 100644 --- a/man/opq_around.Rd +++ b/man/opq_around.Rd @@ -24,7 +24,7 @@ because the server may time out before all data are delivered.} \description{ Find all features around a given point, and optionally match specific 'key'-'value' pairs. This function is \emph{not} intended to be combined with -\code{\link[=add_osm_feature]{add_osm_feature()}}, rather is only to be used in the sequence +\code{\link[=filter_osm_tags]{filter_osm_tags()}}, rather is only to be used in the sequence \code{\link[=opq_around]{opq_around()}} -> \code{\link[=osmdata_xml]{osmdata_xml()}} (or other extraction function). See examples for how to use. } diff --git a/man/opq_csv.Rd b/man/opq_csv.Rd index 80dc8e19..06b27e4e 100644 --- a/man/opq_csv.Rd +++ b/man/opq_csv.Rd @@ -8,7 +8,8 @@ opq_csv(q, fields, header = TRUE) } \arguments{ \item{q}{A opq string or an object of class \code{overpass_query} constructed with -\code{\link[=opq]{opq()}} or alternative opq builders (+ \code{\link[=add_osm_feature]{add_osm_feature()}}/s).} +\code{\link[=opq]{opq()}} or alternative opq builders (+ \code{\link[=filter_osm_tags]{filter_osm_tags()}}, +\code{\link[=add_osm_tags]{add_osm_tags()}}, \code{\link[=filter_osm_user]{filter_osm_user()}}).} \item{fields}{a character vector with the field names.} @@ -35,8 +36,8 @@ expected result. \dontrun{ q <- getbb ("Catalan Countries", format_out = "osm_type_id") |> opq (out = "tags center", osm_type = "relation", timeout = 100) |> - add_osm_feature ("admin_level", "7") |> - add_osm_feature ("boundary", "administrative") |> + filter_osm_tags ("admin_level", "7") |> + filter_osm_tags ("boundary", "administrative") |> opq_csv (fields = c ("name", "::type", "::id", "::lat", "::lon")) comarques <- osmdata_data_frame (q) # without timeout parameter, 0 rows diff --git a/man/opq_enclosing.Rd b/man/opq_enclosing.Rd index 25ad6ccb..68ea6b82 100644 --- a/man/opq_enclosing.Rd +++ b/man/opq_enclosing.Rd @@ -32,7 +32,7 @@ because the server may time out before all data are delivered.} \description{ Find all features which enclose a given point, and optionally match specific 'key'-'value' pairs. This function is \emph{not} intended to be combined with -\code{\link[=add_osm_feature]{add_osm_feature()}}, rather is only to be used in the sequence +\code{\link[=filter_osm_tags]{filter_osm_tags()}}, rather is only to be used in the sequence \code{\link[=opq_enclosing]{opq_enclosing()}} -> \code{\link[=opq_string]{opq_string()}} -> \code{\link[=osmdata_xml]{osmdata_xml()}} (or other extraction function). See examples for how to use. } diff --git a/man/opq_osm_id.Rd b/man/opq_osm_id.Rd index b6d246a9..565108bd 100644 --- a/man/opq_osm_id.Rd +++ b/man/opq_osm_id.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/opq.R \name{opq_osm_id} \alias{opq_osm_id} -\title{Add a feature specified by OSM ID to an Overpass query} +\title{Add features specified by OSM ID to an Overpass query} \usage{ opq_osm_id( id = NULL, @@ -61,7 +61,7 @@ may need to be increased in order to handle large queries.} An \link{opq} object. } \description{ -Add a feature specified by OSM ID to an Overpass query +Add features specified by OSM ID to an Overpass query } \note{ Extracting elements by ID requires explicitly specifying the type of diff --git a/man/osm_elevation.Rd b/man/osm_elevation.Rd index 2dae9d08..3b038900 100644 --- a/man/osm_elevation.Rd +++ b/man/osm_elevation.Rd @@ -26,7 +26,7 @@ pre-downloaded global elevation file from \examples{ \dontrun{ query <- opq ("omaha nebraska") |> - add_osm_feature (key = "highway") + filter_osm_tags (key = "highway") # Elevation can only be applied to \pkg{silicate} 'SC'-class data: dat <- osmdata_sc (query) dat$vertex diff --git a/man/osm_lines.Rd b/man/osm_lines.Rd index 0275c492..2bba49d4 100644 --- a/man/osm_lines.Rd +++ b/man/osm_lines.Rd @@ -24,7 +24,7 @@ polygon. \examples{ \dontrun{ dat <- opq ("hengelo nl") |> - add_osm_feature (key = "highway") |> + filter_osm_tags (key = "highway") |> osmdata_sf () bus <- dat$osm_points [which (dat$osm_points$highway == "bus_stop"), ] |> rownames () # all OSM IDs of bus stops @@ -32,7 +32,7 @@ osm_lines (dat, bus) # all highways containing bus stops # All lines which intersect with Piccadilly Circus in London, UK dat <- opq ("Fitzrovia London") |> - add_osm_feature (key = "highway") |> + filter_osm_tags (key = "highway") |> osmdata_sf () i <- which (dat$osm_polygons$name == "Piccadilly Circus") id <- rownames (dat$osm_polygons [i, ]) diff --git a/man/osm_multilines.Rd b/man/osm_multilines.Rd index fef200c1..f3030a1a 100644 --- a/man/osm_multilines.Rd +++ b/man/osm_multilines.Rd @@ -24,7 +24,7 @@ object(s) which contain the object specified by \code{id}. \examples{ \dontrun{ dat <- opq ("London UK") |> - add_osm_feature (key = "name", value = "Thames", exact = FALSE) |> + filter_osm_tags (key = "name", value = "Thames", exact = FALSE) |> osmdata_sf () # Get ids of lines called "The Thames": id <- rownames (dat$osm_lines [which (dat$osm_lines$name == "The Thames"), ]) diff --git a/man/osm_multipolygons.Rd b/man/osm_multipolygons.Rd index fccc55f2..3c1c301e 100644 --- a/man/osm_multipolygons.Rd +++ b/man/osm_multipolygons.Rd @@ -25,7 +25,7 @@ object(s) which contain the object specified by \code{id}. # "Chiswick Eyot" (which is an island). \dontrun{ dat <- opq ("London UK") |> - add_osm_feature (key = "name", value = "Thames", exact = FALSE) |> + filter_osm_tags (key = "name", value = "Thames", exact = FALSE) |> osmdata_sf () index <- which (dat$osm_multipolygons$name == "Chiswick Eyot") id <- rownames (dat$osm_polygons [id, ]) diff --git a/man/osm_poly2line.Rd b/man/osm_poly2line.Rd index 78290338..eda10fe2 100644 --- a/man/osm_poly2line.Rd +++ b/man/osm_poly2line.Rd @@ -26,7 +26,7 @@ repeated as \code{LINESTRING} objects in \code{osm_lines}. \examples{ \dontrun{ query <- opq ("colchester uk") |> - add_osm_feature (key = "highway") + filter_osm_tags (key = "highway") # Then extract data from 'Overpass' API dat <- osmdata_sf (query) # colchester has lots of roundabouts, and these are stored in 'osm_polygons' diff --git a/man/osm_polygons.Rd b/man/osm_polygons.Rd index 5b8fc764..559da882 100644 --- a/man/osm_polygons.Rd +++ b/man/osm_polygons.Rd @@ -25,7 +25,7 @@ or polygon. # Extract polygons which intersect Conway Street in London \dontrun{ dat <- opq ("Marylebone London") |> - add_osm_feature (key = "highway") |> + filter_osm_tags (key = "highway") |> osmdata_sf () conway <- which (dat$osm_lines$name == "Conway Street") id <- rownames (dat$osm_lines [conway, ]) diff --git a/man/osmdata-package.Rd b/man/osmdata-package.Rd index 5fa4ec89..84163418 100644 --- a/man/osmdata-package.Rd +++ b/man/osmdata-package.Rd @@ -22,8 +22,8 @@ to find all lines which intersect a given point). unnamed vector) return a string \item \code{\link[=overpass_status]{overpass_status()}}: Retrieve status of the overpass API \item \code{\link[=opq]{opq()}}: Build an overpass query -\item \code{\link[=add_osm_feature]{add_osm_feature()}}: Add a feature to an overpass query -\item \code{\link[=add_osm_features]{add_osm_features()}}: Add multiple features to an Overpass query +\item \code{\link[=filter_osm_tags]{filter_osm_tags()}}: Add tags to all current statements of an Overpass query +\item \code{\link[=add_osm_tags]{add_osm_tags()}}: Add multiple tags to independent statments of an Overpass query \item \code{\link[=filter_osm_user]{filter_osm_user()}}: Add an user filter to an Overpass query \item \code{\link[=opq_string]{opq_string()}}: Convert an osmdata query to overpass API string } diff --git a/man/osmdata_data_frame.Rd b/man/osmdata_data_frame.Rd index 0b7dc586..d16cd216 100644 --- a/man/osmdata_data_frame.Rd +++ b/man/osmdata_data_frame.Rd @@ -8,7 +8,7 @@ osmdata_data_frame(q, doc, quiet = TRUE, stringsAsFactors = FALSE) } \arguments{ \item{q}{An object of class \code{overpass_query} constructed with -\code{\link[=opq]{opq()}} and \code{\link[=add_osm_feature]{add_osm_feature()}} or a string with a valid query, such +\code{\link[=opq]{opq()}} and \code{\link[=filter_osm_tags]{filter_osm_tags()}} or a string with a valid query, such as \code{"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"}. May be be omitted, in which case the attributes of the \link{data.frame} will not include the query. See examples below.} @@ -31,14 +31,14 @@ Return an OSM Overpass query as a \link{data.frame} object. } \details{ If you are not interested in the geometries of the results, it's a -good option to query for objects that match the features only and forget +good option to query for objects that match the statements only and forget about members of the ways and relations. You can achieve this by passing the parameter \code{body = "tags"} to \code{\link[=opq]{opq()}}. } \examples{ \dontrun{ query <- opq ("hampi india") |> - add_osm_feature (key = "historic", value = "ruins") + filter_osm_tags (key = "historic", value = "ruins") # Then extract data from 'Overpass' API hampi_df <- osmdata_data_frame (query) attr (hampi_df, "bbox") diff --git a/man/osmdata_sc.Rd b/man/osmdata_sc.Rd index 4184cc0c..cdfb9243 100644 --- a/man/osmdata_sc.Rd +++ b/man/osmdata_sc.Rd @@ -9,7 +9,7 @@ osmdata_sc(q, doc, quiet = TRUE) } \arguments{ \item{q}{An object of class \code{overpass_query} constructed with -\code{\link[=opq]{opq()}} and \code{\link[=add_osm_feature]{add_osm_feature()}} or a string with a valid query, such +\code{\link[=opq]{opq()}} and \code{\link[=filter_osm_tags]{filter_osm_tags()}} or a string with a valid query, such as \code{"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"}. May be be omitted, in which case the \link{osmdata} object will not include the query. See examples below.} @@ -35,7 +35,7 @@ recommended for use only if you really know what you're doing. \examples{ \dontrun{ query <- opq ("hampi india") |> - add_osm_feature (key = "historic", value = "ruins") + filter_osm_tags (key = "historic", value = "ruins") # Then extract data from 'Overpass' API hampi_sc <- osmdata_sc (query) } diff --git a/man/osmdata_sf.Rd b/man/osmdata_sf.Rd index 8e04b771..77aa4d25 100644 --- a/man/osmdata_sf.Rd +++ b/man/osmdata_sf.Rd @@ -8,7 +8,7 @@ osmdata_sf(q, doc, quiet = TRUE, stringsAsFactors = FALSE) } \arguments{ \item{q}{An object of class \code{overpass_query} constructed with -\code{\link[=opq]{opq()}} and \code{\link[=add_osm_feature]{add_osm_feature()}} or a string with a valid query, such +\code{\link[=opq]{opq()}} and \code{\link[=filter_osm_tags]{filter_osm_tags()}} or a string with a valid query, such as \code{"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"}. May be be omitted, in which case the \link{osmdata} object will not include the query. See examples below.} @@ -37,7 +37,7 @@ the \pkg{sf} package into the current workspace with 'library(sf)'. \examples{ \dontrun{ query <- opq ("hampi india") |> - add_osm_feature (key = "historic", value = "ruins") + filter_osm_tags (key = "historic", value = "ruins") # Then extract data from 'Overpass' API hampi_sf <- osmdata_sf (query) } diff --git a/man/osmdata_sp.Rd b/man/osmdata_sp.Rd index 53c4a09c..73e237d0 100644 --- a/man/osmdata_sp.Rd +++ b/man/osmdata_sp.Rd @@ -9,7 +9,7 @@ osmdata_sp(q, doc, quiet = TRUE) } \arguments{ \item{q}{An object of class \code{overpass_query} constructed with -\code{\link[=opq]{opq()}} and \code{\link[=add_osm_feature]{add_osm_feature()}} or a string with a valid query, such +\code{\link[=opq]{opq()}} and \code{\link[=filter_osm_tags]{filter_osm_tags()}} or a string with a valid query, such as \code{"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"}. May be be omitted, in which case the \link{osmdata} object will not include the query. See examples below.} @@ -31,7 +31,7 @@ format. \examples{ \dontrun{ query <- opq ("hampi india") |> - add_osm_feature (key = "historic", value = "ruins") + filter_osm_tags (key = "historic", value = "ruins") # Then extract data from 'Overpass' API hampi_sp <- osmdata_sp (query) } diff --git a/man/osmdata_xml.Rd b/man/osmdata_xml.Rd index 8bff361d..8e35f4de 100644 --- a/man/osmdata_xml.Rd +++ b/man/osmdata_xml.Rd @@ -10,7 +10,7 @@ osmdata_xml(q, filename, quiet = TRUE, encoding) } \arguments{ \item{q}{An object of class \code{overpass_query} constructed with -\code{\link[=opq]{opq()}} and \code{\link[=add_osm_feature]{add_osm_feature()}} or a string with a valid query, such as +\code{\link[=opq]{opq()}} and \code{\link[=filter_osm_tags]{filter_osm_tags()}} or a string with a valid query, such as \code{"(node(39.4712701,-0.3841326,39.4713799,-0.3839475);); out;"}. See examples below.} @@ -38,7 +38,7 @@ Objects of class \code{xml_document} can be saved as \code{.xml} or \examples{ \dontrun{ query <- opq ("hampi india") |> - add_osm_feature (key = "historic", value = "ruins") + filter_osm_tags (key = "historic", value = "ruins") # Then extract data from 'Overpass' API and save to local file: osmdata_xml (query, filename = "hampi.osm") } diff --git a/man/trim_osmdata.Rd b/man/trim_osmdata.Rd index e968b0da..4df0ff8c 100644 --- a/man/trim_osmdata.Rd +++ b/man/trim_osmdata.Rd @@ -43,7 +43,7 @@ the server-side using \code{getbb(..., format_out = "osm_type_id")} \dontrun{ bb <- getbb ("colchester uk") query <- opq (bb) |> - add_osm_feature (key = "highway") + filter_osm_tags (key = "highway") # Then extract data from 'Overpass' API dat <- osmdata_sf (query, quiet = FALSE) # Then get bounding *polygon* for Colchester, as opposed to rectangular @@ -61,7 +61,7 @@ dat_tr <- trim_osmdata (dat, bb_sp) # Server-side trimming equivalent bb <- getbb ("colchester uk", format_out = "osm_type_id") query <- opq (bb) |> - add_osm_feature (key = "highway") + filter_osm_tags (key = "highway") dat <- osmdata_sf (query, quiet = FALSE) } } diff --git a/man/unique_osmdata.Rd b/man/unique_osmdata.Rd index b3c099ff..16478f82 100644 --- a/man/unique_osmdata.Rd +++ b/man/unique_osmdata.Rd @@ -25,7 +25,7 @@ typical output of \pkg{sf}. \examples{ \dontrun{ query <- opq ("colchester uk") |> - add_osm_feature (key = "highway") + filter_osm_tags (key = "highway") # Then extract data from 'Overpass' API dat <- osmdata_sf (query) dat diff --git a/man/unname_osmdata_sf.Rd b/man/unname_osmdata_sf.Rd index 308061e6..c6441517 100644 --- a/man/unname_osmdata_sf.Rd +++ b/man/unname_osmdata_sf.Rd @@ -24,7 +24,7 @@ issues such as those linked to above. \examples{ \dontrun{ query <- opq ("hampi india") |> - add_osm_feature (key = "historic", value = "ruins") + filter_osm_tags (key = "historic", value = "ruins") # Then extract data from 'Overpass' API hampi_sf <- osmdata_sf (query) # Remove rownames from all geometry metrices: diff --git a/src/osmdata-sf.cpp b/src/osmdata-sf.cpp index 1768faa4..d6521d74 100644 --- a/src/osmdata-sf.cpp +++ b/src/osmdata-sf.cpp @@ -202,7 +202,7 @@ Rcpp::List osm_sf::get_osm_relations (const Relations &rels, } // Erase any multipolygon ways that are not okay. An example of these is - // opq("salzburg") |> add_osm_feature (key = "highway"), for which + // opq("salzburg") |> filter_osm_tags (key = "highway"), for which // $osm_multipolygons [[42]] with way#4108738 is not okay. std::vector not_okay_id; for (size_t i = 0; i < mp_okay.size (); i++) diff --git a/vignettes/osm-sf-translation.Rmd b/vignettes/osm-sf-translation.Rmd index 93017a12..49efe4df 100644 --- a/vignettes/osm-sf-translation.Rmd +++ b/vignettes/osm-sf-translation.Rmd @@ -206,7 +206,7 @@ The following three lines define a query and download the resultant data to an `XML` file. ```{r trentham, eval=FALSE} q <- opq (bbox = "Trentham, Australia") -q <- add_osm_feature (q, key = "name") # any named objects +q <- filter_osm_tags (q, key = "name") # any named objects osmdata_xml (q, "trentham.osm") ``` These data may then be converted into SF representations using either `R::sf` or diff --git a/vignettes/osmdata-sc.Rmd b/vignettes/osmdata-sc.Rmd index 08a87dfe..1080711f 100644 --- a/vignettes/osmdata-sc.Rmd +++ b/vignettes/osmdata-sc.Rmd @@ -74,7 +74,7 @@ through the `osm_elevation()` function. The entire procedure is demonstrated with the following lines: ```{r omaha, eval = FALSE} dat <- opq ("omaha nebraska") |> - add_osm_feature (key = "highway") |> + filter_osm_tags (key = "highway") |> osmdata_sc () ``` This object has a `vertex` table like this: diff --git a/vignettes/osmdata.Rmd b/vignettes/osmdata.Rmd index 9a932dfd..a2ad9de4 100644 --- a/vignettes/osmdata.Rmd +++ b/vignettes/osmdata.Rmd @@ -67,17 +67,17 @@ q <- opq (bbox = c (51.1, 0.1, 51.2, 0.2)) The following sub-section provides more detail on bounding boxes. Following the initial `opq()` call, `osmdata` queries are built by adding one or more -'features', which are specified in terms of `key-value` pairs. For example, all +'tags', which are specified in terms of `key-value` pairs. For example, all paths, ways, and roads are designated in OSM with `key=highway`, so that a query all motorways in greater London (UK) can be constructed as follows: ```{r opq3, eval = FALSE} q <- opq (bbox = "greater london uk") |> - add_osm_feature (key = "highway", value = "motorway") + filter_osm_tags (key = "highway", value = "motorway") ``` ```{r, echo = FALSE} q <- opq (bbox = c (51.2867602, -0.510375, 51.6918741, 0.3340155)) |> - add_osm_feature (key = "highway", value = "motorway") + filter_osm_tags (key = "highway", value = "motorway") ``` A detailed description of features is provided at the @@ -101,7 +101,7 @@ respectively. The typical workflow for extracting OSM data with `osmdata` thus consists of the three lines: ```{r workflow, eval = FALSE} x <- opq (bbox = "greater london uk") |> - add_osm_feature (key = "highway", value = "motorway") |> + filter_osm_tags (key = "highway", value = "motorway") |> osmdata_sf () ``` The return object (`x`) is described in the third section below. @@ -143,7 +143,7 @@ extracted with, ```{r trim-osmdata, eval = FALSE} bb <- getbb ("london uk", format_out = "polygon") x <- opq (bbox = bb) |> - add_osm_feature (key = "highway", value = "motorway") |> + filter_osm_tags (key = "highway", value = "motorway") |> osmdata_sf () |> trim_osmdata (bb) ``` @@ -228,49 +228,49 @@ the format typically used in `overpass-turbo`.) ### 2.1. osmdata queries As demonstrated above, an `osmdata` query begins by specifying a bounding box -with the function `opq()`, followed by specifying desired OSM features with -`add_osm_feature()`. +with the function `opq()`, followed by specifying desired OSM tags with +`filter_osm_tags()`. ```{r kunming1, eval = FALSE} q <- opq (bbox = "Kunming, China") |> - add_osm_feature (key = "natural", value = "water") + filter_osm_tags (key = "natural", value = "water") ``` This query will request all natural water water bodies in Kunming, China. A particular water body may be requested through appending a further call to -`add_osm_feature()`: +`filter_osm_tags()`: ```{r kunming2, eval = FALSE} q <- opq (bbox = "Kunming, China") |> - add_osm_feature (key = "natural", value = "water") |> - add_osm_feature (key = "name:en", value = "Dian", value_exact = FALSE) + filter_osm_tags (key = "natural", value = "water") |> + filter_osm_tags (key = "name:en", value = "Dian", value_exact = FALSE) ``` ```{r, echo = FALSE} q <- opq (bbox = c (102.5417638, 24.8915153, 102.8617638, 25.2115153)) |> - add_osm_feature (key = "natural", value = "water") |> - add_osm_feature (key = "name:en", value = "Dian", value_exact = FALSE) + filter_osm_tags (key = "natural", value = "water") |> + filter_osm_tags (key = "name:en", value = "Dian", value_exact = FALSE) ``` -Each successive call to `add_osm_feature()` **adds** features to a query. This query +Each successive call to `filter_osm_tags()` **adds** tags to a query. This query is thus a request for all bodies of natural water **and** those with English names that include 'Dian'. The requested data may be extracted through calling one of the `osmdata_xml/sp/sf()` functions. -Single queries are always constructed through **adding** features, and therefore +Single queries are always constructed through **adding** tags, and therefore correspond to logical **AND** operations: natural water bodies **AND** those whose names include 'Dian'. The equivalent **OR** combination can be extracted -with the [`add_osm_features()` -function](https://docs.ropensci.org/osmdata/reference/add_osm_features.html). +with the [`add_osm_tags()` +function](https://docs.ropensci.org/osmdata/reference/add_osm_tags.html). The following query represents the OR-equivalent of the above query, requesting data on both all natural features with the value of `"water"` OR all features whose English name is `"Dian"`. -```{r add_osm_features-fakey, eval = FALSE} +```{r add_osm_tags-fakey, eval = FALSE} q <- opq (bbox = "Kunming, China") |> - add_osm_features (features = c ( + add_osm_tags (features = c ( "\"natural\"=\"water\"", "\"name:en\"=\"Dian\"" )) ``` -```{r add_osm_features, echo = FALSE} +```{r add_osm_tags, echo = FALSE} q <- list ( bbox = "24.388848,102.1697441,26.548485,103.6683522", prefix = "[out:xml][timeout:25];\n(\n", @@ -280,7 +280,7 @@ q <- list ( attr (q, "class") <- c ("list", "overpass_query") ``` -Note that the `"="` symbols here requests features whose values exactly match +Note that the `"="` symbols here requests tags whose values exactly match the given values. Other "filter" symbols are possible, as described in the [overpass query language definition](https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL#By_tag_.28has-kv.29), @@ -294,20 +294,20 @@ of `osmdata`. ```{r kunming3, eval = FALSE} dat1 <- opq (bbox = "Kunming, China") |> - add_osm_feature (key = "natural", value = "water") |> + filter_osm_tags (key = "natural", value = "water") |> osmdata_sf () dat2 <- opq (bbox = "Kunming, China") |> - add_osm_feature (key = "name:en", value = "Dian", value_exact = FALSE) |> + filter_osm_tags (key = "name:en", value = "Dian", value_exact = FALSE) |> osmdata_sf () dat <- c (dat1, dat2) ``` While the "filter" symbols may be explicitly specified in -[the `add_osm_features()` -function](https://docs.ropensci.org/osmdata/reference/add_osm_features.html), -the single-feature version of -[`add_osm_feature()` -function](https://docs.ropensci.org/osmdata/reference/add_osm_feature.html) has +[the `add_osm_tags()` +function](https://docs.ropensci.org/osmdata/reference/add_osm_tags.html), +the single-tag version of +[`filter_osm_tags()` +function](https://docs.ropensci.org/osmdata/reference/filter_osm_tags.html) has several logical parameters to control matching without needing to remember precise overpass syntax: @@ -320,7 +320,7 @@ The previous query with `key = 'name:end'` and `value = 'Dian'` could thus be replaced by the following: ```{r kunming4, eval = FALSE} -add_osm_feature ( +filter_osm_tags ( key = "name", value = "dian", key_exact = FALSE, value_exact = FALSE, @@ -356,8 +356,8 @@ In summary, `osmdata` queries are generally simplified versions of potentially more complex `overpass` queries, although arbitrarily complex `overpass` queries may be passed directly to the primary `osmdata` functions. As illustrated above, `osmdata` queries are generally constructed through initiating a query -with `opq()`, and then specifying OSM features in terms of `key-value` pairs -with `add_osm_feature()`, along with judicious usage of the `key_exact`, +with `opq()`, and then specifying OSM tags in terms of `key-value` pairs +with `filter_osm_tags()`, along with judicious usage of the `key_exact`, `value_exact`, and `match_case` parameters. The simplest way to use `osmdata` is to simply request all data within a given @@ -369,13 +369,13 @@ lots_of_data <- osmdata_sf (q) ``` Queries are, however, usually more useful when refined through using -`add_osm_feature()`, which minimally requires a single `key` and returns all objects +`filter_osm_tags()`, which minimally requires a single `key` and returns all objects specifying any value for that `key`: ```{r opq-london, eval = FALSE} not_so_much_data <- opq (bbox = "city of london uk") |> - add_osm_feature (key = "highway") |> - add_osm_feature (key = "name") |> + filter_osm_tags (key = "highway") |> + filter_osm_tags (key = "name") |> osmdata_sf () ``` @@ -392,7 +392,7 @@ wanted to find all cycle paths in Seville, Spain: ```{r opq-seville-plot, eval = FALSE} q1 <- opq ("Sevilla") |> - add_osm_feature (key = "highway", value = "cycleway") + filter_osm_tags (key = "highway", value = "cycleway") cway_sev <- osmdata_sp (q1) sp::plot (cway_sev$osm_lines) ``` @@ -405,7 +405,7 @@ only those that are designated cycleways **AND** that are bridges: ```{r des-bike1, eval=FALSE} des_bike <- osmdata_sf (q1) -q2 <- add_osm_feature (q1, key = "bridge", value = "yes") +q2 <- filter_osm_tags (q1, key = "bridge", value = "yes") des_bike_and_bridge <- osmdata_sf (q2) nrow (des_bike_and_bridge$osm_points) nrow (des_bike_and_bridge$osm_lines) @@ -419,7 +419,7 @@ operator: ```{r, des-bike2, eval=FALSE} q2 <- opq ("Sevilla") |> - add_osm_feature (key = "bridge", value = "yes") + filter_osm_tags (key = "bridge", value = "yes") bridge <- osmdata_sf (q2) des_bike_or_bridge <- c (des_bike, bridge) nrow (des_bike_or_bridge$osm_points) @@ -488,7 +488,7 @@ with a new query. ```{r osmdata_xml-london-buildings, eval = FALSE} dat <- opq (bbox = c (-0.12, 51.51, -0.11, 51.52)) |> - add_osm_feature (key = "building") |> + filter_osm_tags (key = "building") |> osmdata_xml (file = "buildings.osm") class (dat) ## [1] "xml_document" "xml_node" @@ -501,7 +501,7 @@ as the name of a file or an XML object: ```{r osmdata_with_files, eval = FALSE} q <- opq (bbox = c (-0.12, 51.51, -0.11, 51.52)) |> - add_osm_feature (key = "building") + filter_osm_tags (key = "building") doc <- osmdata_xml (q, "buildings.osm") dat1 <- osmdata_sf (q, doc) dat2 <- osmdata_sf (q, "buildings.osm") @@ -570,7 +570,7 @@ The following example is based on this query: ```{r trentham, eval = FALSE} opq (bbox = "Trentham, Australia") |> - add_osm_feature (key = "name") |> + filter_osm_tags (key = "name") |> osmdata_xml (filename = "trentham.osm") ``` @@ -758,7 +758,7 @@ objects from Trentham, Australia: ```{r, eval = FALSE} tr <- opq (bbox = "Trentham, Australia") |> - add_osm_feature (key = "name") |> + filter_osm_tags (key = "name") |> osmdata_sf () ``` @@ -839,7 +839,7 @@ which is composed of many (over 100) separate lines: ```{r, eval = FALSE} lcnr9 <- opq ("greater london uk") |> - add_osm_feature ( + filter_osm_tags ( key = "name", value = "LCN 9", value_exact = FALSE ) |> @@ -880,7 +880,7 @@ the OSM database prior to a specified date, or within a specified range of dates. This is achieved by passing one or both values to the [`opq()` function](https://docs.ropensci.org/osmdata/reference/opq.html) of `datetime` and `datetime2`. The resultant data extracted with one or more -`add_osm_feature()` calls and an extraction function (`osmdata_sf/sp/sc/xml`) +`filter_osm_tags()` calls and an extraction function (`osmdata_sf/sp/sc/data_frame/xml`) will then contain only those data present prior to the specified date (when `datetime` only given), or between the two specified dates (when both `datetime` and `datetime2` given). diff --git a/vignettes/query-split.Rmd b/vignettes/query-split.Rmd index e02ca42f..c302e98e 100644 --- a/vignettes/query-split.Rmd +++ b/vignettes/query-split.Rmd @@ -81,10 +81,10 @@ queries: res <- list () res [[1]] <- opq (bbox = bbs [[1]]) |> - add_osm_feature (key = "admin_level", value = "8") |> + filter_osm_tags (key = "admin_level", value = "8") |> osmdata_sf () res [[2]] <- opq (bbox = bbs [[2]]) |> - add_osm_feature (key = "admin_level", value = "8") |> + filter_osm_tags (key = "admin_level", value = "8") |> osmdata_sf () ``` @@ -163,7 +163,7 @@ while (length (queue) > 0) { opres <- NULL opres <- try ({ opq (bbox = queue [[1]], timeout = 25) |> - add_osm_feature (key = "natural", value = "tree") |> + filter_osm_tags (key = "natural", value = "tree") |> osmdata_sf () }) From ffc5b48ebb8a8c1cdfed7bb4de7fb3af91f3be7e Mon Sep 17 00:00:00 2001 From: Joan Maspons Date: Wed, 18 Mar 2026 10:58:07 +0100 Subject: [PATCH 3/5] Rename features -> tags where it make sense Feature refers to represented entities represented by OSM objects. Tags are the attributes of OSM objects that characterize the features. --- R/opq.R | 105 +++++++++++++------------ man/add_osm_tags.Rd | 12 +-- man/filter_osm_tags.Rd | 2 +- tests/testthat/test-osmdata.R | 4 +- tests/testthat/test-set_bind_key_pre.R | 10 +-- 5 files changed, 68 insertions(+), 65 deletions(-) diff --git a/R/opq.R b/R/opq.R index 20292683..1eda1733 100644 --- a/R/opq.R +++ b/R/opq.R @@ -206,11 +206,11 @@ opq <- function (bbox = NULL, nodes_only, } # used in the following filter_osm_tags fn -paste_features <- function (key, value, key_pre = "", bind = "=", - match_case = FALSE, value_exact = FALSE) { +paste_tags <- function (key, value, key_pre = "", bind = "=", + match_case = FALSE, value_exact = FALSE) { if (is.null (value)) { - feature <- ifelse (substring (key, 1, 1) == "!", + tag <- ifelse (substring (key, 1, 1) == "!", sprintf ('[!"%s"]', substring (key, 2, nchar (key))), sprintf ('["%s"]', key) ) @@ -235,17 +235,17 @@ paste_features <- function (key, value, key_pre = "", bind = "=", key_pre <- "" } } - feature <- paste0 (sprintf ( + tag <- paste0 (sprintf ( '[%s"%s"%s"%s"', key_pre, key, bind, value )) if (!match_case) { - feature <- paste0 (feature, ",i") + tag <- paste0 (tag, ",i") } - feature <- paste0 (feature, "]") + tag <- paste0 (tag, "]") } - return (feature) + return (tag) } #' Add tags to all current statements of an Overpass query @@ -323,7 +323,7 @@ paste_features <- function (key, value, key_pre = "", bind = "=", #' #' # Get objects with keys (`natural` OR `waterway`) AND `name` #' q_keys <- opq ("Badia del Vallès", osm_types = "nwr", out = "tags") |> -#' add_osm_tags (features = list (natural = NULL, waterway = NULL)) |> +#' add_osm_tags (tags = list (natural = NULL, waterway = NULL)) |> #' filter_osm_tags (key = "name") #' cat (opq_string (q_keys)) #' } @@ -353,16 +353,16 @@ filter_osm_tags <- function (opq, value <- NULL } - feature <- paste_features ( + tags <- paste_tags ( key, value, bind_key_pre$key_pre, bind_key_pre$bind, match_case, value_exact ) - feature <- paste (feature, collapse = " ") + tags <- paste (tags, collapse = " ") if (is.null (opq$features)) { - opq$features <- feature + opq$features <- tags } else { - opq$features <- paste (opq$features, feature) + opq$features <- paste (opq$features, tags) } if (any (w <- !grepl ("\\[(\\\"|~)", opq$features))) { @@ -419,7 +419,7 @@ add_osm_feature <- function (opq, # TODO: DEPRECATE #' @noRd set_bind_key_pre <- function (key_exact = TRUE, value_exact = TRUE, - features = NULL, + tags = NULL, bind = "=", key_pre = "") { if (!is.null (value_exact)) { @@ -428,35 +428,35 @@ set_bind_key_pre <- function (key_exact = TRUE, check_bind_key_pre (bind, key_pre) - if (!is.null (features)) { + if (!is.null (tags)) { if (length (bind) == 1) { - bind <- rep_len (bind, length (features)) - } else if (!identical_length (features, bind)) { + bind <- rep_len (bind, length (tags)) + } else if (!identical_length (tags, bind)) { stop ( - "bind must be length 1 or the same length as features" + "bind must be length 1 or the same length as tags" ) } if (length (key_pre) == 1) { - key_pre <- rep_len (key_pre, length (features)) - } else if (!identical_length (features, key_pre)) { + key_pre <- rep_len (key_pre, length (tags)) + } else if (!identical_length (tags, key_pre)) { stop ( - "key_pre must be length 1 or the same length as features" + "key_pre must be length 1 or the same length as tags" ) } } - features_len <- 1L - if (!is.null (features)) { - features_len <- length (features) + tags_len <- 1L + if (!is.null (tags)) { + tags_len <- length (tags) } if (!is.null (value_exact) && !value_exact) { - bind <- rep_len ("~", features_len) + bind <- rep_len ("~", tags_len) } if (!is.null (key_exact) && !key_exact) { - key_pre <- rep_len ("~", features_len) + key_pre <- rep_len ("~", tags_len) } list ( @@ -510,7 +510,7 @@ check_bind_key_pre <- function (bind = "=", key_pre = "") { #' #' @inheritParams filter_osm_tags #' @inheritSection filter_osm_tags `filter_osm_tags` vs `add_osm_tags` -#' @param features A named list or vector with the format `list("" = +#' @param tags A named list or vector with the format `list("" = #' "")` or `c("" = "")` or a character vector of #' key-value pairs with keys and values enclosed in escape-formatted #' quotations. See examples for details. @@ -527,13 +527,13 @@ check_bind_key_pre <- function (bind = "=", key_pre = "") { #' @examples #' \dontrun{ #' q <- opq ("portsmouth usa") |> -#' add_osm_tags (features = list ( +#' add_osm_tags (tags = list ( #' "amenity" = "restaurant", #' "amenity" = "pub" #' )) #' #' q <- opq ("portsmouth usa") |> -#' add_osm_tags (features = c ( +#' add_osm_tags (tags = c ( #' "\"amenity\"=\"restaurant\"", #' "\"amenity\"=\"pub\"" #' )) @@ -550,12 +550,12 @@ check_bind_key_pre <- function (bind = "=", key_pre = "") { #' #' # Get objects with keys (`natural` OR `waterway`) AND `name` #' q_keys <- opq ("Badia del Vallès", osm_types = "nwr", out = "tags") |> -#' add_osm_tags (features = list (natural = NULL, waterway = NULL)) |> +#' add_osm_tags (tags = list (natural = NULL, waterway = NULL)) |> #' filter_osm_tags (key = "name") #' cat (opq_string (q_keys)) #' } add_osm_tags <- function (opq, - features, + tags, bbox = NULL, key_exact = TRUE, value_exact = TRUE) { @@ -572,37 +572,37 @@ add_osm_tags <- function (opq, opq$suffix <- ");\n(._;>;);\nout body;" } - check_features (features) + check_tags (tags) - if (is_named (features)) { + if (is_named (tags)) { bind_key_pre <- set_bind_key_pre ( - features = features, + tags = tags, value_exact = value_exact, key_exact = key_exact ) - features <- mapply ( + tags <- mapply ( function (key, value, key_pre, bind) { - paste_features (key, value, + paste_tags (key, value, key_pre = key_pre, bind = bind, match_case = TRUE, value_exact = value_exact ) }, - key = names (features), value = features, + key = names (tags), value = tags, key_pre = bind_key_pre$key_pre, bind = bind_key_pre$bind, SIMPLIFY = FALSE ) - features <- as.character (features) + tags <- as.character (tags) } - index <- which (!grepl ("^\\[", features)) - features [index] <- paste0 ("[", features [index]) - index <- which (!grepl ("\\]$", features)) - features [index] <- paste0 (features [index], "]") + index <- which (!grepl ("^\\[", tags)) + tags [index] <- paste0 ("[", tags [index]) + index <- which (!grepl ("\\]$", tags)) + tags [index] <- paste0 (tags [index], "]") - opq$features <- unique (c (opq$features, features)) + opq$features <- unique (c (opq$features, tags)) opq } @@ -610,6 +610,7 @@ add_osm_tags <- function (opq, #' @rdname add_osm_tags #' #' @description `add_osm_features()` will be DEPRECATED in future versions. +#' @param features Same as `tags`. #' #' @export add_osm_features <- function (opq, # TODO: DEPRECATE @@ -619,7 +620,7 @@ add_osm_features <- function (opq, # TODO: DEPRECATE value_exact = TRUE) { add_osm_tags ( opq = opq, - features = features, + tags = features, bbox = bbox, key_exact = key_exact, value_exact = value_exact @@ -644,19 +645,19 @@ is_escape_delimited <- function (x) { #' Check if tags is provided and uses the required class and formatting #' #' @noRd -check_features <- function (features) { - if (missing (features)) { - stop ("features must be provided", call. = FALSE) +check_tags <- function (tags) { + if (missing (tags)) { + stop ("tags must be provided", call. = FALSE) } stopifnot ( - "features must be a list or character vector." = - is.character (features) | is.list (features) + "tags must be a list or character vector." = + is.character (tags) | is.list (tags) ) - if (!is_named (features) && is_escape_delimited (features)) { + if (!is_named (tags) && is_escape_delimited (tags)) { stop ( - "features must be a named list or vector or a character vector ", + "tags must be a named list or vector or a character vector ", "enclosed in escape delimited quotations (see examples)", call. = FALSE ) @@ -891,7 +892,7 @@ opq_enclosing <- function (lon = NULL, lat = NULL, prefix <- paste0 ("[out:xml][timeout:", timeout, "]") suffix <- ");\n(._;>;);\nout;" - features <- paste_features (key, + tags <- paste_tags (key, value, value_exact = TRUE, match_case = TRUE @@ -900,7 +901,7 @@ opq_enclosing <- function (lon = NULL, lat = NULL, bbox = bbox, prefix = paste0 (prefix, ";\n(\n"), suffix = suffix, - features = features + features = tags ) class (res) <- c (class (res), "overpass_query") attr (res, "datetime") <- attr (res, "datetime2") <- NULL diff --git a/man/add_osm_tags.Rd b/man/add_osm_tags.Rd index 38ca0c91..5e6d4026 100644 --- a/man/add_osm_tags.Rd +++ b/man/add_osm_tags.Rd @@ -5,7 +5,7 @@ \alias{add_osm_features} \title{Add multiple tags to an Overpass query as independent statements} \usage{ -add_osm_tags(opq, features, bbox = NULL, key_exact = TRUE, value_exact = TRUE) +add_osm_tags(opq, tags, bbox = NULL, key_exact = TRUE, value_exact = TRUE) add_osm_features( opq, @@ -18,7 +18,7 @@ add_osm_features( \arguments{ \item{opq}{An \code{overpass_query} object} -\item{features}{A named list or vector with the format \code{list("" = "")} or \code{c("" = "")} or a character vector of +\item{tags}{A named list or vector with the format \code{list("" = "")} or \code{c("" = "")} or a character vector of key-value pairs with keys and values enclosed in escape-formatted quotations. See examples for details.} @@ -29,6 +29,8 @@ opq query bbox has been set.} \url{https://wiki.openstreetmap.org/wiki/Overpass_API}} \item{value_exact}{If FALSE, \code{value} is not interpreted exactly} + +\item{features}{Same as \code{tags}.} } \value{ An \link{opq} object. @@ -57,13 +59,13 @@ tags from these calls in a logical AND; this is analagous to chaining \examples{ \dontrun{ q <- opq ("portsmouth usa") |> - add_osm_tags (features = list ( + add_osm_tags (tags = list ( "amenity" = "restaurant", "amenity" = "pub" )) q <- opq ("portsmouth usa") |> - add_osm_tags (features = c ( + add_osm_tags (tags = c ( "\"amenity\"=\"restaurant\"", "\"amenity\"=\"pub\"" )) @@ -80,7 +82,7 @@ c (osmdata_sf (q1), osmdata_sf (q2)) # all restaurants OR pubs # Get objects with keys (`natural` OR `waterway`) AND `name` q_keys <- opq ("Badia del Vallès", osm_types = "nwr", out = "tags") |> - add_osm_tags (features = list (natural = NULL, waterway = NULL)) |> + add_osm_tags (tags = list (natural = NULL, waterway = NULL)) |> filter_osm_tags (key = "name") cat (opq_string (q_keys)) } diff --git a/man/filter_osm_tags.Rd b/man/filter_osm_tags.Rd index 5add696b..5eff250f 100644 --- a/man/filter_osm_tags.Rd +++ b/man/filter_osm_tags.Rd @@ -107,7 +107,7 @@ cat (opq_string (q4)) # Get objects with keys (`natural` OR `waterway`) AND `name` q_keys <- opq ("Badia del Vallès", osm_types = "nwr", out = "tags") |> - add_osm_tags (features = list (natural = NULL, waterway = NULL)) |> + add_osm_tags (tags = list (natural = NULL, waterway = NULL)) |> filter_osm_tags (key = "name") cat (opq_string (q_keys)) } diff --git a/tests/testthat/test-osmdata.R b/tests/testthat/test-osmdata.R index 7fd6d5ec..1c6df18d 100644 --- a/tests/testthat/test-osmdata.R +++ b/tests/testthat/test-osmdata.R @@ -400,7 +400,7 @@ test_that ("add_osm_features", { qry <- opq (bbox = c (-0.118, 51.514, -0.115, 51.517)) expect_error ( qry <- add_osm_features (qry), - "features must be provided" + "tags must be provided" ) qry$bbox <- NULL @@ -413,7 +413,7 @@ test_that ("add_osm_features", { expect_error ( qry <- add_osm_features (qry, features = "a"), - "features must be a named list or vector or a character vector enclosed in escape delimited quotations \\(see examples\\)" + "tags must be a named list or vector or a character vector enclosed in escape delimited quotations \\(see examples\\)" ) bbox <- c (-0.118, 51.514, -0.115, 51.517) diff --git a/tests/testthat/test-set_bind_key_pre.R b/tests/testthat/test-set_bind_key_pre.R index cfd5c52f..64a6d18b 100644 --- a/tests/testthat/test-set_bind_key_pre.R +++ b/tests/testthat/test-set_bind_key_pre.R @@ -4,22 +4,22 @@ # package developers decide the option could be useful. test_that ("set_bind_key_pre errors", { - features <- list ("amenity" = "restaurant", "amenity" = "pub") + tags <- list ("amenity" = "restaurant", "amenity" = "pub") expect_error ( set_bind_key_pre ( - features = features, + tags = tags, bind = rep ("=", 3) ), - "bind must be length 1 or the same length as features" + "bind must be length 1 or the same length as tags" ) expect_error ( set_bind_key_pre ( - features = features, + tags = tags, key_pre = rep ("", 3) ), - "key_pre must be length 1 or the same length as features" + "key_pre must be length 1 or the same length as tags" ) expect_error ( From a64f7263149bff83ed759715a172373e907c773c Mon Sep 17 00:00:00 2001 From: Joan Maspons Date: Wed, 18 Mar 2026 10:59:29 +0100 Subject: [PATCH 4/5] Document soft deprecation --- R/deprecated.R | 14 ++++++++++++++ man/osmdata-deprecated.Rd | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/R/deprecated.R b/R/deprecated.R index c1e1fa68..8c53b440 100644 --- a/R/deprecated.R +++ b/R/deprecated.R @@ -18,6 +18,20 @@ #' } #' } #' +#' \describe{ +#' \item{`add_osm_feature()`}{ +#' Please use [`filter_osm_tags()`] instead. +#' In future versions, using [`add_osm_feature()`] will produce a deprecation warning. +#' } +#' } +#' +#' \describe{ +#' \item{`add_osm_features()`}{ +#' Please use [`add_osm_tags()`] instead. +#' In future versions, using [`add_osm_features()`] will produce a deprecation warning. +#' } +#' } +#' #' @name osmdata-deprecated #' @keywords internal NULL diff --git a/man/osmdata-deprecated.Rd b/man/osmdata-deprecated.Rd index c2b55bd1..6f250fa6 100644 --- a/man/osmdata-deprecated.Rd +++ b/man/osmdata-deprecated.Rd @@ -24,6 +24,20 @@ Please use \code{\link[=osmdata_sf]{osmdata_sf()}} or \code{\link[=osmdata_sc]{o Since version 0.3, using \code{\link[=osmdata_sp]{osmdata_sp()}} will produce a deprecation warning. } } + +\describe{ +\item{\code{add_osm_feature()}}{ +Please use \code{\link[=filter_osm_tags]{filter_osm_tags()}} instead. +In future versions, using \code{\link[=add_osm_feature]{add_osm_feature()}} will produce a deprecation warning. +} +} + +\describe{ +\item{\code{add_osm_features()}}{ +Please use \code{\link[=add_osm_tags]{add_osm_tags()}} instead. +In future versions, using \code{\link[=add_osm_features]{add_osm_features()}} will produce a deprecation warning. +} +} } \keyword{internal} From cf5500b7db447289b7eb4ee3d169d0f6f3d70ae0 Mon Sep 17 00:00:00 2001 From: Joan Maspons Date: Wed, 18 Mar 2026 11:12:01 +0100 Subject: [PATCH 5/5] Update function names in tests All tests passed without changes before this commit. Old functions still work --- tests/testthat/test-data_frame-osm.R | 34 +++++++------- tests/testthat/test-elevation.R | 2 +- tests/testthat/test-opq.R | 12 ++--- tests/testthat/test-osmdata.R | 64 +++++++++++++------------- tests/testthat/test-set_bind_key_pre.R | 2 +- tests/testthat/test-unname.R | 2 +- tests/timing-benchmark.R | 28 ++++++----- 7 files changed, 75 insertions(+), 69 deletions(-) diff --git a/tests/testthat/test-data_frame-osm.R b/tests/testthat/test-data_frame-osm.R index 2d729cac..e3f32c52 100644 --- a/tests/testthat/test-data_frame-osm.R +++ b/tests/testthat/test-data_frame-osm.R @@ -69,7 +69,7 @@ test_that ("empty result", { colnames (bb) <- c ("min", "max") q0 <- opq (bb, osm_types = "node", datetime = "1714-09-11T00:00:00Z") |> - add_osm_feature ("does not exist", "&%$") + filter_osm_tags ("does not exist", "&%$") osm_empty <- test_path ("fixtures", "osm-empty.osm") doc <- xml2::read_xml (osm_empty) @@ -104,7 +104,7 @@ test_that ("empty result", { datetime = "1714-09-11T00:00:00Z", adiff = TRUE ) |> - add_osm_feature ("does not exist", "&%$") + filter_osm_tags ("does not exist", "&%$") # osm_empty <- test_path ("fixtures", "osm-empty.osm") # same result # doc <- xml2::read_xml (osm_empty) @@ -177,9 +177,9 @@ test_that ("date", { rownames (bb) <- c ("x", "y") colnames (bb) <- c ("min", "max") q <- opq (bb, osm_types = "node", datetime = "2020-11-07T00:00:00Z") |> - add_osm_feature ("natural", "peak") |> - add_osm_feature ("prominence") |> - add_osm_feature ("name:ca") + filter_osm_tags ("natural", "peak") |> + filter_osm_tags ("prominence") |> + filter_osm_tags ("name:ca") osm_meta_date <- test_path ("fixtures", "osm-date.osm") doc <- xml2::read_xml (osm_meta_date) @@ -222,7 +222,7 @@ test_that ("out tags center", { rownames (bb) <- c ("x", "y") colnames (bb) <- c ("min", "max") q <- opq (bb, out = "tags center") |> - add_osm_feature ("amenity", "community_centre") + filter_osm_tags ("amenity", "community_centre") osm_tags_center <- test_path ("fixtures", "osm-tags_center.osm") doc <- xml2::read_xml (osm_tags_center) @@ -258,9 +258,9 @@ test_that ("out meta & diff", { datetime = "2020-11-07T00:00:00Z", datetime2 = "2022-12-04T00:00:00Z" ) |> - add_osm_feature ("natural", "peak") |> - add_osm_feature ("prominence") |> - add_osm_feature ("name:ca") + filter_osm_tags ("natural", "peak") |> + filter_osm_tags ("prominence") |> + filter_osm_tags ("name:ca") osm_meta_diff <- test_path ("fixtures", "osm-meta_diff.osm") doc <- xml2::read_xml (osm_meta_diff) @@ -310,9 +310,9 @@ test_that ("out meta & adiff", { osm_types = "node", out = "meta", datetime = "2020-11-07T00:00:00Z", adiff = TRUE ) |> - add_osm_feature ("natural", "peak") |> - add_osm_feature ("prominence") |> - add_osm_feature ("name:ca") + filter_osm_tags ("natural", "peak") |> + filter_osm_tags ("prominence") |> + filter_osm_tags ("name:ca") osm_meta_adiff <- test_path ("fixtures", "osm-meta_adiff.osm") doc <- xml2::read_xml (osm_meta_adiff) @@ -372,7 +372,7 @@ test_that ("out tags center & adiff", { adiff = TRUE, timeout = 50 ) |> - add_osm_feature ("amenity", "community_centre") + filter_osm_tags ("amenity", "community_centre") osm_tags_center <- test_path ("fixtures", "osm-tags_center-adiff.osm") doc <- xml2::read_xml (osm_tags_center) @@ -421,7 +421,7 @@ test_that ("adiff2", { datetime2 = "2016-11-07T00:00:00Z", adiff = TRUE ) |> - add_osm_feature ("amenity", "restaurant") + filter_osm_tags ("amenity", "restaurant") osm_adiff2 <- test_path ("fixtures", "osm-adiff2.osm") doc <- xml2::read_xml (osm_adiff2) @@ -462,8 +462,8 @@ test_that ("adiff2", { test_that ("out:csv", { # q <- getbb ("Catalan Countries", format_out = "osm_type_id") |> q <- opq (bbox = "relation(id:11747082)", out = "tags center", osm_type = "relation", timeout = 50) |> - add_osm_feature ("admin_level", "7") |> - add_osm_feature ("boundary", "administrative") |> + filter_osm_tags ("admin_level", "7") |> + filter_osm_tags ("boundary", "administrative") |> opq_csv (fields = c ("name", "::type", "::id", "::lat", "::lon")) with_mock_dir ("mock_csv", { @@ -476,7 +476,7 @@ test_that ("out:csv", { # qqoutes <- getbb ("Barcelona", format_out = "osm_type_id") |> qqoutes <- opq (bbox = "relation(id:347950)", osm_types = "nwr", out = "tags") |> opq_csv (fields = c ("name", "::id", "no_exists", "amenity")) |> - add_osm_feature ( + filter_osm_tags ( key = "name", value = "\\\"|,|Pont", value_exact = FALSE ) diff --git a/tests/testthat/test-elevation.R b/tests/testthat/test-elevation.R index 98088f69..9022716b 100644 --- a/tests/testthat/test-elevation.R +++ b/tests/testthat/test-elevation.R @@ -3,7 +3,7 @@ test_that ("elevation", { # elevation can't actually be tested, because it only works with a full SRTM # elevation file, so this test doesn't actually do anything. qry <- opq (bbox = c (-0.116, 51.516, -0.115, 51.517)) |> - add_osm_feature (key = "highway") + filter_osm_tags (key = "highway") f <- file.path (tempdir (), "junk.osm") doc <- with_mock_dir ("mock_elevation", { diff --git a/tests/testthat/test-opq.R b/tests/testthat/test-opq.R index ce4de116..baf0a67d 100644 --- a/tests/testthat/test-opq.R +++ b/tests/testthat/test-opq.R @@ -137,7 +137,7 @@ test_that ("osm_types", { ) expect_true ("nwr" == q1$osm_types) - features <- c ( + tags <- c ( "\"amenity\"=\"school\"", "\"amenity\"=\"kindergarten\"", "\"amenity\"=\"music_school\"", @@ -145,10 +145,10 @@ test_that ("osm_types", { "\"amenity\"=\"dancing_school\"" ) q2 <- opq ("relation(id:349053)") |> # "Catalunya" - add_osm_features (features = features) + add_osm_tags (tags = tags) s <- opq_string (q2) - n_fts <- length (features) + n_fts <- length (tags) n_fts_in_query <- length (gregexpr ("amenity", s) [[1]]) # Query should have that number repeated for each osm_types (default to # node, way, relation): @@ -336,7 +336,7 @@ test_that ("opq_string", { bbox = c (-0.118, 51.514, -0.115, 51.517), osm_types = "node" ) - q1 <- add_osm_feature (q1, key = "amenity", value = "restaurant") + q1 <- filter_osm_tags (q1, key = "amenity", value = "restaurant") s1 <- opq_string (q1) # nodes only, so "out" instead of "out body" and no way nor relation expect_false (grepl ("\\(\\._;>;\\)", s1)) @@ -346,7 +346,7 @@ test_that ("opq_string", { bbox = "relation(id:11747082)", osm_types = "node" ) - q2 <- add_osm_feature (q2, key = "amenity", value = "restaurant") + q2 <- filter_osm_tags (q2, key = "amenity", value = "restaurant") s2 <- opq_string (q2) # nodes only, so "out" instead of "out body" and no way nor relation on clauses expect_false (grepl ("\\(\\._;>;\\)", s2)) @@ -367,7 +367,7 @@ test_that ("opq_string", { # key-value pair: - q2 <- add_osm_feature (q0, key = "highway", value = "!primary") + q2 <- filter_osm_tags (q0, key = "highway", value = "!primary") s2 <- opq_string (q2) expect_true (grepl ("highway", s2)) expect_true (grepl ("primary", s2)) diff --git a/tests/testthat/test-osmdata.R b/tests/testthat/test-osmdata.R index 1c6df18d..7ca8e49e 100644 --- a/tests/testthat/test-osmdata.R +++ b/tests/testthat/test-osmdata.R @@ -3,27 +3,27 @@ has_internet <- curl::has_internet () test_that ("query-construction", { q0 <- opq (bbox = c (-0.12, 51.51, -0.11, 51.52)) - expect_error (q1 <- add_osm_feature (q0), "key must be provided") - expect_silent (q1 <- add_osm_feature (q0, key = "aaa")) # bbox from qry + expect_error (q1 <- filter_osm_tags (q0), "key must be provided") + expect_silent (q1 <- filter_osm_tags (q0, key = "aaa")) # bbox from qry q0$bbox <- NULL expect_error ( - q1 <- add_osm_feature (q0, key = "aaa"), + q1 <- filter_osm_tags (q0, key = "aaa"), "Bounding box has to either be set in opq or must be set here" ) q0 <- opq (bbox = c (-0.12, 51.51, -0.11, 51.52)) - q1 <- add_osm_feature (q0, key = "aaa") + q1 <- filter_osm_tags (q0, key = "aaa") expect_false (grepl ("=", q1$features)) - q1 <- add_osm_feature (q0, key = "aaa", value = "bbb") + q1 <- filter_osm_tags (q0, key = "aaa", value = "bbb") expect_true (grepl ("=", q1$features)) expect_message ( - q1 <- add_osm_feature (q0, + q1 <- filter_osm_tags (q0, key = "aaa", value = "bbb", key_exact = FALSE ), "key_exact = FALSE can only combined with value_exact = FALSE;" ) expect_silent ( - q1 <- add_osm_feature (q0, + q1 <- filter_osm_tags (q0, key = "aaa", value = "bbb", key_exact = FALSE, value_exact = FALSE ) @@ -33,14 +33,14 @@ test_that ("query-construction", { test_that ("add feature", { qry <- opq (bbox = c (-0.118, 51.514, -0.115, 51.517)) - qry1 <- add_osm_feature (qry, key = "highway") - qry2 <- add_osm_feature (qry, key = "highway", value = "primary") - qry3 <- add_osm_feature (qry, + qry1 <- filter_osm_tags (qry, key = "highway") + qry2 <- filter_osm_tags (qry, key = "highway", value = "primary") + qry3 <- filter_osm_tags (qry, key = "highway", value = c ("primary", "tertiary") ) - qry4 <- add_osm_feature (qry, key = "highway", value = "!primary") - qry5 <- add_osm_feature (qry, + qry4 <- filter_osm_tags (qry, key = "highway", value = "!primary") + qry5 <- filter_osm_tags (qry, key = "highway", value = "primary", match_case = FALSE ) @@ -56,7 +56,7 @@ test_that ("add feature", { bbox <- c (-0.118, 51.514, -0.115, 51.517) qry <- opq (bbox = bbox) bbox2 <- bbox + c (0.01, 0.01, -0.01, -0.01) - qry6 <- add_osm_feature ( + qry6 <- filter_osm_tags ( qry, bbox = bbox2, key = "highway", @@ -65,14 +65,14 @@ test_that ("add feature", { expect_true (!identical (qry$bbox, qry6$bbox)) qry7 <- opq ("relation(id:74310)") |> # "Vinçà" - add_osm_feature (key = c ("name", "!name:ca")) + filter_osm_tags (key = c ("name", "!name:ca")) qry8 <- opq ("relation(id:11755232)") |> # "el Carxe" - add_osm_feature (key = "natural", value = "peak") |> - add_osm_feature (key = "!ele") + filter_osm_tags (key = "natural", value = "peak") |> + filter_osm_tags (key = "!ele") expect_warning ( qry9 <- opq ("relation(id:11755232)") |> # "el Carxe" - add_osm_feature (key = "!ele") |> - add_osm_feature (key = "natural", value = "peak"), + filter_osm_tags (key = "!ele") |> + filter_osm_tags (key = "natural", value = "peak"), "The query will request objects whith only a negated key " ) expect_identical (qry7$features, "[\"name\"] [!\"name:ca\"]") @@ -249,7 +249,7 @@ test_that ("osmdata without query", { test_that ("make_query", { qry <- opq (bbox = c (-0.116, 51.516, -0.115, 51.517)) - qry <- add_osm_feature (qry, key = "highway") + qry <- filter_osm_tags (qry, key = "highway") if (!has_internet) { expect_error ( @@ -361,7 +361,7 @@ test_that ("make_query", { test_that ("query-no-quiet", { qry <- opq (bbox = c (-0.116, 51.516, -0.115, 51.517)) - qry <- add_osm_feature (qry, key = "highway") + qry <- filter_osm_tags (qry, key = "highway") with_mock_dir ("mock_osm_xml", { expect_message ( @@ -395,47 +395,47 @@ test_that ("query-no-quiet", { }) }) -test_that ("add_osm_features", { +test_that ("add_osm_tags", { qry <- opq (bbox = c (-0.118, 51.514, -0.115, 51.517)) expect_error ( - qry <- add_osm_features (qry), + qry <- add_osm_tags (qry), "tags must be provided" ) qry$bbox <- NULL expect_error ( - qry <- add_osm_features (qry, features = "a"), + qry <- add_osm_tags (qry, tags = "a"), "Bounding box has to either be set in opq or must be set here" ) qry <- opq (bbox = c (-0.118, 51.514, -0.115, 51.517)) expect_error ( - qry <- add_osm_features (qry, features = "a"), + qry <- add_osm_tags (qry, tags = "a"), "tags must be a named list or vector or a character vector enclosed in escape delimited quotations \\(see examples\\)" ) bbox <- c (-0.118, 51.514, -0.115, 51.517) bbox_mod <- bbox + c (-0.001, -0.001, 0.001, 0.001) qry0 <- opq (bbox = bbox) - qry1 <- add_osm_features (qry0, features = "\"amenity\"=\"restaurant\"") - qry2 <- add_osm_features (qry0, - features = "\"amenity\"=\"restaurant\"", + qry1 <- add_osm_tags (qry0, tags = "\"amenity\"=\"restaurant\"") + qry2 <- add_osm_tags (qry0, + tags = "\"amenity\"=\"restaurant\"", bbox = bbox_mod ) expect_false (identical (qry1$bbox, qry2$bbox)) - qry3 <- add_osm_features (qry0, features = c ("amenity" = "restaurant")) + qry3 <- add_osm_tags (qry0, tags = c ("amenity" = "restaurant")) expect_identical (qry1, qry3) - qry4 <- add_osm_features (qry0, - features = c ("amenity" = "restaurant", "amentity" = "pub") + qry4 <- add_osm_tags (qry0, + tags = c ("amenity" = "restaurant", "amentity" = "pub") ) expect_s3_class (qry4, "overpass_query") - qry5 <- add_osm_features (qry0, - features = list ("amenity" = "restaurant", "amentity" = "pub") + qry5 <- add_osm_tags (qry0, + tags = list ("amenity" = "restaurant", "amentity" = "pub") ) expect_s3_class (qry5, "overpass_query") }) diff --git a/tests/testthat/test-set_bind_key_pre.R b/tests/testthat/test-set_bind_key_pre.R index 64a6d18b..bb746ce2 100644 --- a/tests/testthat/test-set_bind_key_pre.R +++ b/tests/testthat/test-set_bind_key_pre.R @@ -1,6 +1,6 @@ # NOTE: As of November 2022, these conditions are currently not possible, and # can only be triggered by direct calls to the internal functions. The bind -# and key_pre parameters may be exposed in add_osm_features() in the future if +# and key_pre parameters may be exposed in add_osm_tags() in the future if # package developers decide the option could be useful. test_that ("set_bind_key_pre errors", { diff --git a/tests/testthat/test-unname.R b/tests/testthat/test-unname.R index a163a8f0..2445fce2 100644 --- a/tests/testthat/test-unname.R +++ b/tests/testthat/test-unname.R @@ -3,7 +3,7 @@ require (sf) test_that ("unname", { qry <- opq (bbox = c (-0.116, 51.516, -0.115, 51.517)) - qry <- add_osm_feature (qry, key = "highway") + qry <- filter_osm_tags (qry, key = "highway") res <- with_mock_dir ("mock_unname", { osmdata_sf (qry) diff --git a/tests/timing-benchmark.R b/tests/timing-benchmark.R index d584cb8c..2a94e22c 100644 --- a/tests/timing-benchmark.R +++ b/tests/timing-benchmark.R @@ -1,20 +1,23 @@ -#library (osmdata) +# library (osmdata) benchmark <- function (times = 100) { devtools::load_all (".", export_all = FALSE) - q0 <- opq (bbox = c(-0.27, 51.47, -0.20, 51.50)) - q1 <- add_osm_feature (q0, key = "name", value = "Thames") + q0 <- opq (bbox = c (-0.27, 51.47, -0.20, 51.50)) + q1 <- filter_osm_tags (q0, key = "name", value = "Thames") # contains both multipolygons and multilinestrings doc <- osmdata_xml (q1, "export.osm") - objs <- c ("points", "lines", "multilinestrings", "multipolygons", - "other_relations") + objs <- c ( + "points", "lines", "multilinestrings", "multipolygons", + "other_relations" + ) mt_sf <- size_sf <- NULL for (i in seq (objs)) { mb <- microbenchmark::microbenchmark ( - dat <- sf::st_read ("export.osm", layer = objs [i], quiet = TRUE), - times = times) + dat <- sf::st_read ("export.osm", layer = objs [i], quiet = TRUE), + times = times + ) size_sf <- c (size_sf, object.size (dat)) mt_sf <- c (mt_sf, median (mb$time)) cat ("\r", i, " / ", length (objs)) @@ -24,13 +27,16 @@ benchmark <- function (times = 100) { cat ("\t(", mt_sf, "); total = ", sum (mt_sf), "\n") mb <- microbenchmark::microbenchmark (x <- osmdata_sf (q1, doc), - times = times) - #mb <- microbenchmark::microbenchmark ( x <- osmdata_sf (q1, "export.osm"), + times = times + ) + # mb <- microbenchmark::microbenchmark ( x <- osmdata_sf (q1, "export.osm"), # times = 10L) mt <- median (mb$time / 1e6) cat ("osmdata: Median time = ", mt, " ms\n") size_od <- object.size (x) - cat ("\nosmdata took ", mt / sum (mt_sf), " times longer to extract ", - size_od / sum (size_sf), " times as much data\n") + cat ( + "\nosmdata took ", mt / sum (mt_sf), " times longer to extract ", + size_od / sum (size_sf), " times as much data\n" + ) }