Giter VIP home page Giter VIP logo

nominatimlite's Introduction

nominatimlite

CRAN status CRAN results Downloads Nominatim-version R-CMD-check R-hub codecov r-universe CodeFactor Project Status: Active – The project has reached a stable, usable state and is being actively developed. DOI status

The goal of nominatimlite is to provide a light interface for geocoding addresses, based on the Nominatim API. It also allows to load spatial objects using the sf package.

Full site with examples and vignettes on https://dieghernan.github.io/nominatimlite/

What is Nominatim?

Nominatim is a tool to search OpenStreetMap data by name and address (geocoding) and to generate synthetic addresses of OSM points (reverse geocoding).

Why nominatimlite?

The main goal of nominatimlite is to access the Nominatim API avoiding the dependency on curl. In some situations, curl may not be available or accessible, so nominatimlite uses base functions to overcome this limitation.

Recommended packages

There are other packages much more complete and mature than nominatimlite, that presents similar features:

Installation

Install nominatimlite from CRAN:

install.packages("nominatimlite")

You can install the developing version of nominatimlite with:

remotes::install_github("dieghernan/nominatimlite")

Alternatively, you can install nominatimlite using the r-universe:

# Install nominatimlite in R:
install.packages("nominatimlite",
  repos = c(
    "https://dieghernan.r-universe.dev",
    "https://cloud.r-project.org"
  )
)

Usage

sf objects

With nominatimlite you can extract spatial objects easily:

library(nominatimlite)

# Extract some points - Pizza Hut in California

CA <- geo_lite_sf("California", points_only = FALSE)

pizzahut <- geo_lite_sf("Pizza Hut, California",
  limit = 50,
  custom_query = list(countrycodes = "us")
)

library(ggplot2)

ggplot(CA) +
  geom_sf() +
  geom_sf(data = pizzahut, col = "red")

You can also extract polygon and line objects (as provided by the Nominatim API) using the option points_only = FALSE:

sol_poly <- geo_lite_sf("Statue of Liberty, NY, USA", points_only = FALSE) # a building - a polygon

ggplot(sol_poly) +
  geom_sf()

dayton <- geo_lite_sf("Dayton, OH") # default - a point
ohio_state <- geo_lite_sf("Ohio, USA", points_only = FALSE) # a US state - a polygon
ohio_river <- geo_lite_sf("Ohio river", points_only = FALSE) # a river - a line

ggplot() +
  geom_sf(data = ohio_state) +
  geom_sf(data = dayton, color = "red", pch = 4) +
  geom_sf(data = ohio_river, color = "blue")

Geocoding and reverse geocoding

Note: examples adapted from tidygeocoder package

In this first example we will geocode a few addresses using the geo_lite() function:

library(tibble)

# create a dataframe with addresses
some_addresses <- tribble(
  ~name,                  ~addr,
  "White House",          "1600 Pennsylvania Ave NW, Washington, DC",
  "Transamerica Pyramid", "600 Montgomery St, San Francisco, CA 94111",
  "Willis Tower",         "233 S Wacker Dr, Chicago, IL 60606"
)

# geocode the addresses
lat_longs <- geo_lite(some_addresses$addr, lat = "latitude", long = "longitude")
#>   |                                                          |                                                  |   0%  |                                                          |=================                                 |  33%  |                                                          |=================================                 |  67%  |                                                          |==================================================| 100%

Only latitude and longitude are returned from the geocoder service in this example, but full_results = TRUE can be used to return all of the data from the geocoder service.

query latitude longitude address
1600 Pennsylvania Ave NW, Washington, DC 38.89770 -77.03655 White House, 1600, Pennsylvania Avenue Northwest, Ward 2, Washington, District of Columbia, 20500, United States
600 Montgomery St, San Francisco, CA 94111 37.79520 -122.40279 Transamerica Pyramid, 600, Montgomery Street, Financial District, San Francisco, California, 94111, United States
233 S Wacker Dr, Chicago, IL 60606 41.87874 -87.63596 Willis Tower, 233, South Wacker Drive, Printer’s Row, Loop, Chicago, Cook County, Illinois, 60606, United States

