From 0c23d4a8dfdf0ddd9d62810983741bfb625089a1 Mon Sep 17 00:00:00 2001 From: Mike Mahoney Date: Tue, 5 Sep 2023 12:19:40 -0400 Subject: [PATCH] Remove even more rgeos --- NAMESPACE | 6 -- NEWS.md | 4 ++ R/deprecated.R | 106 --------------------------------- R/geojson_json.R | 48 --------------- R/geojson_list.R | 50 +--------------- R/topojson_json.R | 23 -------- R/topojson_list.R | 10 ---- R/topojson_write.R | 24 -------- R/zzz.r | 133 +++++++++++++++++++----------------------- man/defunct.Rd | 135 ------------------------------------------- man/geojson_json.Rd | 33 ----------- man/geojson_list.Rd | 19 +----- man/topojson_json.Rd | 23 -------- man/topojson_list.Rd | 10 ---- 14 files changed, 69 insertions(+), 555 deletions(-) delete mode 100644 R/deprecated.R delete mode 100644 man/defunct.Rd diff --git a/NAMESPACE b/NAMESPACE index 1149592..2e1a4aa 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,7 +20,6 @@ S3method(geojson_atomize,default) S3method(geojson_atomize,geo_json) S3method(geojson_atomize,geo_list) S3method(geojson_atomize,json) -S3method(geojson_json,SpatialCollections) S3method(geojson_json,SpatialGrid) S3method(geojson_json,SpatialGridDataFrame) S3method(geojson_json,SpatialLines) @@ -38,7 +37,6 @@ S3method(geojson_json,numeric) S3method(geojson_json,sf) S3method(geojson_json,sfc) S3method(geojson_json,sfg) -S3method(geojson_list,SpatialCollections) S3method(geojson_list,SpatialGrid) S3method(geojson_list,SpatialGridDataFrame) S3method(geojson_list,SpatialLines) @@ -71,7 +69,6 @@ S3method(geojson_sp,geo_list) S3method(geojson_sp,json) S3method(geojson_style,data.frame) S3method(geojson_style,list) -S3method(geojson_write,SpatialCollections) S3method(geojson_write,SpatialGrid) S3method(geojson_write,SpatialGridDataFrame) S3method(geojson_write,SpatialLines) @@ -82,8 +79,6 @@ S3method(geojson_write,SpatialPoints) S3method(geojson_write,SpatialPointsDataFrame) S3method(geojson_write,SpatialPolygons) S3method(geojson_write,SpatialPolygonsDataFrame) -S3method(geojson_write,SpatialRings) -S3method(geojson_write,SpatialRingsDataFrame) S3method(geojson_write,data.frame) S3method(geojson_write,geo_list) S3method(geojson_write,json) @@ -136,7 +131,6 @@ S3method(topo2geo,json) S3method(topojson_read,character) S3method(topojson_read,default) S3method(topojson_read,location_) -S3method(topojson_write,SpatialCollections) S3method(topojson_write,SpatialGrid) S3method(topojson_write,SpatialGridDataFrame) S3method(topojson_write,SpatialLines) diff --git a/NEWS.md b/NEWS.md index d5ba47f..18f0fc6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # geojsonio (development version) +* Removed an unused V8 call to geojsonhint + +* Removed all remaining references to rgeos + # geojsonio 0.11.2 * This is a tiny patch release with no user-facing changes. diff --git a/R/deprecated.R b/R/deprecated.R deleted file mode 100644 index 7b44737..0000000 --- a/R/deprecated.R +++ /dev/null @@ -1,106 +0,0 @@ -#' Deprecated functions from geojsonio -#' -#' `r lifecycle::badge("defunct")` -#' -#' Due to the retirement of rgeos and maptools in 2023, the following functions -#' are now defunct. They will be removed entirely in the future. -#' -#' At the moment, there is no replacement for these functions that uses the -#' newer geos package (or any alternative for maptools). If you'd be interested -#' in contributing replacements, please feel free to contribute a pull request! -#' -#' @inheritParams geojson_write -#' -#' @rdname defunct -#' @examples \dontrun{ -#' # From SpatialRings -#' library(rgeos) -#' r1 <- Ring(cbind(x = c(1, 1, 2, 2, 1), y = c(1, 2, 2, 1, 1)), ID = "1") -#' r2 <- Ring(cbind(x = c(1, 1, 2, 2, 1), y = c(1, 2, 2, 1, 1)), ID = "2") -#' r1r2 <- SpatialRings(list(r1, r2)) -#' geojson_write(r1r2) -#' -#' # From SpatialRingsDataFrame -#' dat <- data.frame(id = c(1, 2), value = 3:4) -#' r1r2df <- SpatialRingsDataFrame(r1r2, data = dat) -#' geojson_write(r1r2df) -#' -#' # From SpatialCollections -#' library("sp") -#' poly1 <- Polygons(list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1") -#' poly2 <- Polygons(list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2") -#' poly <- SpatialPolygons(list(poly1, poly2), 1:2) -#' coordinates(us_cities) <- ~ long + lat -#' dat <- SpatialCollections(points = us_cities, polygons = poly) -#' geojson_write(dat) -#' } -#' -#' @export -geojson_write.SpatialRings <- function(input, lat = NULL, lon = NULL, geometry = "point", - group = NULL, file = "myfile.geojson", - overwrite = TRUE, precision = NULL, - convert_wgs84 = FALSE, crs = NULL, ...) { - lifecycle::deprecate_stop( - "0.10.0", - "geojson_write.SpatialRings()", - details = "Due to the pending retirement of rgeos in 2023, please migrate any existing code away from using rgeos." - ) -} - -#' @rdname defunct -#' @export -geojson_write.SpatialRingsDataFrame <- function(input, lat = NULL, lon = NULL, geometry = "point", - group = NULL, file = "myfile.geojson", - overwrite = TRUE, precision = NULL, - convert_wgs84 = FALSE, crs = NULL, ...) { - lifecycle::deprecate_stop( - "0.10.0", - "geojson_write.SpatialRingsDataFrame()", - details = "Due to the pending retirement of rgeos in 2023, please migrate any existing code away from using rgeos." - ) -} - -#' @rdname defunct -#' @export -geojson_write.SpatialCollections <- function(input, lat = NULL, lon = NULL, - geometry = "point", - group = NULL, file = "myfile.geojson", - overwrite = TRUE, precision = NULL, - convert_wgs84 = FALSE, crs = NULL, ...) { - lifecycle::deprecate_stop( - "0.10.0", - "geojson_write.SpatialCollections()", - details = "Due to the pending retirement of rgeos in 2023, please migrate any existing code away from using rgeos." - ) -} - -## SpatialRings to SpatialPolygonsDataFrame -as_SpatialPolygonsDataFrame.SpatialRings <- function(from) { - - lifecycle::deprecate_stop( - "0.10.0", - "as.SpatialPolygonsDataFrame.SpatialRings()", - details = "Due to the pending retirement of rgeos in 2023, please migrate any existing code away from using rgeos." - ) -} - -setAs( - "SpatialRings", "SpatialPolygonsDataFrame", - as_SpatialPolygonsDataFrame.SpatialRings -) - - -## SpatialRingsDataFrame to SpatialPolygonsDataFrame -as_SpatialPolygonsDataFrame.SpatialRingsDataFrame <- function(from) { - - lifecycle::deprecate_stop( - "0.10.0", - "as.SpatialPolygonsDataFrame.SpatialRingsDataFrame()", - details = "Due to the pending retirement of rgeos in 2023, please migrate any existing code away from using rgeos." - ) -} - -setAs( - "SpatialRingsDataFrame", "SpatialPolygonsDataFrame", - as_SpatialPolygonsDataFrame.SpatialRingsDataFrame -) diff --git a/R/geojson_json.R b/R/geojson_json.R index e72d5f8..e5c6c2b 100644 --- a/R/geojson_json.R +++ b/R/geojson_json.R @@ -147,25 +147,6 @@ #' sp_poly <- SpatialPolygons(list(poly1, poly2), 1:2) #' geojson_json(sp_poly) #' -#' ## Another SpatialPolygons -#' library("sp") -#' library("rgeos") -#' pt <- SpatialPoints( -#' coordinates(list(x = 0, y = 0)), -#' CRS("+proj=longlat +datum=WGS84") -#' ) -#' ## transfrom to web mercator becuase geos needs project coords -#' crs <- gsub( -#' "\n", "", -#' paste0("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 -#' +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs", collapse = "") -#' ) -#' pt <- spTransform(pt, CRS(crs)) -#' ## buffer -#' pt <- gBuffer(pt, width = 100) -#' pt <- spTransform(pt, CRS("+proj=longlat +datum=WGS84")) -#' geojson_json(pt) -#' #' ## data.frame to geojson #' geojson_write(us_cities[1:2, ], lat = "lat", lon = "long") %>% as.json() #' @@ -233,20 +214,6 @@ #' ) #' geojson_json(pixelsdf) #' -#' # From SpatialCollections -#' library("sp") -#' library("rgeos") -#' pts <- SpatialPoints(cbind(c(1, 2, 3, 4, 5), c(3, 2, 5, 1, 4))) -#' poly1 <- Polygons( -#' list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1" -#' ) -#' poly2 <- Polygons( -#' list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2" -#' ) -#' poly <- SpatialPolygons(list(poly1, poly2), 1:2) -#' dat <- SpatialCollections(pts, polygons = poly) -#' geojson_json(dat) -#' #' # From sf classes: #' if (require(sf)) { #' ## sfg (a single simple features geometry) @@ -436,21 +403,6 @@ geojson_json.sfg <- function(input, lat = NULL, lon = NULL, group = NULL, geoclass(as.json(geojson_list(input, precision = precision), ...), type) } -#' @export -geojson_json.SpatialCollections <- function(input, lat = NULL, lon = NULL, - group = NULL, geometry = "point", type = "FeatureCollection", - convert_wgs84 = FALSE, crs = NULL, precision = NULL, ...) { - check_type_sp(type) - lapply( - geojson_rw(input, - target = "char", convert_wgs84 = convert_wgs84, crs = crs, - precision = precision, ... - ), - geoclass, - type = type - ) -} - # regular R classes -------------------------- #' @export geojson_json.numeric <- function(input, lat = NULL, lon = NULL, group = NULL, diff --git a/R/geojson_list.R b/R/geojson_list.R index c285f90..3600da2 100644 --- a/R/geojson_list.R +++ b/R/geojson_list.R @@ -14,7 +14,7 @@ #' @param group (character) A grouping variable to perform grouping for #' polygons - doesn't apply for points #' @param precision (integer) desired number of decimal places for coordinates. -#' Only used with classes from \pkg{sp}\pkg{rgeos} classes; ignored for other +#' Only used with classes from \pkg{sp} classes; ignored for other #' classes. Using fewer decimal places decreases object sizes (at the #' cost of precision). This changes the underlying precision stored in the #' data. `options(digits = )` changes the maximum number of @@ -208,22 +208,6 @@ #' ) #' geojson_list(pixelsdf) #' -#' # From SpatialCollections -#' library("sp") -#' poly1 <- Polygons( -#' list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1" -#' ) -#' poly2 <- Polygons( -#' list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2" -#' ) -#' poly <- SpatialPolygons(list(poly1, poly2), 1:2) -#' coordinates(us_cities) <- ~ long + lat -#' dat <- SpatialCollections(points = us_cities, polygons = poly) -#' out <- geojson_list(dat) -#' out$SpatialPoints -#' out$SpatialPolygons -#' } -#' #' # From sf classes: #' if (require(sf)) { #' ## sfg (a single simple features geometry) @@ -245,6 +229,7 @@ #' poly_sf <- st_sf(foo = c("a", "b"), bar = 1:2, poly_sfc) #' geojson_list(poly_sf) #' } +#' } #' geojson_list <- function(input, lat = NULL, lon = NULL, group = NULL, geometry = "point", type = "FeatureCollection", @@ -354,37 +339,6 @@ geojson_list.SpatialPixelsDataFrame <- function(input, lat = NULL, lon = NULL, ), "SpatialPixelsDataFrame") } -#' @export -geojson_list.SpatialCollections <- function(input, lat = NULL, lon = NULL, - group = NULL, geometry = "point", type = "FeatureCollection", - convert_wgs84 = FALSE, crs = NULL, precision = NULL, ...) { - pt <- donotnull(input@pointobj, geojson_rw, - target = "list", - convert_wgs84 = convert_wgs84, crs = crs, - precision = precision - ) - ln <- donotnull(input@lineobj, geojson_rw, - target = "list", - convert_wgs84 = convert_wgs84, crs = crs, - precision = precision - ) - rg <- donotnull(input@ringobj, geojson_rw, - target = "list", - convert_wgs84 = convert_wgs84, crs = crs, - precision = precision - ) - py <- donotnull(input@polyobj, geojson_rw, - target = "list", - convert_wgs84 = convert_wgs84, crs = crs, - precision = precision - ) - alldat <- tg_compact(list( - SpatialPoints = pt, SpatialLines = ln, - SpatialRings = rg, SpatialPolygons = py - )) - as.geo_list(alldat, "SpatialCollections") -} - donotnull <- function(x, fun, ...) { if (!is.null(x)) { fun(x, ...) diff --git a/R/topojson_json.R b/R/topojson_json.R index cce1a29..9d9eb6d 100644 --- a/R/topojson_json.R +++ b/R/topojson_json.R @@ -69,19 +69,6 @@ #' topojson_json(sp_poly) #' topojson_json(sp_poly, pretty = TRUE) #' -#' ## Another SpatialPolygons -#' library("sp") -#' library("rgeos") -#' pt <- SpatialPoints(coordinates(list(x = 0, y = 0)), CRS("+proj=longlat +datum=WGS84")) -#' ## transfrom to web mercator becuase geos needs project coords -#' crs <- gsub("\n", "", paste0("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 -#' +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs", collapse = "")) -#' pt <- spTransform(pt, CRS(crs)) -#' ## buffer -#' pt <- gBuffer(pt, width = 100) -#' pt <- spTransform(pt, CRS("+proj=longlat +datum=WGS84")) -#' topojson_json(pt) -#' #' ## data.frame to geojson #' geojson_write(us_cities[1:2, ], lat = "lat", lon = "long") %>% as.json() #' @@ -144,16 +131,6 @@ #' ) #' topojson_json(pixelsdf) #' -#' # From SpatialCollections -#' library("sp") -#' library("rgeos") -#' pts <- SpatialPoints(cbind(c(1, 2, 3, 4, 5), c(3, 2, 5, 1, 4))) -#' poly1 <- Polygons(list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1") -#' poly2 <- Polygons(list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2") -#' poly <- SpatialPolygons(list(poly1, poly2), 1:2) -#' dat <- SpatialCollections(pts, polygons = poly) -#' topojson_json(dat) -#' #' # From sf classes: #' if (require(sf)) { #' ## sfg (a single simple features geometry) diff --git a/R/topojson_list.R b/R/topojson_list.R index 48275ac..23b0aa2 100644 --- a/R/topojson_list.R +++ b/R/topojson_list.R @@ -121,16 +121,6 @@ #' ) #' topojson_list(pixelsdf) #' -#' # From SpatialCollections -#' library("sp") -#' poly1 <- Polygons(list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1") -#' poly2 <- Polygons(list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2") -#' poly <- SpatialPolygons(list(poly1, poly2), 1:2) -#' coordinates(us_cities) <- ~ long + lat -#' dat <- SpatialCollections(points = us_cities, polygons = poly) -#' out <- topojson_list(dat) -#' out[[1]] -#' out[[2]] #' } #' #' # From sf classes: diff --git a/R/topojson_write.R b/R/topojson_write.R index 3a428d9..422e0f3 100644 --- a/R/topojson_write.R +++ b/R/topojson_write.R @@ -178,30 +178,6 @@ topojson_write.SpatialPixelsDataFrame <- function(input, lat = NULL, lon = NULL, ) } -#' @export -topojson_write.SpatialCollections <- function(input, lat = NULL, lon = NULL, - geometry = "point", group = NULL, file = "myfile.topojson", overwrite = TRUE, - precision = NULL, convert_wgs84 = FALSE, crs = NULL, object_name = "foo", quantization = 0, ...) { - tmp <- suppressMessages( - geojson_write( - input, lat, lon, geometry, group, - sub("\\.topojson|\\.json", "\\.geojson", file), - overwrite, precision, convert_wgs84, crs, ... - ) - ) - structure(lapply(tmp, function(z) { - on.exit(unlink(z$path), add = TRUE) - if (!is.null(z)) { - topo_file( - write_topojson( - geo2topo(paste0(readLines(z$path), collapse = ""), object_name, quantization), - sub("\\.geojson|\\.json", "\\.topojson", z$path) - ), - z$type - ) - } - }), class = "spatialcoll") -} ## normal R classes ----------------- #' @export diff --git a/R/zzz.r b/R/zzz.r index 906f760..f8a8de4 100644 --- a/R/zzz.r +++ b/R/zzz.r @@ -11,8 +11,8 @@ to_json <- function(x, precision = 7, ...) { } if (is.null(precision)) precision <- 7 structure(jsonlite::toJSON(x, ..., - digits = precision, auto_unbox = TRUE, - force = TRUE + digits = precision, auto_unbox = TRUE, + force = TRUE ), class = c("json", "geo_json")) } @@ -22,17 +22,17 @@ class_json <- function(x, ..., type = "FeatureCollection") { geoclass <- function(x, type = "FeatureCollection") { res <- switch(type, - "auto" = geojson::to_geojson(unclass(x)), - "Point" = geojson::point(unclass(x)), - "LineString" = geojson::linestring(unclass(x)), - "Polygon" = geojson::polygon(unclass(x)), - "MultiPoint" = geojson::multipoint(unclass(x)), - "MultiLineString" = geojson::multilinestring(unclass(x)), - "MultiPolygon" = geojson::multipolygon(unclass(x)), - "Feature" = geojson::feature(unclass(x)), - "FeatureCollection" = geojson::featurecollection(unclass(x)), - "GeometryCollection" = geojson::geometrycollection(unclass(x)), - "skip" = unclass(x) + "auto" = geojson::to_geojson(unclass(x)), + "Point" = geojson::point(unclass(x)), + "LineString" = geojson::linestring(unclass(x)), + "Polygon" = geojson::polygon(unclass(x)), + "MultiPoint" = geojson::multipoint(unclass(x)), + "MultiLineString" = geojson::multilinestring(unclass(x)), + "MultiPolygon" = geojson::multipolygon(unclass(x)), + "Feature" = geojson::feature(unclass(x)), + "FeatureCollection" = geojson::featurecollection(unclass(x)), + "GeometryCollection" = geojson::geometrycollection(unclass(x)), + "skip" = unclass(x) ) class(res) <- c(class(res), c("geo_json", "json")) return(res) @@ -40,8 +40,8 @@ geoclass <- function(x, type = "FeatureCollection") { list_to_geo_list <- function(x, lat, lon, geometry = "point", type = "FeatureCollection", unnamed = FALSE, group = NULL) { nn <- switch(type, - FeatureCollection = "features", - GeometryCollection = "geometries" + FeatureCollection = "features", + GeometryCollection = "geometries" ) geom <- capwords(match.arg(geometry, c("point", "polygon"))) if (geom == "Point") { @@ -136,34 +136,34 @@ num_to_geo_list <- function(x, geometry = "point", type = "FeatureCollection") { stop("Coordinates are not numeric", call. = FALSE) } else { switch(type, - FeatureCollection = { - list( - type = "FeatureCollection", - features = list( - list( - type = "Feature", - geometry = list(type = geom, coordinates = makecoords(x, geom)), - properties = NULL - ) - ) - ) - }, - GeometryCollection = { - list( - type = "GeometryCollection", - geometries = list( - list(type = geom, coordinates = makecoords(x, geom)) - ) - ) - } + FeatureCollection = { + list( + type = "FeatureCollection", + features = list( + list( + type = "Feature", + geometry = list(type = geom, coordinates = makecoords(x, geom)), + properties = NULL + ) + ) + ) + }, + GeometryCollection = { + list( + type = "GeometryCollection", + geometries = list( + list(type = geom, coordinates = makecoords(x, geom)) + ) + ) + } ) } } makecoords <- function(x, y) { switch(y, - Point = x, - Polygon = list(unname(split(x, ceiling(seq_along(x) / 2)))) + Point = x, + Polygon = list(unname(split(x, ceiling(seq_along(x) / 2)))) ) } @@ -237,8 +237,8 @@ sppolytogeolist <- function(x) { lines_to_geo_list <- function(x, object = "FeatureCollection") { nn <- switch(object, - FeatureCollection = "features", - GeometryCollection = "geometries" + FeatureCollection = "features", + GeometryCollection = "geometries" ) if (length(x@lines) == 1) { list( @@ -345,7 +345,7 @@ write_geojson <- function(input, file = "myfile.geojson", precision = NULL, temp <- tempfile() on.exit(unlink(temp)) write_ogr_sf(input, file, precision, overwrite, - convert_wgs84 = convert_wgs84, crs = crs, ... + convert_wgs84 = convert_wgs84, crs = crs, ... ) } @@ -363,8 +363,8 @@ write_ogr_sf <- function(input, file, precision = NULL, overwrite, layer_options <- paste0("COORDINATE_PRECISION=", precision) } sf::st_write(input_sf, file, - layer_options = layer_options, quiet = TRUE, - delete_dsn = overwrite, ... + layer_options = layer_options, quiet = TRUE, + delete_dsn = overwrite, ... ) message("Success! File is at ", file) } @@ -385,28 +385,17 @@ geojson_rw <- function(input, target = c("char", "list"), convert_wgs84 = FALSE, crs = NULL, precision = NULL, ...) { read_fun <- switch(target, - char = geojson_file_to_char, - list = geojson_file_to_list + char = geojson_file_to_char, + list = geojson_file_to_list ) - - if (inherits(input, "SpatialCollections")) { - tmp <- tempfile(fileext = ".geojson") - on.exit(unlink(tmp)) - tmp2 <- suppressMessages(geojson_write(input, - file = tmp, precision = precision, - convert_wgs84 = convert_wgs84, crs = crs - )) - paths <- vapply(tg_compact(tmp2), "[[", "", "path") - lapply(paths, read_fun, ...) - } else { - tmp <- tempfile(fileext = ".geojson") - on.exit(unlink(tmp)) - suppressMessages(geojson_write(input, - file = tmp, precision = precision, - convert_wgs84 = convert_wgs84, crs = crs - )) - read_fun(tmp, ...) - } + + tmp <- tempfile(fileext = ".geojson") + on.exit(unlink(tmp)) + suppressMessages(geojson_write(input, + file = tmp, precision = precision, + convert_wgs84 = convert_wgs84, crs = crs + )) + read_fun(tmp, ...) } geojson_file_to_char <- function(file, ...) { @@ -420,12 +409,12 @@ geojson_file_to_list <- function(file, ...) { capwords <- function(s, strict = FALSE, onlyfirst = FALSE) { cap <- function(s) { paste(toupper(substring(s, 1, 1)), - { - s <- substring(s, 2) - if (strict) tolower(s) else s - }, - sep = "", - collapse = " " + { + s <- substring(s, 2) + if (strict) tolower(s) else s + }, + sep = "", + collapse = " " ) } if (!onlyfirst) { @@ -433,8 +422,8 @@ capwords <- function(s, strict = FALSE, onlyfirst = FALSE) { } else { sapply(s, function(x) { paste(toupper(substring(x, 1, 1)), - tolower(substring(x, 2)), - sep = "", collapse = " " + tolower(substring(x, 2)), + sep = "", collapse = " " ) }, USE.NAMES = FALSE) } @@ -454,7 +443,7 @@ guess_latlon <- function(x, lat = NULL, lon = NULL) { if (is.null(lat) && is.null(lon)) { lats <- x[grep("^(lat|latitude)$", x, ignore.case = TRUE)] lngs <- x[grep("^(lon|lng|long|longitude)$", x, ignore.case = TRUE)] - + if (length(lats) == 1 && length(lngs) == 1) { if (length(x) > 2) { message( diff --git a/man/defunct.Rd b/man/defunct.Rd deleted file mode 100644 index 0f38cf1..0000000 --- a/man/defunct.Rd +++ /dev/null @@ -1,135 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/deprecated.R -\name{geojson_write.SpatialRings} -\alias{geojson_write.SpatialRings} -\alias{geojson_write.SpatialRingsDataFrame} -\alias{geojson_write.SpatialCollections} -\title{Deprecated functions from geojsonio} -\usage{ -\method{geojson_write}{SpatialRings}( - input, - lat = NULL, - lon = NULL, - geometry = "point", - group = NULL, - file = "myfile.geojson", - overwrite = TRUE, - precision = NULL, - convert_wgs84 = FALSE, - crs = NULL, - ... -) - -\method{geojson_write}{SpatialRingsDataFrame}( - input, - lat = NULL, - lon = NULL, - geometry = "point", - group = NULL, - file = "myfile.geojson", - overwrite = TRUE, - precision = NULL, - convert_wgs84 = FALSE, - crs = NULL, - ... -) - -\method{geojson_write}{SpatialCollections}( - input, - lat = NULL, - lon = NULL, - geometry = "point", - group = NULL, - file = "myfile.geojson", - overwrite = TRUE, - precision = NULL, - convert_wgs84 = FALSE, - crs = NULL, - ... -) -} -\arguments{ -\item{input}{Input list, data.frame, spatial class, or sf class. -Inputs can also be dplyr \code{tbl_df} class since it inherits -from \code{data.frame}} - -\item{lat}{(character) Latitude name. The default is \code{NULL}, and we -attempt to guess.} - -\item{lon}{(character) Longitude name. The default is \code{NULL}, and we -attempt to guess.} - -\item{geometry}{(character) One of point (Default) or polygon.} - -\item{group}{(character) A grouping variable to perform grouping for -polygons - doesn't apply for points} - -\item{file}{(character) A path and file name (e.g., myfile), with the -\code{.geojson} file extension. Default writes to current working -directory.} - -\item{overwrite}{(logical) Overwrite the file given in \code{file} with -\code{input}. Default: \code{TRUE}. If this param is \code{FALSE} and -the file already exists, we stop with error message.} - -\item{precision}{desired number of decimal places for the coordinates in the -geojson file. Using fewer decimal places can decrease file sizes (at the -cost of precision).} - -\item{convert_wgs84}{Should the input be converted to the -standard CRS for GeoJSON (https://tools.ietf.org/html/rfc7946) -(geographic coordinate reference -system, using the WGS84 datum, with longitude and latitude units of decimal -degrees; EPSG: 4326). Default is \code{FALSE} though this may change in a -future package version. This will only work for \code{sf} or \code{Spatial} -objects with a CRS already defined. If one is not defined but you know what -it is, you may define it in the \code{crs} argument below.} - -\item{crs}{The CRS of the input if it is not already defined. This can be -an epsg code as a four or five digit integer or a valid proj4 string. This -argument will be ignored if \code{convert_wgs84} is \code{FALSE} or the -object already has a CRS.} - -\item{...}{Further args passed on to internal functions. For Spatial* -classes, data.frames, -regular lists, and numerics, it is passed through to -\code{\link[sf:st_write]{sf::st_write()}}. For sf classes, -geo_lists and json classes, it is passed through to -\code{\link[jsonlite:fromJSON]{jsonlite::toJSON()}}.} -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#defunct}{\figure{lifecycle-defunct.svg}{options: alt='[Defunct]'}}}{\strong{[Defunct]}} -} -\details{ -Due to the retirement of rgeos and maptools in 2023, the following functions -are now defunct. They will be removed entirely in the future. - -At the moment, there is no replacement for these functions that uses the -newer geos package (or any alternative for maptools). If you'd be interested -in contributing replacements, please feel free to contribute a pull request! -} -\examples{ -\dontrun{ -# From SpatialRings -library(rgeos) -r1 <- Ring(cbind(x = c(1, 1, 2, 2, 1), y = c(1, 2, 2, 1, 1)), ID = "1") -r2 <- Ring(cbind(x = c(1, 1, 2, 2, 1), y = c(1, 2, 2, 1, 1)), ID = "2") -r1r2 <- SpatialRings(list(r1, r2)) -geojson_write(r1r2) - -# From SpatialRingsDataFrame -dat <- data.frame(id = c(1, 2), value = 3:4) -r1r2df <- SpatialRingsDataFrame(r1r2, data = dat) -geojson_write(r1r2df) - -# From SpatialCollections -library("sp") -poly1 <- Polygons(list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1") -poly2 <- Polygons(list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2") -poly <- SpatialPolygons(list(poly1, poly2), 1:2) -coordinates(us_cities) <- ~ long + lat -dat <- SpatialCollections(points = us_cities, polygons = poly) -geojson_write(dat) -} - -} diff --git a/man/geojson_json.Rd b/man/geojson_json.Rd index ece76ca..84e14ce 100644 --- a/man/geojson_json.Rd +++ b/man/geojson_json.Rd @@ -181,25 +181,6 @@ poly2 <- Polygons(list(Polygon(cbind( sp_poly <- SpatialPolygons(list(poly1, poly2), 1:2) geojson_json(sp_poly) -## Another SpatialPolygons -library("sp") -library("rgeos") -pt <- SpatialPoints( - coordinates(list(x = 0, y = 0)), - CRS("+proj=longlat +datum=WGS84") -) -## transfrom to web mercator becuase geos needs project coords -crs <- gsub( - "\n", "", - paste0("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 - +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs", collapse = "") -) -pt <- spTransform(pt, CRS(crs)) -## buffer -pt <- gBuffer(pt, width = 100) -pt <- spTransform(pt, CRS("+proj=longlat +datum=WGS84")) -geojson_json(pt) - ## data.frame to geojson geojson_write(us_cities[1:2, ], lat = "lat", lon = "long") \%>\% as.json() @@ -267,20 +248,6 @@ pixelsdf <- suppressWarnings( ) geojson_json(pixelsdf) -# From SpatialCollections -library("sp") -library("rgeos") -pts <- SpatialPoints(cbind(c(1, 2, 3, 4, 5), c(3, 2, 5, 1, 4))) -poly1 <- Polygons( - list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1" -) -poly2 <- Polygons( - list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2" -) -poly <- SpatialPolygons(list(poly1, poly2), 1:2) -dat <- SpatialCollections(pts, polygons = poly) -geojson_json(dat) - # From sf classes: if (require(sf)) { ## sfg (a single simple features geometry) diff --git a/man/geojson_list.Rd b/man/geojson_list.Rd index 63b3861..67cf47e 100644 --- a/man/geojson_list.Rd +++ b/man/geojson_list.Rd @@ -50,7 +50,7 @@ This argument will be ignored if \code{convert_wgs84} is \code{FALSE} or the object already has a CRS.} \item{precision}{(integer) desired number of decimal places for coordinates. -Only used with classes from \pkg{sp}\pkg{rgeos} classes; ignored for other +Only used with classes from \pkg{sp} classes; ignored for other classes. Using fewer decimal places decreases object sizes (at the cost of precision). This changes the underlying precision stored in the data. \verb{options(digits = )} changes the maximum number of @@ -238,22 +238,6 @@ pixelsdf <- suppressWarnings( ) geojson_list(pixelsdf) -# From SpatialCollections -library("sp") -poly1 <- Polygons( - list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1" -) -poly2 <- Polygons( - list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2" -) -poly <- SpatialPolygons(list(poly1, poly2), 1:2) -coordinates(us_cities) <- ~ long + lat -dat <- SpatialCollections(points = us_cities, polygons = poly) -out <- geojson_list(dat) -out$SpatialPoints -out$SpatialPolygons -} - # From sf classes: if (require(sf)) { ## sfg (a single simple features geometry) @@ -275,5 +259,6 @@ if (require(sf)) { poly_sf <- st_sf(foo = c("a", "b"), bar = 1:2, poly_sfc) geojson_list(poly_sf) } +} } diff --git a/man/topojson_json.Rd b/man/topojson_json.Rd index 92f23e3..33a34a0 100644 --- a/man/topojson_json.Rd +++ b/man/topojson_json.Rd @@ -140,19 +140,6 @@ sp_poly <- SpatialPolygons(list(poly1, poly2), 1:2) topojson_json(sp_poly) topojson_json(sp_poly, pretty = TRUE) -## Another SpatialPolygons -library("sp") -library("rgeos") -pt <- SpatialPoints(coordinates(list(x = 0, y = 0)), CRS("+proj=longlat +datum=WGS84")) -## transfrom to web mercator becuase geos needs project coords -crs <- gsub("\n", "", paste0("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 - +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs", collapse = "")) -pt <- spTransform(pt, CRS(crs)) -## buffer -pt <- gBuffer(pt, width = 100) -pt <- spTransform(pt, CRS("+proj=longlat +datum=WGS84")) -topojson_json(pt) - ## data.frame to geojson geojson_write(us_cities[1:2, ], lat = "lat", lon = "long") \%>\% as.json() @@ -215,16 +202,6 @@ pixelsdf <- suppressWarnings( ) topojson_json(pixelsdf) -# From SpatialCollections -library("sp") -library("rgeos") -pts <- SpatialPoints(cbind(c(1, 2, 3, 4, 5), c(3, 2, 5, 1, 4))) -poly1 <- Polygons(list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1") -poly2 <- Polygons(list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2") -poly <- SpatialPolygons(list(poly1, poly2), 1:2) -dat <- SpatialCollections(pts, polygons = poly) -topojson_json(dat) - # From sf classes: if (require(sf)) { ## sfg (a single simple features geometry) diff --git a/man/topojson_list.Rd b/man/topojson_list.Rd index ce2ca9f..ddacd8d 100644 --- a/man/topojson_list.Rd +++ b/man/topojson_list.Rd @@ -187,16 +187,6 @@ pixelsdf <- suppressWarnings( ) topojson_list(pixelsdf) -# From SpatialCollections -library("sp") -poly1 <- Polygons(list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1") -poly2 <- Polygons(list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2") -poly <- SpatialPolygons(list(poly1, poly2), 1:2) -coordinates(us_cities) <- ~ long + lat -dat <- SpatialCollections(points = us_cities, polygons = poly) -out <- topojson_list(dat) -out[[1]] -out[[2]] } # From sf classes: