Skip to content

Commit

Permalink
Merge pull request #45 from dieghernan/structured
Browse files Browse the repository at this point in the history
Add structured query api
  • Loading branch information
dieghernan authored Apr 8, 2024
2 parents da35987 + 41d2926 commit cdb0abf
Show file tree
Hide file tree
Showing 65 changed files with 2,529 additions and 523 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
^CODE_OF_CONDUCT\.md$
^CONTRIBUTING\.md$
^Rplots\.pdf$
^vignettes/articles$
45 changes: 30 additions & 15 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,6 @@ references:
- type: url
value: https://arxiv.org/abs/1403.2805
version: '>= 1.7.0'
- type: software
title: lifecycle
abstract: 'lifecycle: Manage the Life Cycle of your Package Functions'
notes: Imports
url: https://lifecycle.r-lib.org/
repository: https://CRAN.R-project.org/package=lifecycle
authors:
- family-names: Henry
given-names: Lionel
email: [email protected]
- family-names: Wickham
given-names: Hadley
email: [email protected]
orcid: https://orcid.org/0000-0003-4757-117X
year: '2024'
- type: software
title: sf
abstract: 'sf: Simple Features for R'
Expand Down Expand Up @@ -211,6 +196,21 @@ references:
email: [email protected]
orcid: https://orcid.org/0000-0003-0645-5666
year: '2024'
- type: software
title: lifecycle
abstract: 'lifecycle: Manage the Life Cycle of your Package Functions'
notes: Suggests
url: https://lifecycle.r-lib.org/
repository: https://CRAN.R-project.org/package=lifecycle
authors:
- family-names: Henry
given-names: Lionel
email: [email protected]
- family-names: Wickham
given-names: Hadley
email: [email protected]
orcid: https://orcid.org/0000-0003-4757-117X
year: '2024'
- type: software
title: rmarkdown
abstract: 'rmarkdown: Dynamic Documents for R'
Expand Down Expand Up @@ -266,6 +266,21 @@ references:
email: [email protected]
year: '2024'
version: '>= 3.0.0'
- type: software
title: tibble
abstract: 'tibble: Simple Data Frames'
notes: Suggests
url: https://tibble.tidyverse.org/
repository: https://CRAN.R-project.org/package=tibble
authors:
- family-names: Müller
given-names: Kirill
email: [email protected]
orcid: https://orcid.org/0000-0002-1416-3412
- family-names: Wickham
given-names: Hadley
email: [email protected]
year: '2024'
- type: software
title: tidygeocoder
abstract: 'tidygeocoder: Geocoding Made Easy'
Expand Down
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@ Depends:
Imports:
dplyr (>= 1.0.0),
jsonlite (>= 1.7.0),
lifecycle,
sf (>= 0.9.0),
utils
Suggests:
arcgeocoder,
ggplot2 (>= 3.0.0),
knitr,
lifecycle,
rmarkdown,
testthat (>= 3.0.0),
tibble,
tidygeocoder
VignetteBuilder:
knitr
Config/Needs/website: dieghernan/gitdevr, remotes, devtools, tidyverse
Config/Needs/website: dieghernan/gitdevr, remotes, devtools, tidyverse,
leaflet, reactable, crosswalk, tidyr
Config/testthat/edition: 3
Config/testthat/parallel: true
Copyright: Data © OpenStreetMap contributors, ODbL 1.0.
<https://www.openstreetmap.org/copyright>
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
X-schema.org-applicationCategory: cartography
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export(geo_amenity)
export(geo_amenity_sf)
export(geo_lite)
export(geo_lite_sf)
export(geo_lite_struct)
export(geo_lite_struct_sf)
export(nominatim_check_access)
export(reverse_geo_lite)
export(reverse_geo_lite_sf)
Expand Down
30 changes: 30 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
# nominatimlite (development version)

- New functions:

- `geo_lite_struct()` and `geo_lite_struct_sf()` for performing structured
queries.
- Bring back `geo_amenity()` and `geo_amenity_sf()` as a wrapper of
`geo_lite_struct()` / `geo_lite_struct_sf(),` so now are more robust and
compatible with **sf** objects.

- Improve unnesting of fields when requiring `extratags`, i.e.
`custom_query = list(extratags = TRUE)`.

