Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't convert OSM IDs to integer #48

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ message: 'To cite package "nominatimlite" in publications use:'
type: software
license: MIT
title: 'nominatimlite: Interface with ''Nominatim'' API Service'
version: 0.4.0
version: 0.4.0.9000
doi: 10.32614/CRAN.package.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
Expand All @@ -28,7 +28,7 @@ preferred-citation:
orcid: https://orcid.org/0000-0001-8457-4658
doi: 10.32614/CRAN.package.nominatimlite
year: '2024'
version: 0.4.0
version: 0.4.0.9000
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
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: nominatimlite
Title: Interface with 'Nominatim' API Service
Version: 0.4.0
Version: 0.4.0.9000
Authors@R: c(
person("Diego", "Hernangómez", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0001-8457-4658")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# nominatimlite (development version)

- Fix input validation in `geo_address_lookup()` and `geo_address_lookup_sf()`
that crashes the function if the OSM ID is too long (#47 reported by
\@lshydro).

# nominatimlite 0.4.0

- New functions:
Expand Down
3 changes: 2 additions & 1 deletion R/geo_address_lookup.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ geo_address_lookup <- function(osm_ids,
api <- prepare_api_url(nominatim_server, "lookup?")

# Prepare nodes
osm_ids <- as.integer(osm_ids)
osm_ids <- as.numeric(osm_ids)
osm_ids <- floor(abs(osm_ids))
type <- as.character(type)
nodes <- paste0(type, osm_ids, collapse = ",")

Expand Down
3 changes: 2 additions & 1 deletion R/geo_address_lookup_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ geo_address_lookup_sf <- function(osm_ids,
api <- prepare_api_url(nominatim_server, "lookup?")

# Prepare nodes
osm_ids <- as.integer(osm_ids)
osm_ids <- as.numeric(osm_ids)
osm_ids <- floor(abs(osm_ids))
type <- as.character(type)
nodes <- paste0(type, osm_ids, collapse = ",")

Expand Down
2 changes: 1 addition & 1 deletion R/geo_lite_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ geo_lite_sf <- function(address,
getrows <- dplyr::left_join(init_key, template, by = "query")

# Select rows
all_res <- all_res[as.integer(getrows$rindex), ]
all_res <- all_res[as.double(getrows$rindex), ]
all_res <- sf_to_tbl(all_res)
}

Expand Down
2 changes: 1 addition & 1 deletion R/reverse_geo_lite_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ reverse_geo_lite_sf <- function(lat,
))

# Select rows
all_res <- all_res[as.integer(getrows$rindex), ]
all_res <- all_res[as.double(getrows$rindex), ]
}

# Final cleanup
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,14 @@ A BibTeX entry for LaTeX users is
doi = {10.32614/CRAN.package.nominatimlite},
author = {Diego Hernangómez},
year = {2024},
version = {0.4.0},
version = {0.4.0.9000},
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

<div id="refs" class="references csl-bib-body hanging-indent"
entry-spacing="0">
<div id="refs" class="references csl-bib-body hanging-indent">

<div id="ref-R-tidygeocoder" class="csl-entry">

Expand Down
6 changes: 3 additions & 3 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"codeRepository": "https://github.com/dieghernan/nominatimlite",
"issueTracker": "https://github.com/dieghernan/nominatimlite/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.4.0",
"version": "0.4.0.9000",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.4.0 (2024-04-24 ucrt)",
"runtimePlatform": "R version 4.4.1 (2024-06-14)",
"provider": {
"@id": "https://cran.r-project.org",
"@type": "Organization",
Expand Down Expand Up @@ -220,7 +220,7 @@
},
"applicationCategory": "cartography",
"keywords": ["r", "geocoding", "openstreetmap", "address", "nominatim", "reverse-geocoding", "rstats", "shapefile", "r-package", "spatial", "cran", "api-wrapper", "api", "gis"],
"fileSize": "250.978KB",
"fileSize": "245.448KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand Down
Binary file modified data/osm_amenities.rda
Binary file not shown.
4 changes: 2 additions & 2 deletions inst/schemaorg.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"runtimePlatform": "R version 4.4.0 (2024-04-24 ucrt)",
"version": "0.4.0"
"runtimePlatform": "R version 4.4.1 (2024-06-14)",
"version": "0.4.0.9000"
},
{
"id": "https://doi.org/10.32614/CRAN.package.nominatimlite",
Expand Down
Binary file modified man/figures/README-line-object-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-pizzahut-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-statue_liberty-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions tests/testthat/test-geo_address_lookup.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,33 @@ test_that("Fail", {

expect_true(all(is.na(several[, 2:3])))
})


test_that("Integers #47", {
skip_on_cran()
skip_if_api_server()
skip_if_offline()


vector_ids <- "9743343761"

several <- geo_address_lookup(vector_ids)

# IDs should have the right string
comp <- unique(gsub("[^0-9]", "", several$query))

expect_identical(vector_ids, comp)


# With decimals
vector_ids2 <- 9743343761.34
several <- geo_address_lookup(vector_ids2)

expect_identical(vector_ids, comp)

# With negatives
vector_ids3 <- -1 * vector_ids2
several <- geo_address_lookup(vector_ids3)

expect_identical(vector_ids, comp)
})
30 changes: 30 additions & 0 deletions tests/testthat/test-geo_address_lookup_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,33 @@ test_that("Fail", {

expect_true(all(sf::st_is_empty(several)))
})


test_that("Integers #47", {
skip_on_cran()
skip_if_api_server()
skip_if_offline()


vector_ids <- "9743343761"

several <- geo_address_lookup_sf(vector_ids)

# IDs should have the right string
comp <- unique(gsub("[^0-9]", "", several$query))

expect_identical(vector_ids, comp)


# With decimals
vector_ids2 <- 9743343761.34
several <- geo_address_lookup_sf(vector_ids2)

expect_identical(vector_ids, comp)

# With negatives
vector_ids3 <- -1 * vector_ids2
several <- geo_address_lookup_sf(vector_ids3)

expect_identical(vector_ids, comp)
})
Loading
Loading