To perform reverse geocoding (obtaining addresses from geographic coordinates), we can use the reverse_geo_lite() function. The arguments are similar to the geo_lite() function, but now we specify the input data columns with the lat and long arguments. The dataset used here is from the geocoder query above. The single line address is returned in a column named by the address.

reverse <- reverse_geo_lite(
  lat = lat_longs$latitude, long = lat_longs$longitude,
  address = "address_found"
)
#>   |                                                          |                                                  |   0%  |                                                          |=================                                 |  33%  |                                                          |=================================                 |  67%  |                                                          |==================================================| 100%
address_found lat lon
Zastava Sjedinjenih Američkih Država, Pennsylvania Avenue Northwest, Ward 2, Washington, District of Columbia, 20006, United States 38.89772 -77.03655
Transamerica Pyramid, 600, Montgomery Street, Financial District, San Francisco, California, 94111, United States 37.79520 -122.40279
Willis Tower, 233, South Wacker Drive, Printer’s Row, Loop, Chicago, Cook County, Illinois, 60606, United States 41.87874 -87.63596

For more advance users, see Nominatim docs to check the parameters available.

Citation

Hernangómez D (2024). nominatimlite: Interface with Nominatim API Service. doi:10.32614/CRAN.package.nominatimlite, https://dieghernan.github.io/nominatimlite/.

A BibTeX entry for LaTeX users is