- It is possible to use **nominatimlite** with local server thanks to the new
argument `nominatim_server` (#42 \@alexwhitedatamine).

- Adapt endpoints to **Nominatim v4.4.0** `[Python-only]`.

- `nominatimlite::osm_amenities` data set re-introduced, updated and with
additional description fields.

- API call for non-spatial function uses now JSONV2 format (`&format=jsonv2`).
This implies the following changes in the output:

- `class` renamed to `category`.
- additional field `place_rank` with the search rank of the object.

- `custom_query` argument can use vectors and `logical`:

``` r
geo_lite(address = "New York",
custom_query = list(addressdetails = TRUE,
viewbox = c(-60, -20, 60, 20))
)
```

# nominatimlite 0.3.0

- Add a `progressbar` parameter to `geo_lite()`, `geo_lite_sf()`,
Expand Down
4 changes: 2 additions & 2 deletions R/bbox_to_poly.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#'
#' @family spatial
#'
#' @param bbox numeric vector of 4 elements representing the coordinates of the
#' @param bbox Numeric vector of 4 elements representing the coordinates of the
#' bounding box. Values should be `c(xmin, ymin, xmax, ymax)`.
#' @param xmin,ymin,xmax,ymax alternatively, you can use these named parameters
#' @param xmin,ymin,xmax,ymax Alternatively, you can use these named parameters
#' instead of `bbox`.
#'
#' @inheritParams sf::st_sf
Expand Down
35 changes: 35 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#' OpenStreetMap amenity database
#'
#' @description
#' Database with the list of amenities available on OpenStreetMap.
#'
#' @family datasets
#' @family amenity
#'
#' @encoding UTF-8
#'
#' @name osm_amenities
#'
#' @docType data
#'
#' @format
#' A [`tibble`][tibble::tibble] with with
#' `r prettyNum(nrow(nominatimlite::osm_amenities), big.mark=",")` rows and
#' fields:
#' \describe{
#' \item{category}{The category of the amenity.}
#' \item{amenity}{The value of the amenity.}
#' \item{comment}{A brief description of the type of amenity.}
#' }
#'
#'
#' @source <https://wiki.openstreetmap.org/wiki/Key:amenity>
#'
#' @note Data extracted on **03 April 2024**.
#'
#' @examples
#'
#' data("osm_amenities")
#'
#' osm_amenities
NULL
66 changes: 0 additions & 66 deletions R/deprecated.R

This file was deleted.

8 changes: 3 additions & 5 deletions R/geo_address_lookup.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#' @family lookup
#' @family geocoding
#'
#' @param osm_ids vector of OSM identifiers as **numeric**
#' @param osm_ids Vector of OSM identifiers as **numeric**
#' (`c(00000, 11111, 22222)`).
#' @param type vector character of the type of the OSM type associated to each
#' @param type Vector character of the type of the OSM type associated to each
#' `osm_ids`. Possible values are node (`"N"`), way (`"W"`) or relation
#' (`"R"`). If a single value is provided it would be recycled.
#'
Expand Down Expand Up @@ -64,7 +64,7 @@ geo_address_lookup <- function(osm_ids,
nodes <- paste0(type, osm_ids, collapse = ",")

# Compose url
url <- paste0(api, "osm_ids=", nodes, "&format=json")
url <- paste0(api, "osm_ids=", nodes, "&format=jsonv2")

if (full_results) url <- paste0(url, "&addressdetails=1")

Expand All @@ -81,14 +81,12 @@ geo_address_lookup <- function(osm_ids,
# Keep a tbl with the query
tbl_query <- dplyr::tibble(query = paste0(type, osm_ids))

# nocov start
# If no response...
if (isFALSE(res)) {
message(url, " not reachable.")
out <- empty_tbl(tbl_query, lat, long)
return(invisible(out))
}
# nocov end
result <- dplyr::as_tibble(jsonlite::fromJSON(json, flatten = TRUE))


Expand Down
2 changes: 0 additions & 2 deletions R/geo_address_lookup_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ geo_address_lookup_sf <- function(osm_ids,
# Keep a tbl with the query
tbl_query <- dplyr::tibble(query = paste0(type, osm_ids))

# nocov start
# If no response...
if (isFALSE(res)) {
message(url, " not reachable.")
out <- empty_sf(tbl_query)
return(invisible(out))
}
# nocov end

# Read
sfobj <- sf::read_sf(json, stringsAsFactors = FALSE)
Expand Down
Loading

0 comments on commit cdb0abf

Please sign in to comment.