diff --git a/DESCRIPTION b/DESCRIPTION index 07c503ae..d8ed08c3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: osmdata Title: Import 'OpenStreetMap' Data as Simple Features or Spatial Objects -Version: 0.1.8.010 +Version: 0.1.8.011 Authors@R: c( person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")), person("Bob", "Rudis", role = "aut"), @@ -37,6 +37,7 @@ Imports: magrittr, methods, Rcpp (>= 0.12.4), + reproj, rvest, sp, tibble, diff --git a/NEWS.md b/NEWS.md index bc5e14bc..ba86d06d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,11 @@ Major changes: *around* a defined location; thanks to @barryrowlingson via #199 and @maellecoursonnais via #238 +Minor changes: + +- New dependency on `reproj` package, so that `trim_osmdata()` can be applied + to re-projected coordinates. + 0.1.8 =================== diff --git a/R/trim-osmdata.R b/R/trim-osmdata.R index 1a575ff0..075b2227 100644 --- a/R/trim-osmdata.R +++ b/R/trim-osmdata.R @@ -63,6 +63,10 @@ trim_osmdata_sfp <- function (dat, bb_poly, exclude = TRUE) { if (nrow (bb_poly) > 1) { + srcproj <- .lonlat() #"+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" + crs <- .sph_merc() # "+proj=merc +a=6378137 +b=6378137" + bb_poly <- reproj::reproj (bb_poly, target = crs, source = srcproj) [, 1:2] + dat <- trim_to_poly_pts (dat, bb_poly, exclude = exclude) %>% trim_to_poly (bb_poly = bb_poly, exclude = exclude) %>% trim_to_poly_multi (bb_poly = bb_poly, exclude = exclude) @@ -132,7 +136,11 @@ trim_to_poly_pts <- function (dat, bb_poly, exclude = TRUE) { if (is (dat$osm_points, "sf")) { + srcproj <- .lonlat() #"+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" + crs <- .sph_merc() # "+proj=merc +a=6378137 +b=6378137" + g <- do.call (rbind, dat$osm_points$geometry) + g <- reproj::reproj (g, target = crs, source = srcproj) indx <- sp::point.in.polygon (g [, 1], g [, 2], bb_poly [, 1], bb_poly [, 2]) if (exclude) @@ -160,10 +168,14 @@ trim_to_poly_pts <- function (dat, bb_poly, exclude = TRUE) { #' @noRd get_trim_indx <- function (g, bb, exclude) { + srcproj <- .lonlat() #"+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" + crs <- .sph_merc() # "+proj=merc +a=6378137 +b=6378137" + indx <- lapply (g, function (i) { if (is.list (i)) # polygons i <- i [[1]] + i <- reproj::reproj (as.matrix (i), target = crs, source = srcproj) inp <- sp::point.in.polygon (i [, 1], i [, 2], bb [, 1], bb [, 2]) if ((exclude & all (inp > 0)) | diff --git a/codemeta.json b/codemeta.json index 80ac205f..c974c627 100644 --- a/codemeta.json +++ b/codemeta.json @@ -10,13 +10,13 @@ "codeRepository": "https://github.com/ropensci/osmdata/", "issueTracker": "https://github.com/ropensci/osmdata/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.1.8.010", + "version": "0.1.8.11", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", "url": "https://r-project.org" }, - "runtimePlatform": "R version 4.1.1 (2021-08-10)", + "runtimePlatform": "R version 4.1.2 (2021-11-01)", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -272,6 +272,18 @@ }, "sameAs": "https://CRAN.R-project.org/package=Rcpp" }, + { + "@type": "SoftwareApplication", + "identifier": "reproj", + "name": "reproj", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=reproj" + }, { "@type": "SoftwareApplication", "identifier": "rvest", @@ -332,28 +344,12 @@ ], "applicationCategory": "DataAccess", "isPartOf": "https://ropensci.org", - "keywords": [ - "open0street0map", - "openstreetmap", - "overpass0API", - "OSM", - "overpass-api", - "r", - "cpp", - "rstats", - "osm", - "osm-data", - "r-package", - "peer-reviewed" - ], - "contIntegration": [ - "https://github.com/ropensci/osmdata/actions?query=workflow%3AR-CMD-check", - "https://codecov.io/gh/ropensci/osmdata" - ], + "keywords": ["open0street0map", "openstreetmap", "overpass0API", "OSM", "overpass-api", "r", "cpp", "rstats", "osm", "osm-data", "r-package", "peer-reviewed"], + "contIntegration": ["https://github.com/ropensci/osmdata/actions?query=workflow%3AR-CMD-check", "https://codecov.io/gh/ropensci/osmdata"], "developmentStatus": "https://www.repostatus.org/#active", "releaseNotes": "https://github.com/ropensci/osmdata/blob/master/NEWS.md", "readme": "https://github.com/ropensci/osmdata/blob/main/README.md", - "fileSize": "7782.91KB", + "fileSize": "7784.406KB", "citation": [ { "@type": "ScholarlyArticle", @@ -390,10 +386,7 @@ "issueNumber": "14", "datePublished": "2017", "isPartOf": { - "@type": [ - "PublicationVolume", - "Periodical" - ], + "@type": ["PublicationVolume", "Periodical"], "volumeNumber": "2", "name": "The Journal of Open Source Software" } diff --git a/tests/testthat/test-trim.R b/tests/testthat/test-trim.R index 9eb5d909..4a46d1dd 100644 --- a/tests/testthat/test-trim.R +++ b/tests/testthat/test-trim.R @@ -37,12 +37,12 @@ test_that ("trim_osm_data", { expect_equal (nrow (x1$edge), 0) expect_equal (nrow (x1$vertex), 0) - bb <- list (cbind (c (0, 0), + bb <- list (rbind (c (0, 0), c (0, 1), c (1, 1), c (1, 0), c (0, 0)), - cbind (c (2, 3), + rbind (c (2, 3), c (2, 4), c (3, 4), c (3, 3),