@Manual{R-nominatimlite,
  title = {{nominatimlite}: Interface with {Nominatim} {API} Service},
  doi = {10.32614/CRAN.package.nominatimlite},
  author = {Diego Hernangómez},
  year = {2024},
  version = {0.4.0},
  url = {https://dieghernan.github.io/nominatimlite/},
  abstract = {Lite interface for getting data from OSM service Nominatim <https://nominatim.org/release-docs/latest/>. Extract coordinates from addresses, find places near a set of coordinates and return spatial objects on sf format.},
}

References

Cambon, Jesse, Diego Hernangómez, Christopher Belanger, and Daniel Possenriede. 2021. “tidygeocoder: An R Package for Geocoding.” Journal of Open Source Software 6 (65): 3544. https://doi.org/10.21105/joss.03544.

Hernangómez, Diego. 2024. arcgeocoder: Geocoding with the ArcGIS REST API Service (version 0.1.0). https://doi.org/10.5281/zenodo.10495365.

Padgham, Mark, Robin Lovelace, Maëlle Salmon, and Bob Rudis. 2017. “osmdata.” Journal of Open Source Software 2 (14): 305. https://doi.org/10.21105/joss.00305.

nominatimlite's People

Contributors

actions-user avatar alexwhitedatamine avatar dependabot[bot] avatar dieghernan avatar github-actions[bot] avatar imgbot[bot] avatar imgbotapp avatar jlacko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nominatimlite's Issues

Release nominatimlite 0.2.1

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)

pkgcheck results - main

Checks for nominatimlite (v0.2.0)

git hash: d4da5b6b

  • ✔️ Package is already on CRAN.
  • ✔️ has a 'codemeta.json' file.
  • ✔️ has a 'contributing' file.
  • ✔️ uses 'roxygen2'.
  • ✔️ 'DESCRIPTION' has a URL field.
  • ✔️ 'DESCRIPTION' has a BugReports field.
  • ✔️ Package has at least one HTML vignette
  • ✔️ All functions have examples.
  • ✔️ Package has continuous integration checks.
  • ✖️ Package coverage is 21.7% (should be at least 75%).
  • ✔️ R CMD check found no errors.
  • ✔️ R CMD check found no warnings.

Important: All failing checks above must be addressed prior to proceeding

Package License: MIT + file LICENSE


1. Package Dependencies

Details of Package Dependency Usage (click to open)

The table below tallies all function calls to all packages ('ncalls'), both internal (r-base + recommended, along with the package itself), and external (imported and suggested packages). 'NA' values indicate packages to which no identified calls to R functions could be found. Note that these results are generated by an automated code-tagging system which may not be entirely accurate.

type package ncalls
internal base 133
internal nominatimlite 42
internal stats 6
imports dplyr 57
imports sf 20
imports jsonlite 18
imports utils 2
suggests ggplot2 NA
suggests knitr NA
suggests osmdata NA
suggests rmarkdown NA
suggests testthat NA
suggests tidygeocoder NA
linking_to NA NA

Click below for tallies of functions used in each package. Locations of each call within this package may be generated locally by running 's <- pkgstats::pkgstats(<path/to/repo>)', and examining the 'external_calls' table.

base

url (19), lapply (18), paste0 (18), by (13), tempfile (9), isFALSE (8), names (8), c (5), pmax (4), pmin (4), unique (4), as.character (3), as.double (3), class (2), gsub (2), list (2), nrow (2), seq_len (2), warning (2), length (1), numeric (1), setdiff (1), tryCatch (1), vapply (1)

dplyr

tibble (32), as_tibble (10), left_join (8), inner_join (4), distinct (2), bind_cols (1)

nominatimlite

api_call (10), empty_sf (7), keep_names (6), empty_tbl (5), bbox_to_poly (2), empty_tbl_rev (2), keep_names_rev (2), add_custom_query (1), geo_address_lookup (1), geo_address_lookup_sf (1), geo_amenity (1), geo_amenity_sf (1), reverse_geo_lite_sf_single (1), reverse_geo_lite_single (1), unnest_reverse (1)

sf

read_sf (8), st_as_sf (3), st_crs (3), st_drop_geometry (3), st_as_sfc (1), st_covered_by (1), st_make_valid (1)

jsonlite

fromJSON (18)

stats

df (6)

utils

download.file (2)


2. Statistical Properties

This package features some noteworthy statistical properties which may need to be clarified by a handling editor prior to progressing.

Details of statistical properties (click to open)

The package has:

  • code in R (100% in 13 files) and
  • 1 authors
  • 1 vignette
  • 1 internal data file
  • 4 imported packages
  • 11 exported functions (median 26 lines of code)
  • 47 non-exported functions in R (median 26 lines of code)

Statistical properties of package structure as distributional percentiles in relation to all current CRAN packages
The following terminology is used:

  • loc = "Lines of Code"
  • fn = "function"
  • exp/not_exp = exported / not exported

All parameters are explained as tooltips in the locally-rendered HTML version of this report generated by the checks_to_markdown() function

The final measure (fn_call_network_size) is the total number of calls between functions (in R), or more abstract relationships between code objects in other languages. Values are flagged as "noteworthy" when they lie in the upper or lower 5th percentile.

measure value percentile noteworthy
files_R 13 68.2
files_vignettes 1 68.4
files_tests 12 92.5
loc_R 822 62.6
loc_vignettes 93 23.2
loc_tests 1062 87.8
num_vignettes 1 64.8
data_size_total 1127 60.6
data_size_median 1127 64.9
n_fns_r 58 61.1
n_fns_r_exported 11 48.6
n_fns_r_not_exported 47 65.9
n_fns_per_file_r 3 46.1
num_params_per_fn 8 88.7
loc_per_fn_r 26 71.1
loc_per_fn_r_exp 26 57.4
loc_per_fn_r_not_exp 26 73.5
rel_whitespace_R 36 79.8
rel_whitespace_vignettes 53 38.1
rel_whitespace_tests 31 91.6
doclines_per_fn_exp 67 77.7
doclines_per_fn_not_exp 0 0.0 TRUE
fn_call_network_size 70 73.0

2a. Network visualisation

An interactive visualisation of calls between objects in the package has been uploaded as a workflow artefact. To view it, click on results from the latest 'pkgcheck' action, scroll to the bottom, and click on the 'visual-network' artefact.


3. goodpractice and other checks

Details of goodpractice checks (click to open)

3a. Continuous Integration Badges

check-full.yaml

GitHub Workflow Results

id name conclusion sha run_number date
5737963418 Clear all Github actions caches manually success d4da5b 5 2023-08-02
5737531422 CRAN Status Monitor success f40acb 72 2023-08-02
5737985563 lint success 58d235 279 2023-08-02
5737985545 lintr success 58d235 3 2023-08-02
5738021015 pages build and deployment success 30f3c8 88 2023-08-02
5737888202 pkgcheck NA d4da5b 1 2023-08-02
5737985541 pkgdown-gh-pages success 58d235 250 2023-08-02
5737985542 R-CMD-check NA 58d235 490 2023-08-02
5737985560 test-coverage success 58d235 279 2023-08-02
5737811040 update-docs success bc16d1 120 2023-08-02

3b. goodpractice results

R CMD check with rcmdcheck

rcmdcheck found no errors, warnings, or notes

Test coverage with covr

Package coverage: 21.75

The following files are not completely covered by tests:

file coverage
R/geo_address_lookup_sf.R 0%
R/geo_address_lookup.R 0%
R/geo_amenity_sf.R 55.38%
R/geo_amenity.R 54.55%
R/geo_lite_sf.R 0%
R/geo_lite.R 0%
R/reverse_geo_lite_sf.R 0%
R/reverse_geo_lite.R 0%
R/utils.R 26.53%

Cyclocomplexity with cyclocomp

No functions have cyclocomplexity >= 15

Static code analyses with lintr

lintr found no issues with this package!


Package Versions

package version
pkgstats 0.1.3.4
pkgcheck 0.1.2.1

Release nominatimlite 0.1.2

Prepare for release:

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()

Release nominatimlite 0.4.0

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • Finish & publish blog post
  • Add link to blog post in pkgdown news menu
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)
  • Tweet

