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

Remove even more rgeos #209

Merged
merged 1 commit into from
Sep 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
106 changes: 0 additions & 106 deletions R/deprecated.R

This file was deleted.

48 changes: 0 additions & 48 deletions R/geojson_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
#'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
50 changes: 2 additions & 48 deletions R/geojson_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <some number>)` changes the maximum number of
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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, ...)
Expand Down
23 changes: 0 additions & 23 deletions R/topojson_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
#'
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions R/topojson_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 0 additions & 24 deletions R/topojson_write.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down