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

sp_2.0-0 draft changing to status 2L #135

Merged
merged 6 commits into from
Jun 20, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: sp
Version: 1.6-1
Version: 2.0-0
Title: Classes and Methods for Spatial Data
Authors@R: c(person("Edzer", "Pebesma", role = c("aut", "cre"),
email = "[email protected]"),
Expand All @@ -21,7 +21,11 @@ Description: Classes and methods for spatial
data; the classes document where the spatial location information
resides, for 2D or 3D data. Utility functions are provided, e.g. for
plotting data as maps, spatial selection, as well as methods for
retrieving coordinates, for subsetting, print, summary, etc.
retrieving coordinates, for subsetting, print, summary, etc. From this
version, evolution status is set to '2L' using 'sf' in place of 'rgdal',
see <https://r-spatial.org/r/2023/05/15/evolution4.html> for details.
Retiring packages 'maptools', 'rgdal' and 'rgeos' will be dropped by
October 2023.
License: GPL (>= 2)
URL: https://github.com/edzer/sp/ https://edzer.github.io/sp/
BugReports: https://github.com/edzer/sp/issues
Expand Down
32 changes: 30 additions & 2 deletions R/AAA.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@ assign("PolypathRule", "winding", envir = .spOptions)
assign("col.regions", bpy.colors(), envir = .spOptions)
assign("thin_PROJ6_warnings", FALSE, envir=.spOptions)
assign("PROJ6_warnings_count", 0L, envir=.spOptions)
assign("evolution_status", 0L, envir=.spOptions)
assign("evolution_status", 2L, envir=.spOptions) # default changed 2.0-0
assign("startup_message", "load", envir=.spOptions)

#.sp_CRS_cache <- new.env(FALSE, globalenv())
#assign("CRS_CACHE", list(), envir=.sp_CRS_cache)
.sp_CRS_cache <- new.env(hash=TRUE, globalenv())

.onLoad <- function(lib, pkg) {
load_stuff()
if (get("startup_message", envir=.spOptions) == "load")
smess_func()
}

.onAttach <- function(lib, pkg) {
if (get("startup_message", envir=.spOptions) == "attach")
smess_func()
}


load_stuff <- function() {
rgdal_show_exportToProj4_warnings <- options("rgdal_show_exportToProj4_warnings")
if (!is.null(rgdal_show_exportToProj4_warnings)) {
Expand Down Expand Up @@ -54,7 +63,26 @@ load_stuff <- function() {
assign("evolution_status", unname(evolution_status), envir=.spOptions)
}
}
Smess <- paste("The legacy packages maptools, rgdal, and rgeos, underpinning this package\nwill retire shortly. Please refer to R-spatial evolution reports on\nhttps://r-spatial.org/r/2023/05/15/evolution4.html for details.\nThis package is now running under evolution status", get_evolution_status(), "\n")
startup_message <- unlist(options("sp_startup_message"))
if (!is.null(startup_message)) {
startup_message <- as.character(startup_message)
stopifnot(is.character(startup_message))
stopifnot(isTRUE(startup_message %in% c("attach", "load", "none")))
assign("startup_message", unname(startup_message), envir=.spOptions)
} else {
startup_message <- Sys.getenv("_SP_STARTUP_MESSAGE_")
if (nchar(startup_message) > 0L) {
startup_message <- as.character(startup_message)
stopifnot(is.character(startup_message))
stopifnot(isTRUE(startup_message %in% c("attach", "load", "none")))
assign("startup_message", unname(startup_message), envir=.spOptions)
}
}
}

smess_func <- function() {
where <- get("startup_message", envir=.spOptions)
Smess <- paste("The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,\nwhich was just ", where, "ed, will retire in October 2023.\nPlease refer to R-spatial evolution reports for details, especially\nhttps://r-spatial.org/r/2023/05/15/evolution4.html.\nIt may be desirable to make the sf package available;\npackage maintainers should consider adding sf to Suggests:.\nThe sp package is now running under evolution status ", get_evolution_status(), "\n", ifelse(get_evolution_status() == 2L, " (status 2 uses the sf package in place of rgdal)\n", ""), sep="")
packageStartupMessage(Smess, appendLF = FALSE)
}

Expand Down
3 changes: 2 additions & 1 deletion R/CRS-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ setMethod("rebuild_CRS", signature(obj = "CRS"),
}
return(res)
} else {
warning("sf required for evolution_status==2L")
if (get("startup_message", envir=.spOptions) != "none")
warning("sf required for evolution_status==2L")
}
}
if ((is.na(projargs) && !is.null(SRS_string)) &&
Expand Down
2 changes: 2 additions & 0 deletions R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ aggregate.data.frame.SP <- function (x, by, FUN, ..., dissolve = TRUE) {
if (!gridded(geom) && is(geom, "SpatialPoints"))
geom = split(geom, factor(grp)) # creates SpatialMultiPoints
else {
warning("No rgeos support in sp from October 2023;\nsee https://r-spatial.org/r/2023/05/15/evolution4.html")
.Deprecated("sf::agregate")
if (!requireNamespace("rgeos", quietly = TRUE))
stop("rgeos required")
Expand Down Expand Up @@ -86,6 +87,7 @@ aggregate.Spatial = function(x, by = list(ID = rep(1, length(x))), FUN, ...,
}

aggregatePolyWeighted = function(x, by) {
warning("No rgeos support in sp from October 2023;\nsee https://r-spatial.org/r/2023/05/15/evolution4.html")
if (!requireNamespace("rgeos", quietly = TRUE))
stop("rgeos required")
i = rgeos::gIntersection(x, by, byid = TRUE, drop_lower_td = TRUE)
Expand Down
1 change: 1 addition & 0 deletions R/disaggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if (!isGeneric("disaggregate")) {

# Robert Hijmans:
explodePolygons <- function(x, ignoreholes=FALSE, ...) {
warning("No rgeos support in sp from October 2023;\nsee https://r-spatial.org/r/2023/05/15/evolution4.html")
if (!requireNamespace("rgeos", quietly = TRUE))
stop('package rgeos is needed to relate holes to their corresponding polygons')
npols <- length(x@polygons)
Expand Down
1 change: 1 addition & 0 deletions R/over.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ setMethod("over", signature("SpatialPoints", "SpatialPixelsDataFrame"),

setMethod("over", signature("Spatial", "Spatial"), # catch remaining:
function(x, y, returnList = FALSE, fn = NULL, ...) {
warning("No rgeos support in sp from October 2023;\nsee https://r-spatial.org/r/2023/05/15/evolution4.html")
.Deprecated("sf::st_intersects or sf::aggregate")
if (!requireNamespace("rgeos", quietly = TRUE))
stop("package rgeos is required for additional over methods")
Expand Down
23 changes: 16 additions & 7 deletions R/projected.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,23 @@ is.projectedCRS <- function(obj) {
if (is.null(wkt2) && is.na(p4str))
as.logical(NA)
else if (get("evolution_status", envir=.spOptions) == 2L) {
if (!requireNamespace("sf", quietly = TRUE))
stop("sf required for evolution_status==2L")
o <- try(sf::st_is_longlat(obj), silent=TRUE)
if (requireNamespace("sf", quietly = TRUE)) {
o <- try(sf::st_is_longlat(obj), silent=TRUE)
# rbgm workaround for +proj=utm +zone=18 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +# +a=6378137.0 +es=0.006694380022900787 +lon_0=-75d00 +lat_0=0d00 +x_0=500000.0 +y_0=0.0 +k=0.9996 in bgmfiles Final_CAM_Boxes_8.bgm
if (inherits(o, "try-error"))
length(grep("longlat", p4str, fixed = TRUE)) == 0L
else
!o
if (inherits(o, "try-error"))
length(grep("longlat", p4str, fixed = TRUE)) == 0L
else
!o
} else {
if (get("startup_message", envir=.spOptions) != "none")
warning("Package sf not available")
if (!is.null(wkt2)) # and old rgdal version
substring(wkt2, 1, 3) != "GEO"
else if (is.na(p4str) || !nzchar(p4str))
as.logical(NA)
else
length(grep("longlat", p4str, fixed = TRUE)) == 0L
}
} else if (get("evolution_status", envir=.spOptions) == 0L &&
requireNamespace("rgdal", quietly = TRUE) &&
packageVersion("rgdal") >= "1.5.17" && rgdal::new_proj_and_gdal())
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

R Classes and Methods for Spatial Data.

*Before* **sp** is loaded, `options("sp_evolution_status")` may be set to `0L` for legacy behaviour, `1L` for setting `CRS(, doCheckCRSArgs=FALSE, )` and other minor steps to block calls out to **rgdal** etc., and `2L` to use **sf** internally (not completed yet). If this option is not set, the environment variable `_SP_EVOLUTION_STATUS_` can be used, again *before* **sp** is loaded, set to `"0"`, `"1"` or `"2"`; this is used for running revdep checks under different evolution scenarios, anticipating [retirement of maptools, rgdal and rgeos](https://r-spatial.org/r/2022/04/12/evolution.html).
From version 2.0.0, `sp` evolution status is changed to `2L` to use **sf** internally in place of `rgdal`, from default `0L` until now. See [this report](https://r-spatial.org/r/2023/05/15/evolution4.html) for adaptation details, and [this report](https://r-spatial.org/r/2023/04/10/evolution3.html) for progress on retiring `maptools`, `rgdal` and `rgeos`.

*Before* **sp** is loaded, `options("sp_evolution_status")` may be set to `0L` for legacy behaviour, `1L` for setting `CRS(, doCheckCRSArgs=FALSE, )` and other minor steps to block calls out to **rgdal** etc., and `2L` to use **sf** internally. If this option is not set, the environment variable `_SP_EVOLUTION_STATUS_` can be used, again *before* **sp** is loaded, set to `"0"`, `"1"` or `"2"`; this is used for running revdep checks under different evolution scenarios, anticipating [retirement of maptools, rgdal and rgeos](https://r-spatial.org/r/2022/04/12/evolution.html).

From `sp 1.6.0` published on CRAN 2023-01-19, these status settings may also be changed when `sp` is loaded, using `sp::get_evolution_status()` returning the current value, and `sp::set_evolution_status(value)`, where value can take the integer values `0L`, `1L` and `2L`. `sp 1.6.1` published on CRAN 2023-05-25 added start-up messages to alert users to imminent changes.

See:

Expand Down
2 changes: 1 addition & 1 deletion inst/include/sp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#endif
/* remember to touch local_stubs.c */

#define SP_VERSION "1.6-1"
#define SP_VERSION "2.0-0"

#include <R.h>
/* RSB 091203 */
Expand Down
2 changes: 1 addition & 1 deletion src/sp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#endif
/* remember to touch local_stubs.c */

#define SP_VERSION "1.6-1"
#define SP_VERSION "2.0-0"

#include <R.h>
/* RSB 091203 */
Expand Down
25 changes: 0 additions & 25 deletions tests/agg.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
options("rgdal_show_exportToProj4_warnings"="none")
library(sp)
if (require(rgeos, quietly = TRUE)) {
g = SpatialGrid(GridTopology(c(5,5), c(10,10), c(3,3)))
p = as(g, "SpatialPolygons")
p$z = c(1,0,1,0,1,0,1,0,1)
cc = coordinates(g)
#p$ag1 = aggregate(p, p, mean)[[1]]
#p$ag1a = aggregate(p, p, mean, minDimension = 0)[[1]]
#p$ag2 = aggregate(p, p, mean, minDimension = 1)[[1]]
#p$ag3 = aggregate(p, p, mean, minDimension = 2)[[1]]
#p$ag4 = aggregate(p, p, mean, areaWeighted=TRUE)[[1]]
pts = cbind(c(9,21,21,9,9),c(9,9,21,21,9))
sq = SpatialPolygons(list(Polygons(list(Polygon(pts)), "ID")))
rnd2 = function(x) round(x, 2)
#l = list(
# list("sp.text", cc, rnd2(p$z), which = 1),
# list("sp.text", cc, rnd2(p$ag1), which = 2),
# list("sp.text", cc, rnd2(p$ag1a), which = 3),
# list("sp.text", cc, rnd2(p$ag2), which = 4),
# list("sp.text", cc, rnd2(p$ag3), which = 5),
# list("sp.text", cc, rnd2(p$ag4), which = 6),
# list(sq, col = 'green', which = 6, first = FALSE, lwd = 2)
#)
#spplot(p, names.attr = c("source", "default aggregate", "minDimension=0",
# "minDimension=1", "minDimension=2", "areaWeighted=TRUE"), layout = c(3,2),
# as.table=TRUE, col.regions=bpy.colors(151)[50:151], cuts=100,
# sp.layout = l, scales = list(draw = TRUE))

#rnd2(c(aggregate(p, sq, mean)[[1]],
# aggregate(p, sq, mean, minDimension = 0)[[1]],
# aggregate(p, sq, mean, minDimension = 1)[[1]],
# aggregate(p, sq, mean, minDimension = 2)[[1]],
# aggregate(p, sq, mean, areaWeighted=TRUE)[[1]]))
}
64 changes: 17 additions & 47 deletions tests/agg.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,23 @@ Type 'q()' to quit R.

> options("rgdal_show_exportToProj4_warnings"="none")
> library(sp)
The legacy packages maptools, rgdal, and rgeos, underpinning this package
will retire shortly. Please refer to R-spatial evolution reports on
https://r-spatial.org/r/2023/05/15/evolution4.html for details.
This package is now running under evolution status 0
> if (require(rgeos, quietly = TRUE)) {
+ g = SpatialGrid(GridTopology(c(5,5), c(10,10), c(3,3)))
+ p = as(g, "SpatialPolygons")
+ p$z = c(1,0,1,0,1,0,1,0,1)
+ cc = coordinates(g)
+ #p$ag1 = aggregate(p, p, mean)[[1]]
+ #p$ag1a = aggregate(p, p, mean, minDimension = 0)[[1]]
+ #p$ag2 = aggregate(p, p, mean, minDimension = 1)[[1]]
+ #p$ag3 = aggregate(p, p, mean, minDimension = 2)[[1]]
+ #p$ag4 = aggregate(p, p, mean, areaWeighted=TRUE)[[1]]
+ pts = cbind(c(9,21,21,9,9),c(9,9,21,21,9))
+ sq = SpatialPolygons(list(Polygons(list(Polygon(pts)), "ID")))
+ rnd2 = function(x) round(x, 2)
+ #l = list(
+ # list("sp.text", cc, rnd2(p$z), which = 1),
+ # list("sp.text", cc, rnd2(p$ag1), which = 2),
+ # list("sp.text", cc, rnd2(p$ag1a), which = 3),
+ # list("sp.text", cc, rnd2(p$ag2), which = 4),
+ # list("sp.text", cc, rnd2(p$ag3), which = 5),
+ # list("sp.text", cc, rnd2(p$ag4), which = 6),
+ # list(sq, col = 'green', which = 6, first = FALSE, lwd = 2)
+ #)
+ #spplot(p, names.attr = c("source", "default aggregate", "minDimension=0",
+ # "minDimension=1", "minDimension=2", "areaWeighted=TRUE"), layout = c(3,2),
+ # as.table=TRUE, col.regions=bpy.colors(151)[50:151], cuts=100,
+ # sp.layout = l, scales = list(draw = TRUE))
+
+ #rnd2(c(aggregate(p, sq, mean)[[1]],
+ # aggregate(p, sq, mean, minDimension = 0)[[1]],
+ # aggregate(p, sq, mean, minDimension = 1)[[1]],
+ # aggregate(p, sq, mean, minDimension = 2)[[1]],
+ # aggregate(p, sq, mean, areaWeighted=TRUE)[[1]]))
+ }
rgeos version: 0.6-3, (SVN revision 696)
GEOS runtime version: 3.11.1-CAPI-1.17.1
Please note that rgeos will be retired during October 2023,
plan transition to sf or terra functions using GEOS at your earliest convenience.
See https://r-spatial.org/r/2023/05/15/evolution4.html for details.
GEOS using OverlayNG
Linking to sp version: 1.6-0
Polygon checking: TRUE

The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
which was just loaded, will retire in October 2023.
Please refer to R-spatial evolution reports for details, especially
https://r-spatial.org/r/2023/05/15/evolution4.html.
It may be desirable to make the sf package available;
package maintainers should consider adding sf to Suggests:.
The sp package is now running under evolution status 2
(status 2 uses the sf package in place of rgdal)
> g = SpatialGrid(GridTopology(c(5,5), c(10,10), c(3,3)))
> p = as(g, "SpatialPolygons")
> p$z = c(1,0,1,0,1,0,1,0,1)
> cc = coordinates(g)
> pts = cbind(c(9,21,21,9,9),c(9,9,21,21,9))
> sq = SpatialPolygons(list(Polygons(list(Polygon(pts)), "ID")))
> rnd2 = function(x) round(x, 2)
>
>
> proc.time()
user system elapsed
0.652 0.055 0.701
0.244 0.030 0.266
14 changes: 9 additions & 5 deletions tests/base.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ Type 'q()' to quit R.

> options("rgdal_show_exportToProj4_warnings"="none")
> library(sp)
The legacy packages maptools, rgdal, and rgeos, underpinning this package
will retire shortly. Please refer to R-spatial evolution reports on
https://r-spatial.org/r/2023/05/15/evolution4.html for details.
This package is now running under evolution status 0
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
which was just loaded, will retire in October 2023.
Please refer to R-spatial evolution reports for details, especially
https://r-spatial.org/r/2023/05/15/evolution4.html.
It may be desirable to make the sf package available;
package maintainers should consider adding sf to Suggests:.
The sp package is now running under evolution status 2
(status 2 uses the sf package in place of rgdal)
> data(meuse)
> x = meuse[1:10, ] # limit the output
> coordinates(x) = c("x", "y") # names
Expand Down Expand Up @@ -464,4 +468,4 @@ Data attributes:
>
> proc.time()
user system elapsed
0.386 0.062 0.439
0.466 0.034 0.495
41 changes: 30 additions & 11 deletions tests/fail1.Rout.save
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ Type 'q()' to quit R.

> options("rgdal_show_exportToProj4_warnings"="none")
> library(sp)
The legacy packages maptools, rgdal, and rgeos, underpinning this package
will retire shortly. Please refer to R-spatial evolution reports on
https://r-spatial.org/r/2023/05/15/evolution4.html for details.
This package is now running under evolution status 0
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
which was just loaded, will retire in October 2023.
Please refer to R-spatial evolution reports for details, especially
https://r-spatial.org/r/2023/05/15/evolution4.html.
It may be desirable to make the sf package available;
package maintainers should consider adding sf to Suggests:.
The sp package is now running under evolution status 2
(status 2 uses the sf package in place of rgdal)
> data(meuse)
> x = meuse
>
Expand Down Expand Up @@ -214,14 +218,32 @@ x 5.721109 0.0005312853 84
y 50.955770 0.0003318105 112
>
> try(CRS("+proj=latlon +ellps=WGS84"))
Error in CRS("+proj=latlon +ellps=WGS84") :
northings must follow eastings: +proj=latlon +ellps=WGS84
Coordinate Reference System:
Deprecated Proj.4 representation: +proj=longlat +ellps=WGS84 +no_defs
WKT2 2019 representation:
GEOGCRS["unknown",
DATUM["Unknown based on WGS 84 ellipsoid",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1],
ID["EPSG",7030]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8901]],
CS[ellipsoidal,2],
AXIS["longitude",east,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]],
AXIS["latitude",north,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]]]
> try(CRS("+proj=lonlat +ellps=WGS84"))
Coordinate Reference System:
Deprecated Proj.4 representation: +proj=longlat +ellps=WGS84 +no_defs
WKT2 2019 representation:
GEOGCRS["unknown",
DATUM["Unknown based on WGS84 ellipsoid",
DATUM["Unknown based on WGS 84 ellipsoid",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1],
ID["EPSG",7030]]],
Expand All @@ -237,10 +259,7 @@ GEOGCRS["unknown",
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433,
ID["EPSG",9122]]]]
Warning message:
In CRS("+proj=lonlat +ellps=WGS84") :
'lonlat' changed to 'longlat': +proj=longlat +ellps=WGS84
>
> proc.time()
user system elapsed
0.547 0.073 0.612
0.830 0.046 0.881
Loading