Release nominatimlite 0.1.3

Prepare for release:

  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()

Release nominatimlite 0.1.4

Prepare for release:

  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()

Release nominatimlite 0.3.0

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • Polish NEWS
  • urlchecker::url_check()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • Finish & publish blog post
  • Add link to blog post in pkgdown news menu
  • usethis::use_github_release()
  • usethis::use_dev_version(push = TRUE)
  • Tweet

interpretation of polygon = TRUE in geo_lite_sf()

The "polygon" parameter of geo_lite_sf() is IMHO a killer feature. There is a slight catch though: while all OSM objects can be relied on having a point coordinate defined not all of them come as polygons / think of rivers and roads (lines) or amenities (mostly points only).

This is mentioned in passing in documentation ("or potentially other shapes as polygons or lines") but from this it may not be immediately obvious to users that the polygon is not guaranteed.

When you consider this code an user might - going by the name of the parameter only - expect geometry of type polygon. When in fact it is a linestring.

> geo_lite_sf("Gran Via, Madrid", polygon = T)
Simple feature collection with 1 feature and 2 fields
Geometry type: LINESTRING
Dimension:     XY
Bounding box:  xmin: -3.706446 ymin: 40.42041 xmax: -3.706174 ymax: 40.42059
Geodetic CRS:  WGS 84
             query
1 Gran Via, Madrid
                                                                                                                         address
1 Gran Vía, Universidad, Centro, Madrid, Área metropolitana de Madrid y Corredor del Henares, Comunidad de Madrid, 28001, España
                        geometry
1 LINESTRING (-3.706446 40.42...

It is certainly impractical to force the results to a certain geometry type.

But what may be considered is renaming the parameter - to e.g. points_only, defaulting to FALSE - to make the possibility of other geometry types feel more real.

I would be happy to prepare a pull request with the slight amendment of functionality described, but before I proceed I would appreciate your advice on its practicability / desirability.

Release nominatimlite 0.1.5

Prepare for release:

  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()

Local Nominatim server not supported

The package has the address https://nominatim.openstreetmap.org/ hardcoded in, which doesn't allow for the ability to connect to and query a local Nominatim instance.

I'm proposing a change to the following functions:

  • bbox_to_poly
  • geo_address_lookup
  • geo_address_lookup_sf
  • geo_lite
  • geo_lite_sf
  • reverse_geo_lite
  • reverse_geo_lite_sf

To add a keyword argument nominatim_server which allows the user to specify a custom URL to build the API requests from.

Release nominatimlite 0.1.6

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push

Release nominatimlite 0.2.0

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • git push
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Release nominatimlite 0.1.0

First release:

Prepare for release:

  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • Review pkgdown reference index for, e.g., missing topics
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted 🎉
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Update install instructions in README
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.