From cf2df2614d27c03930b5d656051d8ae241c90e51 Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 23 Jul 2024 12:48:27 +0200 Subject: [PATCH 01/70] adds make_sf_aware() and is_sf_aware() in [.sf addresses #2131 --- DESCRIPTION | 1 + NAMESPACE | 1 + R/sf.R | 66 +++++++++++++++++++++-------------------- R/sf_aware.R | 70 ++++++++++++++++++++++++++++++++++++++++++++ man/make_sf_aware.Rd | 13 ++++++++ 5 files changed, 120 insertions(+), 31 deletions(-) create mode 100644 R/sf_aware.R create mode 100644 man/make_sf_aware.Rd diff --git a/DESCRIPTION b/DESCRIPTION index a761727f1..e1fef10a6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -162,6 +162,7 @@ Collate: 'gdal_utils.R' 'nearest.R' 'normalize.R' + 'sf_aware.R' 'sf-package.R' 'defunct.R' 'z_range.R' diff --git a/NAMESPACE b/NAMESPACE index d0253d02c..49258efd0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -400,6 +400,7 @@ export(gdal_utils) export(gdal_write) export(gdal_write_mdim) export(get_key_pos) +export(make_sf_aware) export(plot_sf) export(rawToHex) export(read_sf) diff --git a/R/sf.R b/R/sf.R index a387ebe53..c4b00ac5a 100644 --- a/R/sf.R +++ b/R/sf.R @@ -339,41 +339,45 @@ st_sf = function(..., agr = NA_agr_, row.names, #' h[g,] #' @export "[.sf" = function(x, i, j, ..., drop = FALSE, op = st_intersects) { - nargs = nargs() - agr = st_agr(x) - if (!missing(i) && (inherits(i, "sf") || inherits(i, "sfc") || inherits(i, "sfg"))) - i = lengths(op(x, i, ...)) != 0 - sf_column = attr(x, "sf_column") - geom = st_geometry(x) - if (!missing(i) && nargs > 2) { # e.g. a[3:4,] not a[3:4] - if (is.character(i)) - i = match(i, row.names(x)) - geom = geom[i] - } - # x = as.data.frame(x) - class(x) = setdiff(class(x), "sf") # one step down - x = if (missing(j)) { - if (nargs == 2) # `[`(x,i) - x[i] # do sth else for tbl? - else - x[i, , drop = drop] - } else - x[i, j, drop = drop] + if (is_sf_aware()) { + nargs = nargs() + agr = st_agr(x) + if (!missing(i) && (inherits(i, "sf") || inherits(i, "sfc") || inherits(i, "sfg"))) + i = lengths(op(x, i, ...)) != 0 + sf_column = attr(x, "sf_column") + geom = st_geometry(x) + if (!missing(i) && nargs > 2) { # e.g. a[3:4,] not a[3:4] + if (is.character(i)) + i = match(i, row.names(x)) + geom = geom[i] + } - if (!missing(j)) - agr = agr[j] - else if (!missing(i) && nargs <= 2) - agr = agr[i] # e.g., obj["name"] + # x = as.data.frame(x) + class(x) = setdiff(class(x), "sf") # one step down + x = if (missing(j)) { + if (nargs == 2) # `[`(x,i) + x[i] # do sth else for tbl? + else + x[i, , drop = drop] + } else + x[i, j, drop = drop] - if (inherits(x, "sfc")) # drop was TRUE, and we selected geom column only - x - else if (! drop) { - x[[ sf_column ]] = geom - x = st_sf(x, sf_column_name = sf_column, sfc_last = FALSE) - st_set_agr(x, agr[match(setdiff(names(x), sf_column), names(agr))]) + if (!missing(j)) + agr = agr[j] + else if (!missing(i) && nargs <= 2) + agr = agr[i] # e.g., obj["name"] + + if (inherits(x, "sfc")) # drop was TRUE, and we selected geom column only + x + else if (! drop) { + x[[ sf_column ]] = geom + x = st_sf(x, sf_column_name = sf_column, sfc_last = FALSE) + st_set_agr(x, agr[match(setdiff(names(x), sf_column), names(agr))]) + } else + structure(x, class = setdiff(class(x), "sf")) } else - structure(x, class = setdiff(class(x), "sf")) + NextMethod() } #' @export diff --git a/R/sf_aware.R b/R/sf_aware.R new file mode 100644 index 000000000..301ae1be2 --- /dev/null +++ b/R/sf_aware.R @@ -0,0 +1,70 @@ +# see https://github.com/r-spatial/sf/issues/2131 + +# Known namespaces that need sticky columns. This is set to the +# packages that are already depending on sf-awareness at the time +# the feature was introduced (Jul 23, 2024). +# New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). +known_sf_aware <- c(".globalenv", + "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") + +# Register environment as sf-aware. We use a lexical flag instead of +# inspecting the the name of the calling namespace and add it to +# `the$sf_aware` because the flag is more flexible. It makes it +# possible for arbitrary environments to opt into (or disable) the sf +# API like this: +# +# ``` +# local({ make_sf_aware(); sf[...] }) +# ``` +# +# Packages should call it like this in their `.onLoad()` hook (and +# thus before their namespace is sealed): +# +# ``` +# make_sf_aware(topenv(environment())) +# ``` + +#' for packages: use the sticky geometry [ behaviour of sf in package code +#' +#' for packages: use the sticky geometry [ behaviour of sf in package code +#' param env environment +#' value logical; default `TRUE` +#' @export +make_sf_aware <- function(env = parent.frame(), value = TRUE) { + env$.__sf_aware__. <- value +} + +is_sf_aware <- function(env = parent.frame(2)) { + top <- topenv(env) + + # Check for overrides + top_name <- env_name(top) + if (!is.null(top_name) && top_name %in% known_sf_aware) + TRUE + else { + if (!requireNamespace("rlang", quietly = TRUE)) + stop("rlang is not installed: install first?") + # Now check for the lexical flag. This could be rewritten + # without rlang as a loop over parents that stops at `topenv()`. + flag <- rlang::env_get( + env, + ".__sf_aware__.", + default = FALSE, + inherit = TRUE, + last = top + ) + stopifnot(is.logical(flag) && length(flag) == 1 && !is.na(flag)) + flag + } +} + +env_name <- function(env) { + ns <- topenv(env) + + if (isNamespace(ns)) + getNamespaceName(ns) + else if (identical(ns, globalenv())) + ".globalenv" + else + NULL +} diff --git a/man/make_sf_aware.Rd b/man/make_sf_aware.Rd new file mode 100644 index 000000000..0030ea5f9 --- /dev/null +++ b/man/make_sf_aware.Rd @@ -0,0 +1,13 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sf_aware.R +\name{make_sf_aware} +\alias{make_sf_aware} +\title{for packages: use the sticky geometry [ behaviour of sf in package code} +\usage{ +make_sf_aware(env = parent.frame(), value = TRUE) +} +\description{ +for packages: use the sticky geometry [ behaviour of sf in package code +param env environment +value logical; default \code{TRUE} +} From 8574c4c1136962f3456520a32e0fc65d5de6a722 Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 23 Jul 2024 13:08:15 +0200 Subject: [PATCH 02/70] pass R CMD check; #2131 --- R/sf_aware.R | 6 +++--- man/make_sf_aware.Rd | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/R/sf_aware.R b/R/sf_aware.R index 301ae1be2..db1bba126 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -4,7 +4,7 @@ # packages that are already depending on sf-awareness at the time # the feature was introduced (Jul 23, 2024). # New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). -known_sf_aware <- c(".globalenv", +known_sf_aware <- c(".globalenv", "sf", "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") # Register environment as sf-aware. We use a lexical flag instead of @@ -27,8 +27,8 @@ known_sf_aware <- c(".globalenv", #' for packages: use the sticky geometry [ behaviour of sf in package code #' #' for packages: use the sticky geometry [ behaviour of sf in package code -#' param env environment -#' value logical; default `TRUE` +#' @param env environment +#' @param value logical; default `TRUE` #' @export make_sf_aware <- function(env = parent.frame(), value = TRUE) { env$.__sf_aware__. <- value diff --git a/man/make_sf_aware.Rd b/man/make_sf_aware.Rd index 0030ea5f9..2b10f5a28 100644 --- a/man/make_sf_aware.Rd +++ b/man/make_sf_aware.Rd @@ -6,8 +6,11 @@ \usage{ make_sf_aware(env = parent.frame(), value = TRUE) } +\arguments{ +\item{env}{environment} + +\item{value}{logical; default \code{TRUE}} +} \description{ for packages: use the sticky geometry [ behaviour of sf in package code -param env environment -value logical; default \code{TRUE} } From c6a2bf6596c7bbaf42e15611ea2018fd7c53821f Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 23 Jul 2024 16:05:47 +0200 Subject: [PATCH 03/70] add pkg base; #2131 --- R/sf_aware.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/sf_aware.R b/R/sf_aware.R index db1bba126..c79e680a8 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -4,7 +4,7 @@ # packages that are already depending on sf-awareness at the time # the feature was introduced (Jul 23, 2024). # New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). -known_sf_aware <- c(".globalenv", "sf", +known_sf_aware <- c(".globalenv", "sf", "base", "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") # Register environment as sf-aware. We use a lexical flag instead of From 70d0318722171df189900562c63d22179a6c722f Mon Sep 17 00:00:00 2001 From: edzer Date: Sat, 27 Jul 2024 17:38:05 +0200 Subject: [PATCH 04/70] strip sf class in [.sf in case of sf-unaware; #2131 --- R/sf.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/sf.R b/R/sf.R index c4b00ac5a..3da3bef7f 100644 --- a/R/sf.R +++ b/R/sf.R @@ -377,7 +377,7 @@ st_sf = function(..., agr = NA_agr_, row.names, } else structure(x, class = setdiff(class(x), "sf")) } else - NextMethod() + structure(NextMethod(), class = setdiff(class(x), "sf")) } #' @export From 7ed9436eb2e47a5ecfd0203a6de9dfc88c24e998 Mon Sep 17 00:00:00 2001 From: edzer Date: Sun, 28 Jul 2024 14:09:01 +0200 Subject: [PATCH 05/70] add pkg utils to sf-aware list; #2131 --- R/sf_aware.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/sf_aware.R b/R/sf_aware.R index c79e680a8..c48b28edb 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -4,7 +4,7 @@ # packages that are already depending on sf-awareness at the time # the feature was introduced (Jul 23, 2024). # New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). -known_sf_aware <- c(".globalenv", "sf", "base", +known_sf_aware <- c(".globalenv", "sf", "base", "utils", "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") # Register environment as sf-aware. We use a lexical flag instead of From 04579817a499210eae7b3a27ebed573d2cd51ca6 Mon Sep 17 00:00:00 2001 From: edzer Date: Sun, 28 Jul 2024 14:36:34 +0200 Subject: [PATCH 06/70] handle drop=TRUE if non-aware; #2131 --- R/sf.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/sf.R b/R/sf.R index 3da3bef7f..7ed419a77 100644 --- a/R/sf.R +++ b/R/sf.R @@ -376,8 +376,13 @@ st_sf = function(..., agr = NA_agr_, row.names, st_set_agr(x, agr[match(setdiff(names(x), sf_column), names(agr))]) } else structure(x, class = setdiff(class(x), "sf")) - } else - structure(NextMethod(), class = setdiff(class(x), "sf")) + } else { + ret = NextMethod() + if (inherits(ret, "sf")) + structure(NextMethod(), class = setdiff(class(ret), "sf")) + else + ret + } } #' @export From d7c8f207e4df4e82557496dc9a98047380ecc0d1 Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 30 Jul 2024 17:41:25 +0200 Subject: [PATCH 07/70] add packages; #2131 --- R/sf_aware.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/sf_aware.R b/R/sf_aware.R index c48b28edb..1d0bba48b 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -4,7 +4,9 @@ # packages that are already depending on sf-awareness at the time # the feature was introduced (Jul 23, 2024). # New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). -known_sf_aware <- c(".globalenv", "sf", "base", "utils", +known_sf_aware <- c(".globalenv", "sf", "base", "utils", "stats", + "rsample", # called by spatialsample + "od", # only imports sfheaders; used by abstr "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") # Register environment as sf-aware. We use a lexical flag instead of From 4b30e55b7194c96bd4f6e042b01a93fa253652df Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 30 Jul 2024 18:03:18 +0200 Subject: [PATCH 08/70] add relocate.sf, to make ARUtools pass check; #2131 --- R/tidyverse.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/tidyverse.R b/R/tidyverse.R index 7e2ddc83d..1626b0bbd 100644 --- a/R/tidyverse.R +++ b/R/tidyverse.R @@ -176,6 +176,11 @@ select.sf <- function(.data, ...) { st_set_agr(st_as_sf(ret, sf_column_name = sf_column), new_agr) } +#' @name tidyverse +relocate.sf = function(.data, ..., .before = NULL, .after = NULL) { + st_as_sf(NextMethod()) +} + #' @name tidyverse #' @examples @@ -678,6 +683,7 @@ register_all_s3_methods = function() { s3_register("dplyr::inner_join", "sf") s3_register("dplyr::left_join", "sf") s3_register("dplyr::mutate", "sf") + s3_register("dplyr::relocate", "sf") s3_register("dplyr::rename", "sf") s3_register("dplyr::rename_with", "sf") s3_register("dplyr::right_join", "sf") From 15786910f0330a624672912c5cfa65088bd7860c Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 31 Jul 2024 14:07:01 +0200 Subject: [PATCH 09/70] add new packages importing sf; #2131 --- R/sf_aware.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/sf_aware.R b/R/sf_aware.R index 1d0bba48b..5f1fc265d 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -7,6 +7,8 @@ known_sf_aware <- c(".globalenv", "sf", "base", "utils", "stats", "rsample", # called by spatialsample "od", # only imports sfheaders; used by abstr + "igr", # published Jul 27, 2024 + "weatherOz", # published Jul 26, 2024 "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") # Register environment as sf-aware. We use a lexical flag instead of From f5d6da5d57e9ff61b741fb8a461fbbe3487e366e Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 31 Jul 2024 22:47:40 +0200 Subject: [PATCH 10/70] add sf_make_aware_pgk(); #2131 --- DESCRIPTION | 2 +- NAMESPACE | 4 +++- R/init.R | 2 +- R/sf_aware.R | 17 +++++++++++++++-- R/tidyverse.R | 2 ++ man/{make_sf_aware.Rd => sf_make_aware.Rd} | 11 ++++++++--- man/tidyverse.Rd | 7 +++++++ tests/spatstat.Rout.save | 11 ++++++----- 8 files changed, 43 insertions(+), 13 deletions(-) rename man/{make_sf_aware.Rd => sf_make_aware.Rd} (67%) diff --git a/DESCRIPTION b/DESCRIPTION index e1fef10a6..3d59d06a7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -112,7 +112,7 @@ LinkingTo: VignetteBuilder: knitr Encoding: UTF-8 -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) Config/testthat/edition: 2 Config/needs/coverage: XML diff --git a/NAMESPACE b/NAMESPACE index b1227fbc2..bb8118faf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -401,13 +401,14 @@ export(gdal_utils) export(gdal_write) export(gdal_write_mdim) export(get_key_pos) -export(make_sf_aware) export(plot_sf) export(rawToHex) export(read_sf) export(sf.colors) export(sf_add_proj_units) export(sf_extSoftVersion) +export(sf_make_aware) +export(sf_make_aware_pkg) export(sf_proj_info) export(sf_proj_network) export(sf_proj_pipelines) @@ -573,6 +574,7 @@ importFrom(units,as_units) importFrom(units,drop_units) importFrom(units,make_unit_label) importFrom(units,set_units) +importFrom(utils,assignInMyNamespace) importFrom(utils,compareVersion) importFrom(utils,globalVariables) importFrom(utils,head) diff --git a/R/init.R b/R/init.R index eea3ef728..50b9ddb3e 100644 --- a/R/init.R +++ b/R/init.R @@ -1,4 +1,4 @@ -#' @importFrom utils head object.size str tail packageVersion compareVersion globalVariables +#' @importFrom utils head tail object.size str packageVersion compareVersion globalVariables assignInMyNamespace #' @importFrom stats aggregate dist na.omit rbinom runif setNames #' @importFrom tools file_ext file_path_sans_ext #' @importFrom methods as new slot slotNames slot<- diff --git a/R/sf_aware.R b/R/sf_aware.R index 5f1fc265d..7438edc34 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -5,7 +5,6 @@ # the feature was introduced (Jul 23, 2024). # New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). known_sf_aware <- c(".globalenv", "sf", "base", "utils", "stats", - "rsample", # called by spatialsample "od", # only imports sfheaders; used by abstr "igr", # published Jul 27, 2024 "weatherOz", # published Jul 26, 2024 @@ -31,13 +30,27 @@ known_sf_aware <- c(".globalenv", "sf", "base", "utils", "stats", #' for packages: use the sticky geometry [ behaviour of sf in package code #' #' for packages: use the sticky geometry [ behaviour of sf in package code +#' @name sf_make_aware #' @param env environment #' @param value logical; default `TRUE` #' @export -make_sf_aware <- function(env = parent.frame(), value = TRUE) { +sf_make_aware <- function(env = parent.frame(), value = TRUE) { env$.__sf_aware__. <- value } +#' @export +#' @name sf_make_aware +#' @param pkg package name +sf_make_aware_pkg <- function(pkg) { + stopifnot(is.character(pkg), length(pkg) == 1) + old = known_sf_aware + if (pkg %in% old) + message(paste("package", pkg, "is already sf-aware")) + else + utils::assignInMyNamespace("known_sf_aware", c(pkg, known_sf_aware)) + invisible(old) +} + is_sf_aware <- function(env = parent.frame(2)) { top <- topenv(env) diff --git a/R/tidyverse.R b/R/tidyverse.R index 1626b0bbd..48cb4b70c 100644 --- a/R/tidyverse.R +++ b/R/tidyverse.R @@ -177,6 +177,8 @@ select.sf <- function(.data, ...) { } #' @name tidyverse +#' @param .before see original docs +#' @param .after see original docs relocate.sf = function(.data, ..., .before = NULL, .after = NULL) { st_as_sf(NextMethod()) } diff --git a/man/make_sf_aware.Rd b/man/sf_make_aware.Rd similarity index 67% rename from man/make_sf_aware.Rd rename to man/sf_make_aware.Rd index 2b10f5a28..abbfc04f8 100644 --- a/man/make_sf_aware.Rd +++ b/man/sf_make_aware.Rd @@ -1,15 +1,20 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/sf_aware.R -\name{make_sf_aware} -\alias{make_sf_aware} +\name{sf_make_aware} +\alias{sf_make_aware} +\alias{sf_make_aware_pkg} \title{for packages: use the sticky geometry [ behaviour of sf in package code} \usage{ -make_sf_aware(env = parent.frame(), value = TRUE) +sf_make_aware(env = parent.frame(), value = TRUE) + +sf_make_aware_pkg(pkg) } \arguments{ \item{env}{environment} \item{value}{logical; default \code{TRUE}} + +\item{pkg}{package name} } \description{ for packages: use the sticky geometry [ behaviour of sf in package code diff --git a/man/tidyverse.Rd b/man/tidyverse.Rd index 1ec7b2eb0..86820f722 100644 --- a/man/tidyverse.Rd +++ b/man/tidyverse.Rd @@ -10,6 +10,7 @@ \alias{mutate.sf} \alias{transmute.sf} \alias{select.sf} +\alias{relocate.sf} \alias{rename.sf} \alias{rename_with.sf} \alias{slice.sf} @@ -53,6 +54,8 @@ transmute.sf(.data, ..., .dots) select.sf(.data, ...) +relocate.sf(.data, ..., .before = NULL, .after = NULL) + rename.sf(.data, ...) rename_with.sf(.data, .fn, .cols, ...) @@ -178,6 +181,10 @@ anti_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...) lazy data frames (e.g. from dbplyr or dtplyr). See \emph{Methods}, below, for more details.} +\item{.before}{see original docs} + +\item{.after}{see original docs} + \item{.fn, .cols}{see original docs} \item{do_union}{logical; in case \code{summary} does not create a geometry column, should geometries be created by unioning using \link{st_union}, or simply by combining using \link{st_combine}? Using \link{st_union} resolves internal boundaries, but in case of unioning points, this will likely change the order of the points; see Details.} diff --git a/tests/spatstat.Rout.save b/tests/spatstat.Rout.save index 8f0a32e94..5033e3a21 100644 --- a/tests/spatstat.Rout.save +++ b/tests/spatstat.Rout.save @@ -1,7 +1,7 @@ -R version 4.3.3 (2024-02-29) -- "Angel Food Cake" +R version 4.4.1 (2024-06-14) -- "Race for Your Life" Copyright (C) 2024 The R Foundation for Statistical Computing -Platform: x86_64-pc-linux-gnu (64-bit) +Platform: x86_64-pc-linux-gnu R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. @@ -125,8 +125,9 @@ Type 'q()' to quit R. + (y = st_as_sfc(as.psp(sf))) + all.equal(st_geometry(x), y) + } -spatstat.geom 3.2-9 -spatstat.random 3.2-3 +spatstat.univar 3.0-0 +spatstat.geom 3.3-2 +spatstat.random 3.3-1 Simple feature collection with 51 features and 1 field Geometry type: GEOMETRY Dimension: XY @@ -165,4 +166,4 @@ In st_as_sfc.owin(spatstat.geom::as.owin(x)) : > > proc.time() user system elapsed - 2.074 1.308 1.918 + 1.892 1.411 1.794 From ad15dfdf7037acd931dd79e26d189ac72aa065d9 Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 23 Aug 2024 14:35:45 +0200 Subject: [PATCH 11/70] address #2424 --- R/geom-predicates.R | 6 +++--- man/geos_binary_pred.Rd | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/geom-predicates.R b/R/geom-predicates.R index 4ff90f983..160858be5 100644 --- a/R/geom-predicates.R +++ b/R/geom-predicates.R @@ -254,7 +254,7 @@ st_equals_exact = function(x, y, par, sparse = TRUE, prepared = FALSE, ...) { #' @name geos_binary_pred #' @export #' @param dist distance threshold; geometry indexes with distances smaller or equal to this value are returned; numeric value or units value having distance units. -st_is_within_distance = function(x, y = x, dist, sparse = TRUE, ...) { +st_is_within_distance = function(x, y = x, dist, sparse = TRUE, ..., remove_self = FALSE) { ret = if (isTRUE(st_is_longlat(x))) { units(dist) = as_units("m") # might convert @@ -269,11 +269,11 @@ st_is_within_distance = function(x, y = x, dist, sparse = TRUE, ...) { lwgeom::st_geod_distance(x, y, tolerance = dist, sparse = TRUE) } sgbp(r, predicate = "is_within_distance", region.id = seq_along(x), - ncol = length(st_geometry(y))) + remove_self = remove_self, ncol = length(st_geometry(y))) } else { if (!is.null(st_crs(x)$ud_unit)) units(dist) = st_crs(x)$ud_unit # might convert - st_geos_binop("is_within_distance", x, y, par = dist, sparse = sparse, ...) + st_geos_binop("is_within_distance", x, y, par = dist, sparse = sparse, remove_self = remove_self, ...) } if (!sparse) as.matrix(ret) diff --git a/man/geos_binary_pred.Rd b/man/geos_binary_pred.Rd index 71a2b2fc3..9c26b29ec 100644 --- a/man/geos_binary_pred.Rd +++ b/man/geos_binary_pred.Rd @@ -49,7 +49,7 @@ st_covered_by(x, y = x, sparse = TRUE, prepared = TRUE, ..., model = "closed") st_equals_exact(x, y, par, sparse = TRUE, prepared = FALSE, ...) -st_is_within_distance(x, y = x, dist, sparse = TRUE, ...) +st_is_within_distance(x, y = x, dist, sparse = TRUE, ..., remove_self = FALSE) } \arguments{ \item{x}{object of class \code{sf}, \code{sfc} or \code{sfg}} From d323b0a620a9852f22b9e0c3d6a1cfb5670c8893 Mon Sep 17 00:00:00 2001 From: edzer Date: Sat, 24 Aug 2024 20:22:41 +0200 Subject: [PATCH 12/70] address #2420 --- src/gdal_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gdal_utils.cpp b/src/gdal_utils.cpp index dae404414..080e8f1f1 100644 --- a/src/gdal_utils.cpp +++ b/src/gdal_utils.cpp @@ -77,7 +77,7 @@ Rcpp::CharacterVector CPL_ogrinfo(Rcpp::CharacterVector obj, Rcpp::CharacterVect GDALDatasetH ds = NULL; #if GDAL_VERSION_NUM >= 3070000 if (obj.size()) - ds = GDALOpenEx((const char *) obj[0], GA_ReadOnly, NULL, oo_char.data(), NULL); + ds = GDALOpenEx((const char *) obj[0], GA_Update, NULL, oo_char.data(), NULL); GDALVectorInfoOptions* opt = GDALVectorInfoOptionsNew(options_char.data(), NULL); char *ret_val = GDALVectorInfo(ds, opt); if (ret_val == NULL) From bbd2471115e5933ee986aaae1fb8189eadc3d009 Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 3 Sep 2024 21:28:46 +0200 Subject: [PATCH 13/70] tidy CRAN checks --- R/read.R | 2 +- inst/docker/gdal/Dockerfile | 18 +++++++++--------- man/st_write.Rd | 2 +- tests/aggregate.R | 2 ++ tests/sfc.R | 2 ++ 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/R/read.R b/R/read.R index 26d407457..80fde11f0 100644 --- a/R/read.R +++ b/R/read.R @@ -443,7 +443,7 @@ abbreviate_shapefile_names = function(x) { #' When deleting layers or data sources is not successful, no error is emitted. #' \code{delete_dsn} and \code{delete_layer} should be #' handled with care; the former may erase complete directories or databases. -#' @seealso \link{st_drivers}, \link{dbWriteTable} +#' @seealso \link{st_drivers}, \link[DBI]{dbWriteTable} #' @return \code{obj}, invisibly #' @examples #' nc = st_read(system.file("shape/nc.shp", package="sf")) diff --git a/inst/docker/gdal/Dockerfile b/inst/docker/gdal/Dockerfile index aba8fc35e..4b7a26daf 100644 --- a/inst/docker/gdal/Dockerfile +++ b/inst/docker/gdal/Dockerfile @@ -100,8 +100,8 @@ RUN cd proj* \ # && cd - # GDAL: -ENV GDAL_VERSION 3.9.0 -ENV GDAL_VERSION_NAME 3.9.0rc1 +ENV GDAL_VERSION 3.9.2 +ENV GDAL_VERSION_NAME 3.9.2 #https://download.osgeo.org/gdal/3.9.0/gdal-3.9.0beta1.tar.gz RUN wget -q http://download.osgeo.org/gdal/${GDAL_VERSION}/gdal-${GDAL_VERSION_NAME}.tar.gz \ @@ -128,10 +128,10 @@ RUN R CMD build --no-manual stars RUN R CMD INSTALL sf RUN R CMD INSTALL lwgeom RUN R CMD INSTALL stars - -RUN R CMD check --no-build-vignettes --no-manual --as-cran sf_*.tar.gz -RUN R CMD check --no-build-vignettes --no-manual --as-cran lwgeom_*.tar.gz - -RUN Rscript -e 'options(timeout=1200); install.packages("starsdata", repos="http://cran.uni-muenster.de/pebesma/")' - -RUN _R_CHECK_FORCE_SUGGESTS_=false R CMD check --no-build-vignettes --no-manual --as-cran stars_*.tar.gz +# +#RUN R CMD check --no-build-vignettes --no-manual --as-cran sf_*.tar.gz +#RUN R CMD check --no-build-vignettes --no-manual --as-cran lwgeom_*.tar.gz +# +#RUN Rscript -e 'options(timeout=1200); install.packages("starsdata", repos="http://cran.uni-muenster.de/pebesma/")' +# +#RUN _R_CHECK_FORCE_SUGGESTS_=false R CMD check --no-build-vignettes --no-manual --as-cran stars_*.tar.gz diff --git a/man/st_write.Rd b/man/st_write.Rd index b28ee2e10..7d8455705 100644 --- a/man/st_write.Rd +++ b/man/st_write.Rd @@ -136,5 +136,5 @@ if (require(sp, quietly = TRUE)) { } } \seealso{ -\link{st_drivers}, \link{dbWriteTable} +\link{st_drivers}, \link[DBI]{dbWriteTable} } diff --git a/tests/aggregate.R b/tests/aggregate.R index 723f8f238..b74240e14 100644 --- a/tests/aggregate.R +++ b/tests/aggregate.R @@ -1,4 +1,6 @@ +## IGNORE_RDIFF_BEGIN library(sf) +## IGNORE_RDIFF_END # aggregate pl1 = st_polygon(list(rbind(c(0,0),c(1,0),c(1,1),c(0,0)))) pl2 = st_polygon(list(rbind(c(0,0),c(1,1),c(0,1),c(0,0)))) diff --git a/tests/sfc.R b/tests/sfc.R index a0e082972..855160f8f 100644 --- a/tests/sfc.R +++ b/tests/sfc.R @@ -100,7 +100,9 @@ x = st_sfc(st_point(c(-90,35)), st_point(c(-80,36)), crs = "+proj=longlat +datum=NAD27") y = st_transform(x, 3857) +## IGNORE_RDIFF_BEGIN sf_extSoftVersion()[1:3] +## IGNORE_RDIFF_END # Ops.sfc: ls = st_sfc(st_linestring(rbind(c(0,0),c(0,1)))) From 0381f3a9cfa402e9986fd46ee02e30161c23cc39 Mon Sep 17 00:00:00 2001 From: Andrea Gilardi Date: Mon, 16 Sep 2024 18:07:07 +0200 Subject: [PATCH 14/70] Update comment Update comment following the discussion at https://github.com/r-spatial/sf/issues/2439 --- src/gdal.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gdal.cpp b/src/gdal.cpp index 0410ba594..1653aca79 100644 --- a/src/gdal.cpp +++ b/src/gdal.cpp @@ -663,6 +663,10 @@ Rcpp::List CPL_transform(Rcpp::List sfc, Rcpp::List crs, Rcpp::List ret = sfc_from_ogr(g, true); // destroys g; // how to return the target CRS when only a transformation pipeline is provided? Not by: // ret.attr("crs") = create_crs(ct->GetTargetCS(), true); + // + // According to the discussion at https://github.com/r-spatial/sf/issues/2439, this is + // not a solvable issue in general. See the same link for a possible workaround and + // a more general solution that uses PROJ. ct->DestroyCT(ct); if (dest) dest->Release(); From 6a2eb34a26dac739a33d767e31a6377e221a2b4f Mon Sep 17 00:00:00 2001 From: edzer Date: Tue, 17 Sep 2024 23:53:13 +0200 Subject: [PATCH 15/70] update --- inst/docker/gdal/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/docker/gdal/Dockerfile b/inst/docker/gdal/Dockerfile index 4b7a26daf..37a0044dd 100644 --- a/inst/docker/gdal/Dockerfile +++ b/inst/docker/gdal/Dockerfile @@ -63,7 +63,7 @@ RUN locale-gen en_US.UTF-8 ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH # GEOS: -ENV GEOS_VERSION 3.12.1 +ENV GEOS_VERSION 3.13.0 RUN wget -q http://download.osgeo.org/geos/geos-${GEOS_VERSION}.tar.bz2 \ && bzip2 -d geos-*bz2 \ @@ -79,7 +79,7 @@ RUN wget -q http://download.osgeo.org/geos/geos-${GEOS_VERSION}.tar.bz2 \ #RUN git clone --depth 1 https://github.com/OSGeo/PROJ.git # https://download.osgeo.org/proj/proj-9.0.0RC1.tar.gz -ENV PROJ_VERSION 9.4.0 +ENV PROJ_VERSION 9.4.1 RUN wget -q http://download.osgeo.org/proj/proj-${PROJ_VERSION}.tar.gz RUN tar zxvf proj-${PROJ_VERSION}.tar.gz RUN cd proj* \ From 3d82b7a0d8b28937480f47ea791e545a79be7f4f Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 18 Sep 2024 00:34:28 +0200 Subject: [PATCH 16/70] first shot at #2441 --- R/sfc.R | 4 ++-- R/wkt.R | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/R/sfc.R b/R/sfc.R index 5b3e103c1..c12423a62 100644 --- a/R/sfc.R +++ b/R/sfc.R @@ -255,9 +255,9 @@ print.sfc = function(x, ..., n = 5L, what = "Geometry set for", append = "") { cat(paste0("First ", n, " geometries:\n")) for (i in seq_len(min(n, length(x)))) if (inherits(x[[i]], "sfg")) - print(x[[i]], width = 50) + print(x[[i]], width = 50, crs = crs) else - print(x[[i]]) + print(x[[i]], crs = crs) invisible(x) } diff --git a/R/wkt.R b/R/wkt.R index 23db01d66..dc73c1346 100644 --- a/R/wkt.R +++ b/R/wkt.R @@ -57,7 +57,14 @@ prnt.MULTIPOINT = function(x, ..., EWKT = TRUE, nested_parens = FALSE) { prnt.Matrix(x, nested_parens = nested_parens, ...)) } prnt.LINESTRING = function(x, ..., EWKT = TRUE) paste(WKT_name(x, EWKT = EWKT), prnt.Matrix(x, ...)) -prnt.POLYGON = function(x, ..., EWKT = TRUE) paste(WKT_name(x, EWKT = EWKT), prnt.MatrixList(x, ...)) +POLYGON_FULL = matrix(c(0,-90,0,-90), 2, byrow = TRUE) +prnt.POLYGON = function(x, ..., EWKT = TRUE) { + if (!is.null(crs <- list(...)$crs) && st_is_longlat(crs) && length(x) && nrow(x[[1]]) == 2 && identical(x[[1]], POLYGON_FULL)) + "POLYGON FULL" + else + paste(WKT_name(x, EWKT = EWKT), prnt.MatrixList(x, ...)) +} + prnt.MULTILINESTRING = function(x, ..., EWKT = TRUE) paste(WKT_name(x, EWKT = EWKT), prnt.MatrixList(x, ...)) prnt.MULTIPOLYGON = function(x, ..., EWKT = TRUE) paste(WKT_name(x, EWKT = EWKT), prnt.MatrixListList(x, ...)) prnt.GEOMETRYCOLLECTION = function(x, ..., EWKT = TRUE) { @@ -164,6 +171,8 @@ st_as_sfc.character = function(x, crs = NA_integer_, ..., GeoJSON = FALSE) { } x = ewkt_to_wkt(x) } + if (isTRUE(st_is_longlat(crs)) && any(full <- (x == "POLYGON FULL"))) + x[full] = "POLYGON((0 -90,0 -90))" # s2 code for POLYGON FULL ret = st_sfc(CPL_sfc_from_wkt(x)) st_crs(ret) = crs ret From 4bde1501c61aecc1fd167cdf804ad00ca16205a1 Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 20 Sep 2024 22:05:24 +0200 Subject: [PATCH 17/70] more support for POLYGON FULL; #2441 --- NAMESPACE | 6 +++ R/bbox.R | 12 ++++- R/crs.R | 2 +- R/geom-predicates.R | 4 +- R/sfc.R | 52 ++++++++++++++++++- R/valid.R | 5 +- R/wkt.R | 8 +-- man/geos_binary_pred.Rd | 2 +- man/st_bbox.Rd | 7 +++ tests/full.R | 27 ++++++++++ tests/full.Rout.save | 110 ++++++++++++++++++++++++++++++++++++++++ vignettes/sf7.Rmd | 68 ++++++++++++------------- 12 files changed, 255 insertions(+), 48 deletions(-) create mode 100644 tests/full.R create mode 100644 tests/full.Rout.save diff --git a/NAMESPACE b/NAMESPACE index bb8118faf..5f7990594 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -237,6 +237,10 @@ S3method(st_intersects,sfg) S3method(st_is,sf) S3method(st_is,sfc) S3method(st_is,sfg) +S3method(st_is_full,bbox) +S3method(st_is_full,sf) +S3method(st_is_full,sfc) +S3method(st_is_full,sfg) S3method(st_is_valid,sf) S3method(st_is_valid,sfc) S3method(st_is_valid,sfg) @@ -380,6 +384,7 @@ export(.get_layout) export(.image_scale) export(.image_scale_factor) export(.stop_geos) +export(FULL_bbox_) export(NA_agr_) export(NA_bbox_) export(NA_crs_) @@ -465,6 +470,7 @@ export(st_intersection) export(st_intersects) export(st_is) export(st_is_empty) +export(st_is_full) export(st_is_longlat) export(st_is_simple) export(st_is_valid) diff --git a/R/bbox.R b/R/bbox.R index 387e9ef8c..69e265ea6 100644 --- a/R/bbox.R +++ b/R/bbox.R @@ -71,7 +71,7 @@ st_bbox.MULTIPOINT = bbox.Mtrx st_bbox.LINESTRING = bbox.Mtrx #' @export #' @name st_bbox -st_bbox.POLYGON = bbox.MtrxSet +st_bbox.POLYGON = function(obj, ...) if (sf_use_s2() && length(obj) == 1 && nrow(obj[[1]]) == 2) FULL_bbox_ else bbox.MtrxSet(obj) #' @export #' @name st_bbox st_bbox.MULTILINESTRING = bbox.MtrxSet @@ -138,7 +138,7 @@ compute_bbox = function(obj) { sfc_POINT = bb_wrap(bbox.Set(obj)), sfc_MULTIPOINT = bb_wrap(bbox.MtrxSet(obj)), sfc_LINESTRING = bb_wrap(bbox.MtrxSet(obj)), - sfc_POLYGON = bb_wrap(bbox.MtrxSetSet(obj)), + sfc_POLYGON = if (any(st_is_full(obj))) FULL_bbox_ else bb_wrap(bbox.MtrxSetSet(obj)), sfc_MULTILINESTRING = bb_wrap(bbox.MtrxSetSet(obj)), sfc_MULTIPOLYGON = bb_wrap(bbox.MtrxSetSetSet(obj)), bbox_list(obj) @@ -219,6 +219,14 @@ NA_bbox_ = structure(rep(NA_real_, 4), crs = NA_crs_, class = "bbox") +#' @name st_bbox +#' @details \code{NA_bbox_} represents the missing value for a \code{bbox} object +#' @export +FULL_bbox_ = structure(c(-180.,-90.,180.,90.), + names = c("xmin", "ymin", "xmax", "ymax"), + crs = NA_crs_, + class = "bbox") + #' @name st_bbox #' @export format.bbox = function(x, ...) { diff --git a/R/crs.R b/R/crs.R index a73bdb158..15053645e 100644 --- a/R/crs.R +++ b/R/crs.R @@ -249,7 +249,7 @@ st_is_longlat = function(x) { NA else { ret = crs_parameters(crs)$IsGeographic - if (ret && inherits(x, c("sf", "sfc", "stars"))) { + if (ret && inherits(x, c("sf", "sfc", "stars")) && !is.null(attr(x, "bbox"))) { bb = st_bbox(x) # check for potentially meaningless value range: eps = sqrt(.Machine$double.eps) diff --git a/R/geom-predicates.R b/R/geom-predicates.R index 160858be5..170fea2dd 100644 --- a/R/geom-predicates.R +++ b/R/geom-predicates.R @@ -165,9 +165,9 @@ st_intersects.sfg = function(x, y, sparse = TRUE, prepared = TRUE, ...) #' @name geos_binary_pred #' @export -st_disjoint = function(x, y = x, sparse = TRUE, prepared = TRUE) { +st_disjoint = function(x, y = x, sparse = TRUE, prepared = TRUE, ...) { # st_geos_binop("disjoint", x, y, sparse = sparse, prepared = prepared) -> didn't use STRtree - int = st_geos_binop("intersects", x, y, sparse = sparse, prepared = prepared) + int = st_geos_binop("intersects", x, y, sparse = sparse, prepared = prepared, ...) # disjoint = !intersects : if (sparse) sgbp(lapply(int, function(g) setdiff(seq_along(st_geometry(y)), g)), diff --git a/R/sfc.R b/R/sfc.R index c12423a62..65b822d29 100644 --- a/R/sfc.R +++ b/R/sfc.R @@ -602,6 +602,54 @@ st_as_sfc.blob = function(x, ...) { #' @name st_as_sfc #' @export st_as_sfc.bbox = function(x, ...) { - box = st_polygon(list(matrix(x[c(1, 2, 3, 2, 3, 4, 1, 4, 1, 2)], ncol = 2, byrow = TRUE))) - st_sfc(box, crs = st_crs(x)) + if (st_is_full(x)) + st_as_sfc("POLYGON FULL", crs = st_crs(x)) + else { + box = st_polygon(list(matrix(x[c(1, 2, 3, 2, 3, 4, 1, 4, 1, 2)], ncol = 2, byrow = TRUE))) + st_sfc(box, crs = st_crs(x)) + } +} + +POLYGON_FULL = matrix(c(0,-90,0,-90), 2, byrow = TRUE) + +#' predicate whether a geometry is equal to a POLYGON FULL +#' +#' predicate whether a geometry is equal to a POLYGON FULL +#' @param x object of class `sfg`, `sfc` or `sf` +#' @param ... ignored, except when it contains a `crs` argument to inform unspecified `is_longlat` +#' @returns logical, indicating whether geometries are POLYGON FULL (a spherical +#' polygon covering the entire sphere) +#' @export +st_is_full = function(x, ...) UseMethod("st_is_full") + +#' @export +#' @param is_longlat logical; output of \link{st_is_longlat} of the parent `sfc` object +st_is_full.sfg = function(x, ..., is_longlat = NULL) { + if (identical(is_longlat, FALSE)) # we know these are Cartesian coordinates: + FALSE + else + sf_use_s2() && inherits(x, "POLYGON") && + length(x) == 1 && nrow(x[[1]]) == 2 && identical(x[[1]], POLYGON_FULL) +} + +#' @export +st_is_full.sfc = function(x, ...) { + if (sf_use_s2() && inherits(x, c("sfc_POLYGON", "sfc_GEOMETRY"))) { + is_longlat = if (!is.null(attr(x, "crs"))) + st_is_longlat(x) + else + NA + sapply(x, st_is_full.sfg, ..., is_longlat = is_longlat) + } else + rep_len(FALSE, length(x)) +} + +#' @export +st_is_full.sf = function(x, ...) { + st_is_full(st_geometry(x), ...) +} + +#' @export +st_is_full.bbox = function(x, ...) { + sf_use_s2() && st_is_longlat(x) && all(x == c(-180,-90,180,90)) } diff --git a/R/valid.R b/R/valid.R index d97f3e856..851f6904f 100644 --- a/R/valid.R +++ b/R/valid.R @@ -83,8 +83,11 @@ st_make_valid.sfc = function(x, ..., oriented = FALSE, s2_options = s2::s2_optio s2 = s2::as_s2_geography(st_as_binary(st_set_precision(x, 0.0)), oriented = oriented, check = FALSE) if (st_precision(x) != 0 && missing(s2_options)) s2_options = s2::s2_options(snap = s2::s2_snap_precision(st_precision(x)), ...) + full = st_is_full(x) # workaround, see https://github.com/r-spatial/s2/issues/262 s2 = s2::s2_rebuild(s2, s2_options) - st_as_sfc(s2, crs = crs) + ret = st_as_sfc(s2, crs = crs) + ret[full] = st_polygon(list(POLYGON_FULL)) + ret } else if (compareVersion(CPL_geos_version(), "3.8.0") == -1) { if (!missing(geos_method) || !missing(geos_keep_collapsed)) warning("ignoring arguments geos_method and geos_keep_collapsed, as these require GEOS >= 3.8.0") diff --git a/R/wkt.R b/R/wkt.R index dc73c1346..4c3c58941 100644 --- a/R/wkt.R +++ b/R/wkt.R @@ -57,9 +57,9 @@ prnt.MULTIPOINT = function(x, ..., EWKT = TRUE, nested_parens = FALSE) { prnt.Matrix(x, nested_parens = nested_parens, ...)) } prnt.LINESTRING = function(x, ..., EWKT = TRUE) paste(WKT_name(x, EWKT = EWKT), prnt.Matrix(x, ...)) -POLYGON_FULL = matrix(c(0,-90,0,-90), 2, byrow = TRUE) + prnt.POLYGON = function(x, ..., EWKT = TRUE) { - if (!is.null(crs <- list(...)$crs) && st_is_longlat(crs) && length(x) && nrow(x[[1]]) == 2 && identical(x[[1]], POLYGON_FULL)) + if (st_is_full(x, ...)) "POLYGON FULL" else paste(WKT_name(x, EWKT = EWKT), prnt.MatrixList(x, ...)) @@ -171,8 +171,8 @@ st_as_sfc.character = function(x, crs = NA_integer_, ..., GeoJSON = FALSE) { } x = ewkt_to_wkt(x) } - if (isTRUE(st_is_longlat(crs)) && any(full <- (x == "POLYGON FULL"))) - x[full] = "POLYGON((0 -90,0 -90))" # s2 code for POLYGON FULL + if (sf_use_s2() && !identical(st_is_longlat(crs), FALSE) && any(full <- (x == "POLYGON FULL"))) + x[full] = "POLYGON((0 -90,0 -90))" # s2 struct for POLYGON FULL ret = st_sfc(CPL_sfc_from_wkt(x)) st_crs(ret) = crs ret diff --git a/man/geos_binary_pred.Rd b/man/geos_binary_pred.Rd index 9c26b29ec..bf4143697 100644 --- a/man/geos_binary_pred.Rd +++ b/man/geos_binary_pred.Rd @@ -19,7 +19,7 @@ \usage{ st_intersects(x, y, sparse = TRUE, ...) -st_disjoint(x, y = x, sparse = TRUE, prepared = TRUE) +st_disjoint(x, y = x, sparse = TRUE, prepared = TRUE, ...) st_touches(x, y, sparse = TRUE, prepared = TRUE, ...) diff --git a/man/st_bbox.Rd b/man/st_bbox.Rd index c6b34ec5b..270d71b9f 100644 --- a/man/st_bbox.Rd +++ b/man/st_bbox.Rd @@ -26,9 +26,12 @@ \alias{st_bbox.Extent} \alias{st_bbox.numeric} \alias{NA_bbox_} +\alias{FULL_bbox_} \alias{format.bbox} \title{Return bounding of a simple feature or simple feature set} \format{ +An object of class \code{bbox} of length 4. + An object of class \code{bbox} of length 4. } \usage{ @@ -80,6 +83,8 @@ st_bbox(obj, ...) NA_bbox_ +FULL_bbox_ + \method{format}{bbox}(x, ...) } \arguments{ @@ -103,6 +108,8 @@ methods for \code{bbox} objects to generate a polygon around the four bounding b Return bounding of a simple feature or simple feature set } \details{ +\code{NA_bbox_} represents the missing value for a \code{bbox} object + \code{NA_bbox_} represents the missing value for a \code{bbox} object } \examples{ diff --git a/tests/full.R b/tests/full.R new file mode 100644 index 000000000..fd2883a1f --- /dev/null +++ b/tests/full.R @@ -0,0 +1,27 @@ +suppressPackageStartupMessages(library(sf)) + +# create full polygon: +(f = st_as_sfc("POLYGON FULL")) +g = st_sfc(st_polygon(list(matrix(c(0,-90,0,-90), 2, byrow = TRUE)))) +identical(f, g) +old = sf_use_s2(FALSE) +try(st_as_sfc("POLYGON FULL")) # errors +sf_use_s2(old) +(f = st_as_sfc(c("POLYGON FULL", "POLYGON((0 0,1 0,1 1,0 1,0 0))"))) +st_is_full(f) +st_bbox(f[1]) +st_bbox(f[2]) +st_is_valid(f) # full polygon NA: right, we don't know the CRS +st_crs(f) = 'OGC:CRS84' # geodetic: +st_is_valid(f) +st_crs(f) = NA +try(st_make_valid(f)) +st_crs(f) = 'OGC:CRS84' # geodetic: +st_make_valid(f) +# mixed geometries: +(f = st_as_sfc(c("POLYGON FULL", "POLYGON((0 0,1 0,1 1,0 1,0 0))", "POINT(0 1)"), crs = 'OGC:CRS84')) +st_bbox(f[1]) +st_bbox(f[3]) +st_is_valid(f) +st_make_valid(f) +st_make_valid(f[2:3]) diff --git a/tests/full.Rout.save b/tests/full.Rout.save new file mode 100644 index 000000000..d35622c3e --- /dev/null +++ b/tests/full.Rout.save @@ -0,0 +1,110 @@ + +R version 4.4.1 (2024-06-14) -- "Race for Your Life" +Copyright (C) 2024 The R Foundation for Statistical Computing +Platform: x86_64-pc-linux-gnu + +R is free software and comes with ABSOLUTELY NO WARRANTY. +You are welcome to redistribute it under certain conditions. +Type 'license()' or 'licence()' for distribution details. + +R is a collaborative project with many contributors. +Type 'contributors()' for more information and +'citation()' on how to cite R or R packages in publications. + +Type 'demo()' for some demos, 'help()' for on-line help, or +'help.start()' for an HTML browser interface to help. +Type 'q()' to quit R. + +> suppressPackageStartupMessages(library(sf)) +> +> # create full polygon: +> (f = st_as_sfc("POLYGON FULL")) +Geometry set for 1 feature +Geometry type: POLYGON +Dimension: XY +Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 +CRS: NA +POLYGON FULL +> g = st_sfc(st_polygon(list(matrix(c(0,-90,0,-90), 2, byrow = TRUE)))) +> identical(f, g) +[1] TRUE +> old = sf_use_s2(FALSE) +Spherical geometry (s2) switched off +> try(st_as_sfc("POLYGON FULL")) # errors +OGR: Corrupt data +Error : OGR error +> sf_use_s2(old) +Spherical geometry (s2) switched on +> (f = st_as_sfc(c("POLYGON FULL", "POLYGON((0 0,1 0,1 1,0 1,0 0))"))) +Geometry set for 2 features +Geometry type: POLYGON +Dimension: XY +Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 +CRS: NA +POLYGON FULL +POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) +> st_is_full(f) +[1] TRUE FALSE +> st_bbox(f[1]) +xmin ymin xmax ymax +-180 -90 180 90 +> st_bbox(f[2]) +xmin ymin xmax ymax + 0 0 1 1 +> st_is_valid(f) # full polygon NA: right, we don't know the CRS +[1] NA TRUE +> st_crs(f) = 'OGC:CRS84' # geodetic: +> st_is_valid(f) +[1] TRUE TRUE +> st_crs(f) = NA +> try(st_make_valid(f)) +Error in (function (msg) : + IllegalArgumentException: Invalid number of points in LinearRing found 2 - must be 0 or >= 3 +> st_crs(f) = 'OGC:CRS84' # geodetic: +> st_make_valid(f) +Geometry set for 2 features +Geometry type: POLYGON +Dimension: XY +Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 +Geodetic CRS: WGS 84 (CRS84) +POLYGON FULL +POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) +> # mixed geometries: +> (f = st_as_sfc(c("POLYGON FULL", "POLYGON((0 0,1 0,1 1,0 1,0 0))", "POINT(0 1)"), crs = 'OGC:CRS84')) +Geometry set for 3 features +Geometry type: GEOMETRY +Dimension: XY +Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 +Geodetic CRS: WGS 84 (CRS84) +POLYGON FULL +POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) +POINT (0 1) +> st_bbox(f[1]) +xmin ymin xmax ymax +-180 -90 180 90 +> st_bbox(f[3]) +xmin ymin xmax ymax + 0 1 0 1 +> st_is_valid(f) +[1] TRUE TRUE TRUE +> st_make_valid(f) +Geometry set for 3 features +Geometry type: GEOMETRY +Dimension: XY +Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 +Geodetic CRS: WGS 84 (CRS84) +POLYGON FULL +POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) +POINT (0 1) +> st_make_valid(f[2:3]) +Geometry set for 2 features +Geometry type: GEOMETRY +Dimension: XY +Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 +Geodetic CRS: WGS 84 (CRS84) +POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) +POINT (0 1) +> +> proc.time() + user system elapsed + 0.530 1.356 0.467 diff --git a/vignettes/sf7.Rmd b/vignettes/sf7.Rmd index e557d0097..030ddda47 100644 --- a/vignettes/sf7.Rmd +++ b/vignettes/sf7.Rmd @@ -22,23 +22,15 @@ knitr::opts_chunk$set(collapse = TRUE) This vignette describes what spherical geometry implies, and how package `sf` uses the s2geometry library (http://s2geometry.io) -for geometrical measures, predicates and transformations. The code -in this vignette only runs if `s2` has been installed, e.g. with - -```{r, eval=FALSE} -install.packages("s2") -``` - -and is available. After `sf` has been loaded, you can check if `s2` -is being used: +for geometrical measures, predicates and transformations. +After `sf` has been loaded, it will report whether `s2` is being +used; it can be switched off (resorting to flat space geometry) +by `sf_use_s2(FALSE)`. ```{r} library(sf) -sf_use_s2() ``` -Attach the `s2` package as follows: - ```{r} library(s2) ``` @@ -148,33 +140,38 @@ s2_area(st_as_s2(nc, oriented = TRUE)[1:3]) # wrong direction: Earth's surface m nc = read_sf(system.file("gpkg/nc.gpkg", package="sf"), check_ring_dir = TRUE) s2_area(st_as_s2(nc, oriented = TRUE)[1:3]) # no second correction needed here: ``` +The default conversion from `sf` to `s2` uses `oriented = FALSE`, so that we +get +```{r} +all(units::drop_units(st_area(nc)) == s2_area(st_as_s2(nc, oriented = FALSE))) +``` + Here is an example where the oceans are computed as the difference from the full polygon representing the entire globe, ```{r} -g = as_s2_geography(TRUE) +g = st_as_sfc("POLYGON FULL", crs = 'EPSG:4326') g ``` and the countries, and shown in an orthographic projection: ```{r} -co = s2_data_countries() -oc = s2_difference(g, s2_union_agg(co)) # oceans -b = s2_buffer_cells(as_s2_geography("POINT(-30 52)"), 9800000) # visible half -i = s2_intersection(b, oc) # visible ocean -plot(st_transform(st_as_sfc(i), "+proj=ortho +lat_0=52 +lon_0=-30"), col = 'blue') +options(s2_oriented = TRUE) # don't change orientation from here on +co = st_as_sf(s2_data_countries()) +oc = st_difference(g, st_union(co)) # oceans +b = st_buffer(st_as_sfc("POINT(-30 52)", crs = 'EPSG:4326'), 9800000) # visible half +i = st_intersection(b, oc) # visible ocean +plot(st_transform(i, "+proj=ortho +lat_0=52 +lon_0=-30"), col = 'blue') ``` -(Note that the WKT printing of the full polygon `g` is not valid WKT, -and can not be used as input as it doesn't follow the simple feature -standard; it seems to reflect the internal representation of the -full polygon, and would require a WKT extension). +(Note that the printing of `POLYGON FULL` is not valid WKT according +to the simple feature standard, which does not include this.) We can now calculate the proportion of the Earth's surface covered by oceans: ```{r} -s2_area(oc) / s2_area(g) +st_area(oc) / st_area(g) ``` @@ -202,12 +199,12 @@ where every grid cell (typically) only contains its upper-left corner and its upper and left sides. ```{r} -a = as_s2_geography("POINT(0 0)") -b = as_s2_geography("POLYGON((0 0,1 0,1 1,0 1,0 0))") -s2_intersects(a, b, s2_options(model = "open")) -s2_intersects(a, b, s2_options(model = "closed")) -s2_intersects(a, b, s2_options(model = "semi-open")) # a toss -s2_intersects(a, b) # default: semi-open +a = st_as_sfc("POINT(0 0)", crs = 'EPSG:4326') +b = st_as_sfc("POLYGON((0 0,1 0,1 1,0 1,0 0))", crs = 'EPSG:4326') +st_intersects(a, b, model = "open") +st_intersects(a, b, model = "closed") +st_intersects(a, b, model = "semi-open") # a toss +st_intersects(a, b) # default: closed ``` ## Bounding cap, bounding rectangle @@ -257,6 +254,7 @@ sf_use_s2(TRUE) ## Area ```{r eval=require("lwgeom", quietly = TRUE)} +options(s2_oriented = FALSE) # correct orientation from here on library(sf) library(units) nc = read_sf(system.file("gpkg/nc.gpkg", package="sf")) @@ -323,14 +321,14 @@ using an unprojected object representing the UK as an example: uk = s2_data_countries("United Kingdom") class(uk) uk_sfc = st_as_sfc(uk) -uk_buffer = s2_buffer_cells(uk, distance = 20000) -uk_buffer2 = s2_buffer_cells(uk, distance = 20000, max_cells = 10000) -uk_buffer3 = s2_buffer_cells(uk, distance = 20000, max_cells = 100) +uk_buffer = st_buffer(uk_sfc, dist = 20000) +uk_buffer2 = st_buffer(uk_sfc, dist = 20000, max_cells = 10000) +uk_buffer3 = st_buffer(uk_sfc, dist = 20000, max_cells = 100) class(uk_buffer) plot(uk_sfc) -plot(st_as_sfc(uk_buffer)) -plot(st_as_sfc(uk_buffer2)) -plot(st_as_sfc(uk_buffer3)) +plot(uk_buffer) +plot(uk_buffer2) +plot(uk_buffer3) uk_sf = st_as_sf(uk) ``` From 55455077bee7931478bea4da3818a17ab16cb3b9 Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 20 Sep 2024 22:07:16 +0200 Subject: [PATCH 18/70] news for #2441 --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index e4ddcdf7a..9091c6ab0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # version 1.0-17 +* support `POLYGON FULL` simple feature geometry, representing the the entire Earth surface; #2441 + * add `st_transform()` method for `bbox` objects; this uses OGRCoordinateTransformation::TransformBounds(), densifying first and antemeridian proof; #2415 * `st_filter.sf()` correctly scopes `x` and `y` arguments using !! operator; #2416 From 4028763a81fb9ed30b72bfd5a2e3ad2472233c34 Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 20 Sep 2024 23:02:41 +0200 Subject: [PATCH 19/70] add POLYGON FULL roundtrip through gpkg; #2441 --- R/read.R | 2 -- src/gdal_read.cpp | 2 +- tests/full.R | 6 ++++++ tests/full.Rout.save | 19 ++++++++++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/R/read.R b/R/read.R index 98245ebac..bcf52e6b6 100644 --- a/R/read.R +++ b/R/read.R @@ -295,8 +295,6 @@ st_read.character = function(dsn, layer, ..., query = NA, options = NULL, quiet if (length(promote_to_multi) > 1) stop("`promote_to_multi' should have length one, and applies to all geometry columns") - - if (use_stream) { stream = nanoarrow::nanoarrow_allocate_array_stream() info = CPL_read_gdal_stream(stream, dsn, layer, query, as.character(options), quiet, diff --git a/src/gdal_read.cpp b/src/gdal_read.cpp index a7c42053d..3dc20e119 100644 --- a/src/gdal_read.cpp +++ b/src/gdal_read.cpp @@ -115,7 +115,7 @@ OGRwkbGeometryType to_multi_what(std::vector gv) { return wkbMultiPoint; if (lines && multilines) return wkbMultiLineString; - if (!lines && !multilines) + if (polygons && multipolygons) return wkbMultiPolygon; } // another mix or single type: diff --git a/tests/full.R b/tests/full.R index fd2883a1f..fb5dcf99e 100644 --- a/tests/full.R +++ b/tests/full.R @@ -25,3 +25,9 @@ st_bbox(f[3]) st_is_valid(f) st_make_valid(f) st_make_valid(f[2:3]) + +# roundtrip: +sf = st_as_sf(data.frame(attr = 1:3, geom = f[1:3])) +write_sf(sf, fn <- tempfile(fileext=".gpkg")) +g = read_sf(fn) +g diff --git a/tests/full.Rout.save b/tests/full.Rout.save index d35622c3e..2c19bb5f3 100644 --- a/tests/full.Rout.save +++ b/tests/full.Rout.save @@ -105,6 +105,23 @@ Geodetic CRS: WGS 84 (CRS84) POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) POINT (0 1) > +> # roundtrip: +> sf = st_as_sf(data.frame(attr = 1:3, geom = f[1:3])) +> write_sf(sf, fn <- tempfile(fileext=".gpkg")) +> g = read_sf(fn) +> g +Simple feature collection with 3 features and 1 field +Geometry type: GEOMETRY +Dimension: XY +Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 +Geodetic CRS: WGS 84 (CRS84) +# A tibble: 3 × 2 + attr geom + +1 1 POLYGON FULL +2 2 POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) +3 3 POINT (0 1) +> > proc.time() user system elapsed - 0.530 1.356 0.467 + 0.767 1.331 0.742 From 436c2938eefac117013b446af97cb7e09488af50 Mon Sep 17 00:00:00 2001 From: edzer Date: Thu, 26 Sep 2024 22:05:04 +0200 Subject: [PATCH 20/70] update for #2441 --- R/RcppExports.R | 4 ++++ R/geom-predicates.R | 13 +++++++++++-- R/sfc.R | 7 ++++++- src/RcppExports.cpp | 12 ++++++++++++ src/sfc-sfg.cpp | 20 ++++++++++++++++++++ tests/full.R | 5 +++++ tests/full.Rout.save | 11 ++++++++++- 7 files changed, 68 insertions(+), 4 deletions(-) diff --git a/R/RcppExports.R b/R/RcppExports.R index f7946d9a3..f4d9d07d3 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -361,6 +361,10 @@ sfc_is_empty <- function(sfc) { .Call(`_sf_sfc_is_empty`, sfc) } +sfc_is_full <- function(sfc) { + .Call(`_sf_sfc_is_full`, sfc) +} + points_cpp <- function(pts, gdim = "XY") { .Call(`_sf_points_cpp`, pts, gdim) } diff --git a/R/geom-predicates.R b/R/geom-predicates.R index 170fea2dd..44ad608f3 100644 --- a/R/geom-predicates.R +++ b/R/geom-predicates.R @@ -4,7 +4,13 @@ #' @examples #' ls = st_linestring(rbind(c(0,0), c(1,1), c(1,0), c(0,1))) #' st_is_simple(st_sfc(ls, st_point(c(0,0)))) -st_is_simple = function(x) CPL_geos_is_simple(st_geometry(x)) +st_is_simple = function(x) { + x = st_geometry(x) + not_full = !sfc_is_full(x) + ret = rep(TRUE, length(x)) + ret[not_full] = CPL_geos_is_simple(x[not_full]) + ret +} #' @name geos_query #' @export @@ -12,7 +18,10 @@ st_is_simple = function(x) CPL_geos_is_simple(st_geometry(x)) #' @examples #' ls = st_linestring(rbind(c(0,0), c(1,1), c(1,0), c(0,1))) #' st_is_empty(st_sfc(ls, st_point(), st_linestring())) -st_is_empty = function(x) CPL_geos_is_empty(st_geometry(x)) +st_is_empty = function(x) sfc_is_empty(st_geometry(x)) + # used to call + # CPL_geos_is_empty(st_geometry(x)) + # but this avoids a R -> WKB -> GEOS conversion is_symmetric = function(operation, pattern) { if (!is.na(pattern)) { diff --git a/R/sfc.R b/R/sfc.R index 65b822d29..33a7c1875 100644 --- a/R/sfc.R +++ b/R/sfc.R @@ -623,6 +623,7 @@ POLYGON_FULL = matrix(c(0,-90,0,-90), 2, byrow = TRUE) st_is_full = function(x, ...) UseMethod("st_is_full") #' @export +#' @name st_is_full #' @param is_longlat logical; output of \link{st_is_longlat} of the parent `sfc` object st_is_full.sfg = function(x, ..., is_longlat = NULL) { if (identical(is_longlat, FALSE)) # we know these are Cartesian coordinates: @@ -633,23 +634,27 @@ st_is_full.sfg = function(x, ..., is_longlat = NULL) { } #' @export +#' @name st_is_full st_is_full.sfc = function(x, ...) { if (sf_use_s2() && inherits(x, c("sfc_POLYGON", "sfc_GEOMETRY"))) { is_longlat = if (!is.null(attr(x, "crs"))) st_is_longlat(x) else NA - sapply(x, st_is_full.sfg, ..., is_longlat = is_longlat) + #sapply(x, st_is_full.sfg, ..., is_longlat = is_longlat) + sfc_is_full(x) } else rep_len(FALSE, length(x)) } #' @export +#' @name st_is_full st_is_full.sf = function(x, ...) { st_is_full(st_geometry(x), ...) } #' @export +#' @name st_is_full st_is_full.bbox = function(x, ...) { sf_use_s2() && st_is_longlat(x) && all(x == c(-180,-90,180,90)) } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index cfbd35a4e..56586fa7a 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -1229,6 +1229,17 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// sfc_is_full +LogicalVector sfc_is_full(List sfc); +RcppExport SEXP _sf_sfc_is_full(SEXP sfcSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< List >::type sfc(sfcSEXP); + rcpp_result_gen = Rcpp::wrap(sfc_is_full(sfc)); + return rcpp_result_gen; +END_RCPP +} // points_cpp List points_cpp(NumericMatrix pts, CharacterVector gdim); RcppExport SEXP _sf_points_cpp(SEXP ptsSEXP, SEXP gdimSEXP) { @@ -1560,6 +1571,7 @@ static const R_CallMethodDef CallEntries[] = { {"_sf_sfc_is_null", (DL_FUNC) &_sf_sfc_is_null, 1}, {"_sf_sfc_unique_sfg_dims_and_types", (DL_FUNC) &_sf_sfc_unique_sfg_dims_and_types, 1}, {"_sf_sfc_is_empty", (DL_FUNC) &_sf_sfc_is_empty, 1}, + {"_sf_sfc_is_full", (DL_FUNC) &_sf_sfc_is_full, 1}, {"_sf_points_cpp", (DL_FUNC) &_sf_points_cpp, 2}, {"_sf_CPL_signed_area", (DL_FUNC) &_sf_CPL_signed_area, 1}, {"_sf_CPL_get_metadata", (DL_FUNC) &_sf_CPL_get_metadata, 3}, diff --git a/src/sfc-sfg.cpp b/src/sfc-sfg.cpp index aa5a5a40f..ff25eb5c6 100644 --- a/src/sfc-sfg.cpp +++ b/src/sfc-sfg.cpp @@ -130,6 +130,26 @@ LogicalVector sfc_is_empty(List sfc) { return out; } +// [[Rcpp::export]] +LogicalVector sfc_is_full(List sfc) { + LogicalVector out(sfc.size()); + + SEXP item; + + for (R_xlen_t i = 0; i < sfc.size(); i++) { + item = sfc[i]; + int item_len = Rf_length(item); + bool is_full = false; + if (item_len == 1 && Rf_inherits(item, "POLYGON")) { + SEXP m = VECTOR_ELT(item, 0); + if (Rf_isMatrix(m) && Rf_nrows(m) == 2) /* we can go on and check the values, but... */ + is_full = true; + } + out[i] = is_full; + } + return out; +} + // [[Rcpp::export]] List points_cpp(NumericMatrix pts, CharacterVector gdim = "XY") { int n = pts.nrow(); diff --git a/tests/full.R b/tests/full.R index fb5dcf99e..a4625677e 100644 --- a/tests/full.R +++ b/tests/full.R @@ -31,3 +31,8 @@ sf = st_as_sf(data.frame(attr = 1:3, geom = f[1:3])) write_sf(sf, fn <- tempfile(fileext=".gpkg")) g = read_sf(fn) g + +st_is_empty(g) +st_is_full(g) +st_is_valid(g) +st_is_simple(g) diff --git a/tests/full.Rout.save b/tests/full.Rout.save index 2c19bb5f3..fa3aada11 100644 --- a/tests/full.Rout.save +++ b/tests/full.Rout.save @@ -122,6 +122,15 @@ Geodetic CRS: WGS 84 (CRS84) 2 2 POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) 3 3 POINT (0 1) > +> st_is_empty(g) +[1] FALSE FALSE FALSE +> st_is_full(g) +[1] TRUE FALSE FALSE +> st_is_valid(g) +[1] TRUE TRUE TRUE +> st_is_simple(g) +[1] TRUE TRUE TRUE +> > proc.time() user system elapsed - 0.767 1.331 0.742 + 0.777 1.387 0.661 From 66c5c5d35bdcab5974f31548dbef5c8d075a88f4 Mon Sep 17 00:00:00 2001 From: edzer Date: Thu, 26 Sep 2024 22:15:32 +0200 Subject: [PATCH 21/70] further tests for #2441 --- tests/full.R | 6 +++++- tests/full.Rout.save | 30 ++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/tests/full.R b/tests/full.R index a4625677e..8aace5c0f 100644 --- a/tests/full.R +++ b/tests/full.R @@ -19,7 +19,7 @@ try(st_make_valid(f)) st_crs(f) = 'OGC:CRS84' # geodetic: st_make_valid(f) # mixed geometries: -(f = st_as_sfc(c("POLYGON FULL", "POLYGON((0 0,1 0,1 1,0 1,0 0))", "POINT(0 1)"), crs = 'OGC:CRS84')) +(f = st_as_sfc(c("POLYGON FULL", "POLYGON((0 0,1 0,1 1,0 1,0 0))", "POINT(3 1)"), crs = 'OGC:CRS84')) st_bbox(f[1]) st_bbox(f[3]) st_is_valid(f) @@ -36,3 +36,7 @@ st_is_empty(g) st_is_full(g) st_is_valid(g) st_is_simple(g) +st_dimension(g) +st_area(g) +st_length(g) +st_distance(g) diff --git a/tests/full.Rout.save b/tests/full.Rout.save index fa3aada11..341bf9263 100644 --- a/tests/full.Rout.save +++ b/tests/full.Rout.save @@ -70,7 +70,7 @@ Geodetic CRS: WGS 84 (CRS84) POLYGON FULL POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) > # mixed geometries: -> (f = st_as_sfc(c("POLYGON FULL", "POLYGON((0 0,1 0,1 1,0 1,0 0))", "POINT(0 1)"), crs = 'OGC:CRS84')) +> (f = st_as_sfc(c("POLYGON FULL", "POLYGON((0 0,1 0,1 1,0 1,0 0))", "POINT(3 1)"), crs = 'OGC:CRS84')) Geometry set for 3 features Geometry type: GEOMETRY Dimension: XY @@ -78,13 +78,13 @@ Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 Geodetic CRS: WGS 84 (CRS84) POLYGON FULL POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) -POINT (0 1) +POINT (3 1) > st_bbox(f[1]) xmin ymin xmax ymax -180 -90 180 90 > st_bbox(f[3]) xmin ymin xmax ymax - 0 1 0 1 + 3 1 3 1 > st_is_valid(f) [1] TRUE TRUE TRUE > st_make_valid(f) @@ -95,15 +95,15 @@ Bounding box: xmin: -180 ymin: -90 xmax: 180 ymax: 90 Geodetic CRS: WGS 84 (CRS84) POLYGON FULL POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) -POINT (0 1) +POINT (3 1) > st_make_valid(f[2:3]) Geometry set for 2 features Geometry type: GEOMETRY Dimension: XY -Bounding box: xmin: 0 ymin: 0 xmax: 1 ymax: 1 +Bounding box: xmin: 0 ymin: 0 xmax: 3 ymax: 1 Geodetic CRS: WGS 84 (CRS84) POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) -POINT (0 1) +POINT (3 1) > > # roundtrip: > sf = st_as_sf(data.frame(attr = 1:3, geom = f[1:3])) @@ -120,7 +120,7 @@ Geodetic CRS: WGS 84 (CRS84) 1 1 POLYGON FULL 2 2 POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)) -3 3 POINT (0 1) +3 3 POINT (3 1) > > st_is_empty(g) [1] FALSE FALSE FALSE @@ -130,7 +130,21 @@ Geodetic CRS: WGS 84 (CRS84) [1] TRUE TRUE TRUE > st_is_simple(g) [1] TRUE TRUE TRUE +> st_dimension(g) +[1] 2 2 0 +> st_area(g) +Units: [m^2] +[1] 5.100661e+14 1.236404e+10 0.000000e+00 +> st_length(g) +Units: [m] +[1] 0 0 0 +> st_distance(g) +Units: [m] + [,1] [,2] [,3] +[1,] 0 0.0 0.0 +[2,] 0 0.0 222356.3 +[3,] 0 222356.3 0.0 > > proc.time() user system elapsed - 0.777 1.387 0.661 + 0.746 1.417 0.668 From f9a94fdeef6410069746de2567d71be06b566de1 Mon Sep 17 00:00:00 2001 From: edzer Date: Thu, 26 Sep 2024 22:19:12 +0200 Subject: [PATCH 22/70] update news --- NEWS.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 9091c6ab0..d056a6457 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,9 @@ -# version 1.0-17 +# version 1.0-18 * support `POLYGON FULL` simple feature geometry, representing the the entire Earth surface; #2441 +# version 1.0-17 + * add `st_transform()` method for `bbox` objects; this uses OGRCoordinateTransformation::TransformBounds(), densifying first and antemeridian proof; #2415 * `st_filter.sf()` correctly scopes `x` and `y` arguments using !! operator; #2416 From 39da056beca597947410db7a46ab71a16ea656a5 Mon Sep 17 00:00:00 2001 From: edzer Date: Fri, 27 Sep 2024 09:11:21 +0200 Subject: [PATCH 23/70] fixes #2448 --- R/init.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/init.R b/R/init.R index eea3ef728..4488157ec 100644 --- a/R/init.R +++ b/R/init.R @@ -26,6 +26,7 @@ setOldClass(c("sfc_GEOMETRY", "sfc")) setOldClass(c("sfc_GEOMETRYCOLLECTION", "sfc")) setOldClass("sfg") setOldClass("crs") +setOldClass("bbox") .sf_cache <- new.env(FALSE, parent=globalenv()) From 49b5fbd18f23d3045278b385879c420ab56bb4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Darius=20A=2E=20G=C3=B6rgen?= Date: Tue, 24 Sep 2024 04:42:30 +0000 Subject: [PATCH 24/70] address #2442 --- NEWS.md | 2 ++ R/geom-transformers.R | 7 ++++++- tests/gdal_geom.R | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 12add0430..610ad4491 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ * fix build failure with GDAL < 3.4.0 #2436 +* `st_simplify()` now accepts feature-wise tolerance values when `s2` is switched on #2442 + # version 1.0-17 * add `st_transform()` method for `bbox` objects; this uses OGRCoordinateTransformation::TransformBounds(), densifying first and antemeridian proof; #2415 diff --git a/R/geom-transformers.R b/R/geom-transformers.R index af13a68e3..1998997ed 100644 --- a/R/geom-transformers.R +++ b/R/geom-transformers.R @@ -286,7 +286,12 @@ st_simplify.sfc = function(x, preserveTopology, dTolerance = 0.0) { if (ll && sf_use_s2()) { if (!missing(preserveTopology) && isFALSE(preserveTopology)) warning("argument preserveTopology cannot be set to FALSE when working with ellipsoidal coordinates since the algorithm behind st_simplify always preserves topological relationships") - st_as_sfc(s2::s2_simplify(x, dTolerance), crs = st_crs(x)) + if (length(dTolerance) == 1) { + st_as_sfc(s2::s2_simplify(x, dTolerance), crs = st_crs(x)) + } else { + simplify <- function(x, dTolerance) st_as_sfc(s2::s2_simplify(x, dTolerance)) + st_as_sfc(mapply(simplify, x, dTolerance), crs = st_crs(x)) + } } else { if (missing(preserveTopology)) { preserveTopology = FALSE diff --git a/tests/gdal_geom.R b/tests/gdal_geom.R index 7785de0be..b18de15ef 100644 --- a/tests/gdal_geom.R +++ b/tests/gdal_geom.R @@ -20,6 +20,8 @@ x = st_convex_hull(nc) x = st_simplify(nc_tr, dTolerance = 1e4) +x = st_simplify(nc_tr, dTolerance = rep(1e4, nrow(nc_tr))) + x = st_simplify(nc_tr, preserveTopology = TRUE) if (sf:::CPL_geos_version() >= "3.4.0") From 4c893e3bb3c037b8e50e4ee1b20eeed1aa85a401 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 13:55:20 +0200 Subject: [PATCH 25/70] Revert "add sf_make_aware_pgk(); #2131" This reverts commit f5d6da5d57e9ff61b741fb8a461fbbe3487e366e. --- DESCRIPTION | 2 +- NAMESPACE | 4 +--- R/init.R | 2 +- R/sf_aware.R | 17 ++--------------- R/tidyverse.R | 2 -- man/{sf_make_aware.Rd => make_sf_aware.Rd} | 11 +++-------- man/tidyverse.Rd | 7 ------- tests/spatstat.Rout.save | 11 +++++------ 8 files changed, 13 insertions(+), 43 deletions(-) rename man/{sf_make_aware.Rd => make_sf_aware.Rd} (67%) diff --git a/DESCRIPTION b/DESCRIPTION index 6d2f24a37..2de4d715d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -112,7 +112,7 @@ LinkingTo: VignetteBuilder: knitr Encoding: UTF-8 -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) Config/testthat/edition: 2 Config/needs/coverage: XML diff --git a/NAMESPACE b/NAMESPACE index 5f7990594..8fd23209e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -406,14 +406,13 @@ export(gdal_utils) export(gdal_write) export(gdal_write_mdim) export(get_key_pos) +export(make_sf_aware) export(plot_sf) export(rawToHex) export(read_sf) export(sf.colors) export(sf_add_proj_units) export(sf_extSoftVersion) -export(sf_make_aware) -export(sf_make_aware_pkg) export(sf_proj_info) export(sf_proj_network) export(sf_proj_pipelines) @@ -580,7 +579,6 @@ importFrom(units,as_units) importFrom(units,drop_units) importFrom(units,make_unit_label) importFrom(units,set_units) -importFrom(utils,assignInMyNamespace) importFrom(utils,compareVersion) importFrom(utils,globalVariables) importFrom(utils,head) diff --git a/R/init.R b/R/init.R index 0ce76a31b..4488157ec 100644 --- a/R/init.R +++ b/R/init.R @@ -1,4 +1,4 @@ -#' @importFrom utils head tail object.size str packageVersion compareVersion globalVariables assignInMyNamespace +#' @importFrom utils head object.size str tail packageVersion compareVersion globalVariables #' @importFrom stats aggregate dist na.omit rbinom runif setNames #' @importFrom tools file_ext file_path_sans_ext #' @importFrom methods as new slot slotNames slot<- diff --git a/R/sf_aware.R b/R/sf_aware.R index 7438edc34..5f1fc265d 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -5,6 +5,7 @@ # the feature was introduced (Jul 23, 2024). # New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). known_sf_aware <- c(".globalenv", "sf", "base", "utils", "stats", + "rsample", # called by spatialsample "od", # only imports sfheaders; used by abstr "igr", # published Jul 27, 2024 "weatherOz", # published Jul 26, 2024 @@ -30,27 +31,13 @@ known_sf_aware <- c(".globalenv", "sf", "base", "utils", "stats", #' for packages: use the sticky geometry [ behaviour of sf in package code #' #' for packages: use the sticky geometry [ behaviour of sf in package code -#' @name sf_make_aware #' @param env environment #' @param value logical; default `TRUE` #' @export -sf_make_aware <- function(env = parent.frame(), value = TRUE) { +make_sf_aware <- function(env = parent.frame(), value = TRUE) { env$.__sf_aware__. <- value } -#' @export -#' @name sf_make_aware -#' @param pkg package name -sf_make_aware_pkg <- function(pkg) { - stopifnot(is.character(pkg), length(pkg) == 1) - old = known_sf_aware - if (pkg %in% old) - message(paste("package", pkg, "is already sf-aware")) - else - utils::assignInMyNamespace("known_sf_aware", c(pkg, known_sf_aware)) - invisible(old) -} - is_sf_aware <- function(env = parent.frame(2)) { top <- topenv(env) diff --git a/R/tidyverse.R b/R/tidyverse.R index 48cb4b70c..1626b0bbd 100644 --- a/R/tidyverse.R +++ b/R/tidyverse.R @@ -177,8 +177,6 @@ select.sf <- function(.data, ...) { } #' @name tidyverse -#' @param .before see original docs -#' @param .after see original docs relocate.sf = function(.data, ..., .before = NULL, .after = NULL) { st_as_sf(NextMethod()) } diff --git a/man/sf_make_aware.Rd b/man/make_sf_aware.Rd similarity index 67% rename from man/sf_make_aware.Rd rename to man/make_sf_aware.Rd index abbfc04f8..2b10f5a28 100644 --- a/man/sf_make_aware.Rd +++ b/man/make_sf_aware.Rd @@ -1,20 +1,15 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/sf_aware.R -\name{sf_make_aware} -\alias{sf_make_aware} -\alias{sf_make_aware_pkg} +\name{make_sf_aware} +\alias{make_sf_aware} \title{for packages: use the sticky geometry [ behaviour of sf in package code} \usage{ -sf_make_aware(env = parent.frame(), value = TRUE) - -sf_make_aware_pkg(pkg) +make_sf_aware(env = parent.frame(), value = TRUE) } \arguments{ \item{env}{environment} \item{value}{logical; default \code{TRUE}} - -\item{pkg}{package name} } \description{ for packages: use the sticky geometry [ behaviour of sf in package code diff --git a/man/tidyverse.Rd b/man/tidyverse.Rd index 86820f722..1ec7b2eb0 100644 --- a/man/tidyverse.Rd +++ b/man/tidyverse.Rd @@ -10,7 +10,6 @@ \alias{mutate.sf} \alias{transmute.sf} \alias{select.sf} -\alias{relocate.sf} \alias{rename.sf} \alias{rename_with.sf} \alias{slice.sf} @@ -54,8 +53,6 @@ transmute.sf(.data, ..., .dots) select.sf(.data, ...) -relocate.sf(.data, ..., .before = NULL, .after = NULL) - rename.sf(.data, ...) rename_with.sf(.data, .fn, .cols, ...) @@ -181,10 +178,6 @@ anti_join.sf(x, y, by = NULL, copy = FALSE, suffix = c(".x", ".y"), ...) lazy data frames (e.g. from dbplyr or dtplyr). See \emph{Methods}, below, for more details.} -\item{.before}{see original docs} - -\item{.after}{see original docs} - \item{.fn, .cols}{see original docs} \item{do_union}{logical; in case \code{summary} does not create a geometry column, should geometries be created by unioning using \link{st_union}, or simply by combining using \link{st_combine}? Using \link{st_union} resolves internal boundaries, but in case of unioning points, this will likely change the order of the points; see Details.} diff --git a/tests/spatstat.Rout.save b/tests/spatstat.Rout.save index 97d9fc4ef..1e9f3ec58 100644 --- a/tests/spatstat.Rout.save +++ b/tests/spatstat.Rout.save @@ -1,7 +1,7 @@ -R version 4.4.1 (2024-06-14) -- "Race for Your Life" +R version 4.3.3 (2024-02-29) -- "Angel Food Cake" Copyright (C) 2024 The R Foundation for Statistical Computing -Platform: x86_64-pc-linux-gnu +Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. @@ -126,9 +126,8 @@ Type 'q()' to quit R. + (y = st_as_sfc(as.psp(sf))) + all.equal(st_geometry(x), y) + } -spatstat.univar 3.0-0 -spatstat.geom 3.3-2 -spatstat.random 3.3-1 +spatstat.geom 3.2-9 +spatstat.random 3.2-3 Simple feature collection with 51 features and 1 field Geometry type: GEOMETRY Dimension: XY @@ -168,4 +167,4 @@ In st_as_sfc.owin(spatstat.geom::as.owin(x)) : > > proc.time() user system elapsed - 1.768 1.389 1.788 + 2.074 1.308 1.918 From 50e90bdcd061f2cd6b6ffd1dac6050b2c17d5789 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 13:55:54 +0200 Subject: [PATCH 26/70] Revert "add new packages importing sf; #2131" This reverts commit 15786910f0330a624672912c5cfa65088bd7860c. --- R/sf_aware.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/sf_aware.R b/R/sf_aware.R index 5f1fc265d..1d0bba48b 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -7,8 +7,6 @@ known_sf_aware <- c(".globalenv", "sf", "base", "utils", "stats", "rsample", # called by spatialsample "od", # only imports sfheaders; used by abstr - "igr", # published Jul 27, 2024 - "weatherOz", # published Jul 26, 2024 "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") # Register environment as sf-aware. We use a lexical flag instead of From 64a6fce525e61e0a582831f4c2c96cf38ce97354 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 13:56:30 +0200 Subject: [PATCH 27/70] Revert "add relocate.sf, to make ARUtools pass check; #2131" This reverts commit 4b30e55b7194c96bd4f6e042b01a93fa253652df. --- R/tidyverse.R | 6 ------ 1 file changed, 6 deletions(-) diff --git a/R/tidyverse.R b/R/tidyverse.R index 1626b0bbd..7e2ddc83d 100644 --- a/R/tidyverse.R +++ b/R/tidyverse.R @@ -176,11 +176,6 @@ select.sf <- function(.data, ...) { st_set_agr(st_as_sf(ret, sf_column_name = sf_column), new_agr) } -#' @name tidyverse -relocate.sf = function(.data, ..., .before = NULL, .after = NULL) { - st_as_sf(NextMethod()) -} - #' @name tidyverse #' @examples @@ -683,7 +678,6 @@ register_all_s3_methods = function() { s3_register("dplyr::inner_join", "sf") s3_register("dplyr::left_join", "sf") s3_register("dplyr::mutate", "sf") - s3_register("dplyr::relocate", "sf") s3_register("dplyr::rename", "sf") s3_register("dplyr::rename_with", "sf") s3_register("dplyr::right_join", "sf") From 63fd2005f69a1b0dc70484955161e30dc85a43d8 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 13:56:44 +0200 Subject: [PATCH 28/70] Revert "add packages; #2131" This reverts commit d7c8f207e4df4e82557496dc9a98047380ecc0d1. --- R/sf_aware.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/sf_aware.R b/R/sf_aware.R index 1d0bba48b..c48b28edb 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -4,9 +4,7 @@ # packages that are already depending on sf-awareness at the time # the feature was introduced (Jul 23, 2024). # New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). -known_sf_aware <- c(".globalenv", "sf", "base", "utils", "stats", - "rsample", # called by spatialsample - "od", # only imports sfheaders; used by abstr +known_sf_aware <- c(".globalenv", "sf", "base", "utils", "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") # Register environment as sf-aware. We use a lexical flag instead of From 7d903115b61908cb9c60b86f541f57f9586ec449 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 13:56:59 +0200 Subject: [PATCH 29/70] Revert "handle drop=TRUE if non-aware; #2131" This reverts commit 04579817a499210eae7b3a27ebed573d2cd51ca6. --- R/sf.R | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/R/sf.R b/R/sf.R index 6247e04c8..ae7ed0ac9 100644 --- a/R/sf.R +++ b/R/sf.R @@ -375,13 +375,8 @@ st_sf = function(..., agr = NA_agr_, row.names, st_set_agr(x, agr[match(setdiff(names(x), sf_column), names(agr))]) } else structure(x, class = setdiff(class(x), "sf")) - } else { - ret = NextMethod() - if (inherits(ret, "sf")) - structure(NextMethod(), class = setdiff(class(ret), "sf")) - else - ret - } + } else + structure(NextMethod(), class = setdiff(class(x), "sf")) } #' @export From 64e2259c7eccb1cc4844f94dde7fa02420d82de7 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 13:57:18 +0200 Subject: [PATCH 30/70] Revert "add pkg utils to sf-aware list; #2131" This reverts commit 7ed9436eb2e47a5ecfd0203a6de9dfc88c24e998. --- R/sf_aware.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/sf_aware.R b/R/sf_aware.R index c48b28edb..c79e680a8 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -4,7 +4,7 @@ # packages that are already depending on sf-awareness at the time # the feature was introduced (Jul 23, 2024). # New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). -known_sf_aware <- c(".globalenv", "sf", "base", "utils", +known_sf_aware <- c(".globalenv", "sf", "base", "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") # Register environment as sf-aware. We use a lexical flag instead of From 45e06344ebcc41c1c1d260eddb67e48d4245a3ed Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 13:57:37 +0200 Subject: [PATCH 31/70] Revert "strip sf class in [.sf in case of sf-unaware; #2131" This reverts commit 70d0318722171df189900562c63d22179a6c722f. --- R/sf.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/sf.R b/R/sf.R index ae7ed0ac9..7989e7f35 100644 --- a/R/sf.R +++ b/R/sf.R @@ -376,7 +376,7 @@ st_sf = function(..., agr = NA_agr_, row.names, } else structure(x, class = setdiff(class(x), "sf")) } else - structure(NextMethod(), class = setdiff(class(x), "sf")) + NextMethod() } #' @export From 17276a083520819457129c7d42c3e540b3dae754 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 13:58:01 +0200 Subject: [PATCH 32/70] Revert "add pkg base; #2131" This reverts commit c6a2bf6596c7bbaf42e15611ea2018fd7c53821f. --- R/sf_aware.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/sf_aware.R b/R/sf_aware.R index c79e680a8..db1bba126 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -4,7 +4,7 @@ # packages that are already depending on sf-awareness at the time # the feature was introduced (Jul 23, 2024). # New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). -known_sf_aware <- c(".globalenv", "sf", "base", +known_sf_aware <- c(".globalenv", "sf", "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") # Register environment as sf-aware. We use a lexical flag instead of From a448b6955e140371dc167c899518a8b21fb649be Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 13:58:12 +0200 Subject: [PATCH 33/70] Revert "pass R CMD check; #2131" This reverts commit 8574c4c1136962f3456520a32e0fc65d5de6a722. --- R/sf_aware.R | 6 +++--- man/make_sf_aware.Rd | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/R/sf_aware.R b/R/sf_aware.R index db1bba126..301ae1be2 100644 --- a/R/sf_aware.R +++ b/R/sf_aware.R @@ -4,7 +4,7 @@ # packages that are already depending on sf-awareness at the time # the feature was introduced (Jul 23, 2024). # New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). -known_sf_aware <- c(".globalenv", "sf", +known_sf_aware <- c(".globalenv", "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") # Register environment as sf-aware. We use a lexical flag instead of @@ -27,8 +27,8 @@ known_sf_aware <- c(".globalenv", "sf", #' for packages: use the sticky geometry [ behaviour of sf in package code #' #' for packages: use the sticky geometry [ behaviour of sf in package code -#' @param env environment -#' @param value logical; default `TRUE` +#' param env environment +#' value logical; default `TRUE` #' @export make_sf_aware <- function(env = parent.frame(), value = TRUE) { env$.__sf_aware__. <- value diff --git a/man/make_sf_aware.Rd b/man/make_sf_aware.Rd index 2b10f5a28..0030ea5f9 100644 --- a/man/make_sf_aware.Rd +++ b/man/make_sf_aware.Rd @@ -6,11 +6,8 @@ \usage{ make_sf_aware(env = parent.frame(), value = TRUE) } -\arguments{ -\item{env}{environment} - -\item{value}{logical; default \code{TRUE}} -} \description{ for packages: use the sticky geometry [ behaviour of sf in package code +param env environment +value logical; default \code{TRUE} } From e91f87b3fc928342666b97325b52ea376a69dadd Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 13:58:24 +0200 Subject: [PATCH 34/70] Revert "adds make_sf_aware() and is_sf_aware() in [.sf" This reverts commit cf2df2614d27c03930b5d656051d8ae241c90e51. --- DESCRIPTION | 1 - NAMESPACE | 1 - R/sf.R | 66 ++++++++++++++++++++--------------------- R/sf_aware.R | 70 -------------------------------------------- man/make_sf_aware.Rd | 13 -------- 5 files changed, 31 insertions(+), 120 deletions(-) delete mode 100644 R/sf_aware.R delete mode 100644 man/make_sf_aware.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 2de4d715d..2775100f0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -162,7 +162,6 @@ Collate: 'gdal_utils.R' 'nearest.R' 'normalize.R' - 'sf_aware.R' 'sf-package.R' 'defunct.R' 'z_range.R' diff --git a/NAMESPACE b/NAMESPACE index 8fd23209e..3c2cf0128 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -406,7 +406,6 @@ export(gdal_utils) export(gdal_write) export(gdal_write_mdim) export(get_key_pos) -export(make_sf_aware) export(plot_sf) export(rawToHex) export(read_sf) diff --git a/R/sf.R b/R/sf.R index 7989e7f35..eb262dced 100644 --- a/R/sf.R +++ b/R/sf.R @@ -338,45 +338,41 @@ st_sf = function(..., agr = NA_agr_, row.names, #' h[g,] #' @export "[.sf" = function(x, i, j, ..., drop = FALSE, op = st_intersects) { + nargs = nargs() + agr = st_agr(x) + if (!missing(i) && (inherits(i, "sf") || inherits(i, "sfc") || inherits(i, "sfg"))) + i = lengths(op(x, i, ...)) != 0 + sf_column = attr(x, "sf_column") + geom = st_geometry(x) + if (!missing(i) && nargs > 2) { # e.g. a[3:4,] not a[3:4] + if (is.character(i)) + i = match(i, row.names(x)) + geom = geom[i] + } - if (is_sf_aware()) { - nargs = nargs() - agr = st_agr(x) - if (!missing(i) && (inherits(i, "sf") || inherits(i, "sfc") || inherits(i, "sfg"))) - i = lengths(op(x, i, ...)) != 0 - sf_column = attr(x, "sf_column") - geom = st_geometry(x) - if (!missing(i) && nargs > 2) { # e.g. a[3:4,] not a[3:4] - if (is.character(i)) - i = match(i, row.names(x)) - geom = geom[i] - } - - # x = as.data.frame(x) - class(x) = setdiff(class(x), "sf") # one step down - x = if (missing(j)) { - if (nargs == 2) # `[`(x,i) - x[i] # do sth else for tbl? - else - x[i, , drop = drop] - } else - x[i, j, drop = drop] + # x = as.data.frame(x) + class(x) = setdiff(class(x), "sf") # one step down + x = if (missing(j)) { + if (nargs == 2) # `[`(x,i) + x[i] # do sth else for tbl? + else + x[i, , drop = drop] + } else + x[i, j, drop = drop] - if (!missing(j)) - agr = agr[j] - else if (!missing(i) && nargs <= 2) - agr = agr[i] # e.g., obj["name"] + if (!missing(j)) + agr = agr[j] + else if (!missing(i) && nargs <= 2) + agr = agr[i] # e.g., obj["name"] - if (inherits(x, "sfc")) # drop was TRUE, and we selected geom column only - x - else if (! drop) { - x[[ sf_column ]] = geom - x = st_sf(x, sf_column_name = sf_column, sfc_last = FALSE) - st_set_agr(x, agr[match(setdiff(names(x), sf_column), names(agr))]) - } else - structure(x, class = setdiff(class(x), "sf")) + if (inherits(x, "sfc")) # drop was TRUE, and we selected geom column only + x + else if (! drop) { + x[[ sf_column ]] = geom + x = st_sf(x, sf_column_name = sf_column, sfc_last = FALSE) + st_set_agr(x, agr[match(setdiff(names(x), sf_column), names(agr))]) } else - NextMethod() + structure(x, class = setdiff(class(x), "sf")) } #' @export diff --git a/R/sf_aware.R b/R/sf_aware.R deleted file mode 100644 index 301ae1be2..000000000 --- a/R/sf_aware.R +++ /dev/null @@ -1,70 +0,0 @@ -# see https://github.com/r-spatial/sf/issues/2131 - -# Known namespaces that need sticky columns. This is set to the -# packages that are already depending on sf-awareness at the time -# the feature was introduced (Jul 23, 2024). -# New packages wanting to opt-in should use `make_sf_aware()` in their .onLoad(). -known_sf_aware <- c(".globalenv", - "alcyon", "animalEKF", "arcpullr", "basf", "bcmaps", "bispdep", "canadamaps", "CCAMLRGIS", "cffdrs", "chilemapas", "dggridR", "ecochange", "geotopbricks", "ggmapinset", "habCluster", "hgwrr", "LabourMarketAreas", "M3", "MazamaSpatialUtils", "micromap", "nngeo", "onmaRg", "PointedSDMs", "ppgm", "raptr", "RCzechia", "rgplates", "rKIN", "rLFT", "rts2", "segmetric", "sftime", "siland", "spatialreg", "spdep", "spMaps", "spsurvey", "stars", "starsExtra", "stcos", "surveyvoi", "tilegramsR", "transfR", "waver", "wdnr.gis", "wdpar", "windAC", "abmR", "abstr", "adw", "agricolaeplotr", "alarmdata", "amt", "anipaths", "aopdata", "appeears", "arcgisgeocode", "arcgislayers", "arcgisutils", "areal", "arealDB", "ARPALData", "ARUtools", "ascotraceR", "atakrig", "atpolR", "automap", "bangladesh", "basemaps", "bayesmove", "BayesX", "bcdata", "bcputility", "bdc", "bdl", "bdvis", "BeeBDC", "BFS", "bfsMaps", "BIEN", "bigDM", "BIOMASS", "bioregion", "blackmarbler", "blockCV", "bluebike", "BoundaryStats", "bRacatus", "btb", "camtrapR", "canadianmaps", "capm", "CARBayes", "CARBayesdata", "CARBayesST", "card", "cartograflow", "cartogram", "cartogramR", "cartographer", "cartographr", "cartography", "CAST", "CatastRo", "CDCPLACES", "cdrcR", "CDSE", "censable", "centr", "cft", "changeRangeR", "chessboard", "chirps", "cleangeo", "clhs", "cmsafvis", "cnmap", "CoastlineFD", "comorosmaps", "concaveman", "conleyreg", "constrainedKriging", "CopernicusDEM", "CopernicusMarine", "covid19br", "covid19sf", "covidcast", "crawl", "crimedata", "cropDemand", "CropScapeR", "cropZoning", "crsuggest", "CRTspat", "cshapes", "CSHShydRology", "csodata", "csquares", "ctmm", "cubble", "CvmortalityMult", "cyclestreets", "dafishr", "damAOI", "datazoom.amazonia", "daymetr", "densityarea", "DEPONS2R", "Directional", "disaggregation", "dispeRse", "distanceto", "divseg", "divvy", "dots", "downscale", "dsims", "dsmSearch", "dssd", "dwp", "dynamicSDM", "ebirdst", "echor", "edbuildmapr", "ediblecity", "EEAaq", "eiExpand", "eixport", "eks", "elevatr", "EmissV", "emstreeR", "enmSdmX", "envi", "epikit", "epiR", "epm", "eSDM", "evolMap", "exactextractr", "expowo", "extRatum", "FedData", "feltr", "fgdr", "FIESTA", "FIESTAutils", "fisheye", "fishRman", "fitbitViz", "flexpolyline", "flightplot", "FLightR", "fmesher", "forestecology", "ForestTools", "FORTLS", "fsr", "fude", "galah", "gbm.auto", "gdalUtilities", "geneHapR", "GeNetIt", "GeoAdjust", "geoAr", "geobr", "geocausal", "geocmeans", "geodimension", "geodiv", "geodrawr", "geofi", "geogenr", "geogrid", "geojsonio", "geomander", "GEOmap", "geomaroc", "geomerge", "geomultistar", "geonetwork", "geoperu", "geostan", "geouy", "gfcanalysis", "ggautomap", "ggfields", "ggOceanMaps", "GGoutlieR", "ggseg", "ggspatial", "GIFT", "giscoR", "GISINTEGRATION", "GISSB", "glottospace", "googletraffic", "gps.track", "GPSeqClus", "grainscape", "graph4lg", "GREENeR", "gridpattern", "gstat", "gtfs2emis", "gtfs2gps", "gtfstools", "gwavr", "GWmodel", "GWnnegPCA", "GWpcor", "gwpcormapper", "GWSDAT", "h3jsr", "happign", "HDSpatialScan", "helsinki", "hemispheR", "hereR", "hero", "himach", "hosm", "hwsdr", "hydroloom", "hyfo", "hypsoLoop", "IceSat2R", "icosa", "idbr", "imcRtools", "importinegi", "inlabru", "INLAspacetime", "inldata", "intamap", "intamapInteractive", "ipdw", "IRexamples", "ispdata", "ISRaD", "itsdm", "jmastats", "jpgrid", "jpmesh", "klexdatr", "KMLtoSHAPE", "kokudosuuchi", "LAGOSNE", "lakemorpho", "LandComp", "landsepi", "lazysf", "lconnect", "leafem", "leafgl", "leafpm", "leafpop", "leastcostpath", "letsR", "lgcp", "lidaRtRee", "lidR", "link2GI", "LMMsolver", "LMoFit", "lwgeom", "macleish", "macroBiome", "MainExistingDatasets", "malariaAtlas", "mapboxapi", "mapchina", "mapedit", "MapGAM", "mapi", "mapiso", "mapme.biodiversity", "mapmixture", "mapping", "mapsapi", "mapscanner", "mapsf", "mapSpain", "mapStats", "maptiles", "mapview", "MassWateR", "MazamaSpatialPlots", "medfateland", "meteo", "meteoland", "meteospain", "metR", "MetricGraph", "mgwrhw", "mgwrsar", "micromapST", "MigConnectivity", "misuvi", "mkde", "mlr3spatial", "modisfast", "MODISTools", "Momocs", "monographaR", "Morpho", "motif", "move2", "movecost", "movegroup", "MTA", "naijR", "naturaList", "ncdfgeom", "ndi", "neonPlantEcology", "netmap", "nhdplusTools", "nhdR", "NipponMap", "njgeo", "nlrx", "nominatimlite", "nswgeo", "oceanexplorer", "oceanic", "oceanis", "oceanmap", "odbr", "ofpetrial", "ohsome", "ohun", "openairmaps", "opendatatoronto", "openeo", "opentripplanner", "Orcs", "osmextract", "OSMscale", "osrm", "otpr", "overturemapsr", "ows4R", "ozmaps", "palaeoverse", "PAMscapes", "pargasite", "pastclim", "patternize", "pavo", "pct", "pgirmess", "PL94171", "PlanetNICFI", "planscorer", "plantTracker", "pliman", "plotdap", "plusCode2", "populR", "potential", "povmap", "pRecipe", "PReMiuM", "pressuRe", "prevR", "prioritizr", "prioritizrdata", "prisonbrief", "pseudohouseholds", "pspatreg", "ptools", "PublicWorksFinanceIT", "pycno", "qlcVisualize", "qualmap", "r5r", "raceland", "rangeBuilder", "rangeMapper", "rasterbc", "rasterDT", "rasterpic", "raybevel", "raytracing", "rcarbon", "RchivalTag", "rdhs", "rdwplus", "readwritesqlite", "redist", "redistmetrics", "redistverse", "redlistr", "ref.ICAR", "Relectoral", "remap", "rerddapXtracto", "rfishnet2", "rflexscan", "rgeoboundaries", "rgeoda", "rgeopat2", "rgugik", "ripc", "RiskMap", "riverdist", "rivnet", "rlandfire", "Rlibkdv", "rmapshaper", "rmapzen", "rnaturalearth", "rnrfa", "roads", "robis", "rolap", "rosmium", "roughsf", "rpostgis", "RPyGeo", "Rsagacmd", "rsat", "rsi", "rsocialwatcher", "rSPARCS", "rstac", "RStoolbox", "rTLsDeep", "rtop", "rWCVP", "RWmisc", "sabre", "sampbias", "satres", "SchoolDataIT", "scider", "SDLfilter", "SDPDmod", "secr", "secrdesign", "secrlinear", "seedreg", "sfarrow", "sfcentral", "sfdct", "sfdep", "sfhotspot", "sfislands", "sfnetworks", "sftrack", "sgapi", "sgsR", "shoredate", "simodels", "SimSurvey", "sits", "smartmap", "smile", "SMITIDstruct", "smoothr", "soilassessment", "sorvi", "spacejamr", "SpatFD", "SpatGC", "spatgeom", "SpatGRID", "spatialEco", "SpatialFeatureExperiment", "SpatialGraph", "SpatialKDE", "SpatialPosition", "SpatialRDD", "spatialrisk", "spatialsample", "SpaTopic", "spatsoc", "spatsurv", "spbal", "spectator", "spectralR", "sphet", "spmodel", "spmoran", "spnaf", "spNetwork", "sqlhelper", "SRTsim", "SSDM", "SSIMmap", "SSN2", "SSNbayes", "stampr", "starsTileServer", "stats19", "stelfi", "StormR", "stplanr", "stppSim", "streamDepletr", "streetscape", "sugarbag", "SUMMER", "SUNGEO", "suntools", "supercells", "SurfaceTortoise", "surveyPrev", "swfscDAS", "swfscMisc", "SWMPrExtension", "SWTools", "tanaka", "TDLM", "tectonicr", "tenm", "terrainr", "tidycensus", "tidygeoRSS", "tidyrgee", "tidysdm", "tidyterra", "tidytransit", "tidyUSDA", "tigris", "tilemaps", "tinytiger", "tmap", "tmaptools", "tongfen", "track2KBA", "trackdf", "trackeRapp", "transformr", "treePlotArea", "TreeRingShape", "treesliceR", "trigpoints", "TUFLOWR", "uavRmp", "uci", "ulex", "UnalR", "upstartr", "ursa", "usmapdata", "valhallr", "valuemap", "VancouvR", "vein", "velociraptr", "versioning", "VicmapR", "vietnameseConverter", "viewscape", "voluModel", "Voyager", "walkboutr", "wallace", "waywiser", "weed", "WEGE", "WeightedTreemaps", "WES", "wflo", "wildlifeDI", "wingen", "WorldMapR", "zippeR", "zonebuilder") - -# Register environment as sf-aware. We use a lexical flag instead of -# inspecting the the name of the calling namespace and add it to -# `the$sf_aware` because the flag is more flexible. It makes it -# possible for arbitrary environments to opt into (or disable) the sf -# API like this: -# -# ``` -# local({ make_sf_aware(); sf[...] }) -# ``` -# -# Packages should call it like this in their `.onLoad()` hook (and -# thus before their namespace is sealed): -# -# ``` -# make_sf_aware(topenv(environment())) -# ``` - -#' for packages: use the sticky geometry [ behaviour of sf in package code -#' -#' for packages: use the sticky geometry [ behaviour of sf in package code -#' param env environment -#' value logical; default `TRUE` -#' @export -make_sf_aware <- function(env = parent.frame(), value = TRUE) { - env$.__sf_aware__. <- value -} - -is_sf_aware <- function(env = parent.frame(2)) { - top <- topenv(env) - - # Check for overrides - top_name <- env_name(top) - if (!is.null(top_name) && top_name %in% known_sf_aware) - TRUE - else { - if (!requireNamespace("rlang", quietly = TRUE)) - stop("rlang is not installed: install first?") - # Now check for the lexical flag. This could be rewritten - # without rlang as a loop over parents that stops at `topenv()`. - flag <- rlang::env_get( - env, - ".__sf_aware__.", - default = FALSE, - inherit = TRUE, - last = top - ) - stopifnot(is.logical(flag) && length(flag) == 1 && !is.na(flag)) - flag - } -} - -env_name <- function(env) { - ns <- topenv(env) - - if (isNamespace(ns)) - getNamespaceName(ns) - else if (identical(ns, globalenv())) - ".globalenv" - else - NULL -} diff --git a/man/make_sf_aware.Rd b/man/make_sf_aware.Rd deleted file mode 100644 index 0030ea5f9..000000000 --- a/man/make_sf_aware.Rd +++ /dev/null @@ -1,13 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/sf_aware.R -\name{make_sf_aware} -\alias{make_sf_aware} -\title{for packages: use the sticky geometry [ behaviour of sf in package code} -\usage{ -make_sf_aware(env = parent.frame(), value = TRUE) -} -\description{ -for packages: use the sticky geometry [ behaviour of sf in package code -param env environment -value logical; default \code{TRUE} -} From 02efb81b067a6bdb59f64da2700fbdb3e8405960 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 2 Oct 2024 14:20:53 +0200 Subject: [PATCH 35/70] remove commits related to [.sf from this branch --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2775100f0..433ecd9cf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -112,7 +112,7 @@ LinkingTo: VignetteBuilder: knitr Encoding: UTF-8 -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) Config/testthat/edition: 2 Config/needs/coverage: XML From c3037434cac371612f194701d28fdc887db371c9 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 9 Oct 2024 09:57:49 +0200 Subject: [PATCH 36/70] allow oriented to be set at the sfc object level; #2441 --- R/s2.R | 9 +++++---- R/sfc.R | 9 +++++++-- man/s2.Rd | 7 ++++++- man/sfc.Rd | 6 +++++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/R/s2.R b/R/s2.R index af54b6515..379cc3147 100644 --- a/R/s2.R +++ b/R/s2.R @@ -44,13 +44,13 @@ as_s2_geography.sfg <- function(x, ..., oriented = getOption("s2_oriented", FALS } # dynamically exported in tidyverse.R -as_s2_geography.sfc <- function(x, ..., oriented = getOption("s2_oriented", FALSE)) { +as_s2_geography.sfc <- function(x, ..., oriented = getOption("s2_oriented", FALSE) || isTRUE(attr(x, "oriented"))) { st_as_s2.sfc(x, ..., oriented = oriented) } # dynamically exported in tidyverse.R -as_s2_geography.sf <- function(x, ..., oriented = getOption("s2_oriented", FALSE)) { - st_as_s2.sf(x, ..., oriented = oriented) +as_s2_geography.sf <- function(x, ...) { + st_as_s2.sf(x, ...) } #' functions for spherical geometry, using s2 package @@ -86,7 +86,8 @@ st_as_s2.sf = function(x, ...) st_as_s2(st_geometry(x), ...) #' left of the polygon's path. #' @param rebuild logical; call \link[s2]{s2_rebuild} on the geometry (think of this as a \code{st_make_valid} on the sphere) #' @export -st_as_s2.sfc = function(x, ..., oriented = getOption("s2_oriented", FALSE), rebuild = FALSE) { +st_as_s2.sfc = function(x, ..., oriented = getOption("s2_oriented", FALSE) || isTRUE(attr(x, "oriented")), + rebuild = FALSE) { if (!is.na(st_crs(x)) && !st_is_longlat(x)) x = st_transform(x, ifelse(st_axis_order(), "OGC:CRS84", "EPSG:4326")) if (length(x) && nchar(class(x[[1]])[1]) > 2) { # Z, M, ZM: diff --git a/R/sfc.R b/R/sfc.R index 33a7c1875..c3230fb2a 100644 --- a/R/sfc.R +++ b/R/sfc.R @@ -26,6 +26,8 @@ format.sfc = function(x, ..., width = 30) { #' @param check_ring_dir see \link{st_read} #' @param dim character; if this function is called without valid geometries, this argument may carry the right dimension to set empty geometries #' @param recompute_bbox logical; use \code{TRUE} to force recomputation of the bounding box +#' @param oriented logical; if \code{TRUE}, the ring is oriented such that left of the edges is inside the polygon; this is +#' needed for convering polygons larger than half the globe to s2 #' @return an object of class \code{sfc}, which is a classed list-column with simple feature geometries. #' #' @details A simple feature geometry list-column is a list of class @@ -40,7 +42,7 @@ format.sfc = function(x, ..., width = 30) { #' d = st_sf(data.frame(a=1:2, geom=sfc)) #' @export st_sfc = function(..., crs = NA_crs_, precision = 0.0, check_ring_dir = FALSE, dim, - recompute_bbox = FALSE) { + recompute_bbox = FALSE, oriented = NA) { lst = list(...) # if we have only one arg, which is already a list with sfg's, but NOT a geometrycollection: # (this is the old form of calling st_sfc; it is way faster to call st_sfc(lst) if lst @@ -137,6 +139,9 @@ st_sfc = function(..., crs = NA_crs_, precision = 0.0, check_ring_dir = FALSE, d # if (length(u <- unique(sfg_classes[1L,])) > 1) # stop(paste("found multiple dimensions:", paste(u, collapse = " "))) } + if (isTRUE(oriented)) + attr(lst, "oriented") = TRUE + lst } @@ -606,7 +611,7 @@ st_as_sfc.bbox = function(x, ...) { st_as_sfc("POLYGON FULL", crs = st_crs(x)) else { box = st_polygon(list(matrix(x[c(1, 2, 3, 2, 3, 4, 1, 4, 1, 2)], ncol = 2, byrow = TRUE))) - st_sfc(box, crs = st_crs(x)) + st_sfc(box, crs = st_crs(x), oriented = TRUE) } } diff --git a/man/s2.Rd b/man/s2.Rd index f04168357..e35ff8541 100644 --- a/man/s2.Rd +++ b/man/s2.Rd @@ -14,7 +14,12 @@ st_as_s2(x, ...) \method{st_as_s2}{sf}(x, ...) -\method{st_as_s2}{sfc}(x, ..., oriented = getOption("s2_oriented", FALSE), rebuild = FALSE) +\method{st_as_s2}{sfc}( + x, + ..., + oriented = getOption("s2_oriented", FALSE) || isTRUE(attr(x, "oriented")), + rebuild = FALSE +) } \arguments{ \item{use_s2}{logical; if \code{TRUE}, use the s2 spherical geometry package diff --git a/man/sfc.Rd b/man/sfc.Rd index 9fb773565..50d83c79d 100644 --- a/man/sfc.Rd +++ b/man/sfc.Rd @@ -19,7 +19,8 @@ st_sfc( precision = 0, check_ring_dir = FALSE, dim, - recompute_bbox = FALSE + recompute_bbox = FALSE, + oriented = NA ) \method{[}{sfc}(x, i, j, ..., op = st_intersects) @@ -37,6 +38,9 @@ st_sfc( \item{recompute_bbox}{logical; use \code{TRUE} to force recomputation of the bounding box} +\item{oriented}{logical; if \code{TRUE}, the ring is oriented such that left of the edges is inside the polygon; this is +needed for convering polygons larger than half the globe to s2} + \item{x}{object of class \code{sfc}} \item{i}{record selection. Might also be an \code{sfc}/\code{sf} object to work with the \code{op} argument} From ae4231d1850e4f908544d5ba6ba6abd27c331fb4 Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Wed, 9 Oct 2024 12:57:32 +0200 Subject: [PATCH 37/70] fix badges in README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 06a14d691..0f46557c3 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ [![tic-db](https://github.com/r-spatial/sf/actions/workflows/tic-db.yml/badge.svg)](https://github.com/r-spatial/sf/actions/workflows/tic-db.yml) [![Coverage Status](https://img.shields.io/codecov/c/github/r-spatial/sf/main.svg)](https://app.codecov.io/gh/r-spatial/sf) [![License](http://img.shields.io/badge/license-GPL%20%28%3E=%202%29-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-2.0.html) -[![CRAN](http://www.r-pkg.org/badges/version/sf)](https://cran.r-project.org/package=sf) +[![CRAN](https://www.r-pkg.org/badges/version/sf)](https://cran.r-project.org/package=sf) [![cran checks](https://badges.cranchecks.info/worst/sf.svg)](https://cran.r-project.org/web/checks/check_results_sf.html) -[![Downloads](http://cranlogs.r-pkg.org/badges/sf?color=brightgreen)](https://www.r-pkg.org:443/pkg/sf) +[![Downloads](https://cranlogs.r-pkg.org/badges/sf?color=brightgreen)](https://www.r-pkg.org/pkg/sf) [![status](https://tinyverse.netlify.com/badge/sf)](https://CRAN.R-project.org/package=sf) @@ -159,13 +159,13 @@ If you use dynamic linking (installation from source) and have multiple versions ### lwgeom -Functions and methods that require `liblwgeom`, including ellipsoidal (not spherical or Eucledian) metrics (area, distances), are provide by and used from [lwgeom](https://github.com/r-spatial/lwgeom), which is also on [CRAN](https://cran.r-project.org/package=lwgeom). +Functions and methods that require `liblwgeom`, including ellipsoidal (not spherical or Euclidean) metrics (area, distances), are provide by and used from [lwgeom](https://github.com/r-spatial/lwgeom), which is also on [CRAN](https://cran.r-project.org/package=lwgeom). ## Contributing * Contributions of all sorts are most welcome, issues and pull requests are the preferred ways of sharing them. -* When contributing pull requests, please adhere to the package style (in package code use `=` rather than `<-`; don't change indentation; tab stops of 4 spaces are preferred) -* This project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms. +* When contributing pull requests, please adhere to the package style (in package code use `=` rather than `<-`; don't change indentation; tab stops of 4 spaces are preferred). +* This project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project, you agree to abide by its terms. ## How to cite From 713d0661a82695c49ba43947075ec3e1d6e25140 Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Wed, 9 Oct 2024 13:01:24 +0200 Subject: [PATCH 38/70] one more badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f46557c3..d2ff4842b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![CRAN](https://www.r-pkg.org/badges/version/sf)](https://cran.r-project.org/package=sf) [![cran checks](https://badges.cranchecks.info/worst/sf.svg)](https://cran.r-project.org/web/checks/check_results_sf.html) [![Downloads](https://cranlogs.r-pkg.org/badges/sf?color=brightgreen)](https://www.r-pkg.org/pkg/sf) -[![status](https://tinyverse.netlify.com/badge/sf)](https://CRAN.R-project.org/package=sf) +[![status](https://tinyverse.netlify.app/badge/sf)](https://CRAN.R-project.org/package=sf) # Simple Features for R From 8e02a1d02fbb76ba8c63a658f8d7bca5d6fcc1f5 Mon Sep 17 00:00:00 2001 From: edzer Date: Wed, 9 Oct 2024 16:19:26 +0200 Subject: [PATCH 39/70] add news --- NEWS.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 882d88464..c5243034b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # version 1.0-18 -* support `POLYGON FULL` simple feature geometry, representing the the entire Earth surface; #2441 +* support `POLYGON FULL` simple feature geometry, representing the the entire Earth surface, as used by `s2geometry`; #2441 + +* `st_sfc()` has an argument `oriented` which, when set to `TRUE`, adds an attribute `oriented=TRUE` to an `sfc` object, indicating that this object should not be reoriented in conversion to `s2_geography` (avoiding using the global option `s2_oriented`); `st_as_sfc.bbox()` sets this to `TRUE`; #2441 * fix build failure with GDAL < 3.4.0 #2436 From b335356678900a8e82f17b57f540bc3890c9fb7a Mon Sep 17 00:00:00 2001 From: Krzysztof Dyba <35004826+kadyb@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:34:20 +0200 Subject: [PATCH 40/70] update URL in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2ff4842b..76b870cd7 100644 --- a/README.md +++ b/README.md @@ -181,8 +181,8 @@ for Spatial Vector Data. The R Journal [10:1, 439-446.](https://journal.r-projec This project gratefully acknowledges financial [support](https://www.r-consortium.org/projects) from the - - + +