Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can we make spex() independent? #23

Open
3 tasks
mdsumner opened this issue May 16, 2020 · 5 comments
Open
3 tasks

can we make spex() independent? #23

mdsumner opened this issue May 16, 2020 · 5 comments

Comments

@mdsumner
Copy link
Owner

mdsumner commented May 16, 2020

Considering only the function spex(), we want:

  • get the four numbers
  • get the crs, if we can
  • can we be independent of raster and sp

I think we can, because we only need sp and raster if we use accessors in ways that trigger code to run.

All these lines are run in fresh sessions, but the uncommented ones can be run without loading sp.

#saveRDS(wrld_simpl[1:2, ], "sp.rds")
#sp@data        sp@polygons    sp@plotOrder   sp@bbox        sp@proj4string
sp <- readRDS("sp.rds")  ## doesn't load sp

#sp@  #<tab> loads sp

sp@bbox  ## doesn't load sp

sp@data        
#sp@polygons     ## loads sp
sp@plotOrder       ## doesn't load sp
#sp@proj4string    ## loads sp
sp@proj4string@projargs
# comment(sp@proj4string) ## NULL atm
#sp::proj4string(sp) <- sp::proj4string(sp)  ## loads sp, adds WKT
#saveRDS(sp, "sp_wkt.rds")

What about new objects.

sp <- readRDS("sp_wkt.rds")        ## doesn't load sp
sp@proj4string@projargs  ## doesn't load sp
sp@plotOrder                     ## doesn't load sp
sp@bbox                             ## doesn't load sp
sp@data                              ## doesn't load sp

comment(sp@proj4string)  ## doesn't load sp
attributes(sp@proj4string)  ## doesn't load sp
grep(":sp$", search())
integer(0)

Let's check for sure.

remove.packages("sp")
grep("^sp$", list.files(.libPaths()))
# integer(0)

``` r
sp <- readRDS("C:/temp/sp_wkt.rds")        
sp@proj4string@projargs  
#> [1] "+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs"
sp@plotOrder                     
#> [1] 2 1
sp@bbox                             
#>         min      max
#> x -61.88722 11.98648
#> y  17.02444 37.08639
sp@data                              
#>                    NAME
#> ATG Antigua and Barbuda
#> DZA             Algeria

comment(sp@proj4string)  
#> [1] "BOUNDCRS[\n    SOURCECRS[\n        GEOGCRS[\"unknown\",\n            DATUM[\"World Geodetic System 1984\",\n                ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n                    LENGTHUNIT[\"metre\",1]],\n                ID[\"EPSG\",6326]],\n            PRIMEM[\"Greenwich\",0,\n                ANGLEUNIT[\"degree\",0.0174532925199433],\n                ID[\"EPSG\",8901]],\n            CS[ellipsoidal,2],\n                AXIS[\"longitude\",east,\n                    ORDER[1],\n                    ANGLEUNIT[\"degree\",0.0174532925199433,\n                        ID[\"EPSG\",9122]]],\n                AXIS[\"latitude\",north,\n                    ORDER[2],\n                    ANGLEUNIT[\"degree\",0.0174532925199433,\n                        ID[\"EPSG\",9122]]]]],\n    TARGETCRS[\n        GEOGCRS[\"WGS 84\",\n            DATUM[\"World Geodetic System 1984\",\n                ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n                    LENGTHUNIT[\"metre\",1]]],\n            PRIMEM[\"Greenwich\",0,\n                ANGLEUNIT[\"degree\",0.0174532925199433]],\n            CS[ellipsoidal,2],\n                AXIS[\"latitude\",north,\n                    ORDER[1],\n                    ANGLEUNIT[\"degree\",0.0174532925199433]],\n                AXIS[\"longitude\",east,\n                    ORDER[2],\n                    ANGLEUNIT[\"degree\",0.0174532925199433]],\n            ID[\"EPSG\",4326]]],\n    ABRIDGEDTRANSFORMATION[\"Transformation from unknown to WGS84\",\n        METHOD[\"Geocentric translations (geog2D domain)\",\n            ID[\"EPSG\",9603]],\n        PARAMETER[\"X-axis translation\",0,\n            ID[\"EPSG\",8605]],\n        PARAMETER[\"Y-axis translation\",0,\n            ID[\"EPSG\",8606]],\n        PARAMETER[\"Z-axis translation\",0,\n            ID[\"EPSG\",8607]]]]"
attributes(sp@proj4string)  
#> $projargs
#> [1] "+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs"
#> 
#> $class
#> [1] "CRS"
#> attr(,"package")
#> [1] "sp"
#> 
#> $comment
#> [1] "BOUNDCRS[\n    SOURCECRS[\n        GEOGCRS[\"unknown\",\n            DATUM[\"World Geodetic System 1984\",\n                ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n                    LENGTHUNIT[\"metre\",1]],\n                ID[\"EPSG\",6326]],\n            PRIMEM[\"Greenwich\",0,\n                ANGLEUNIT[\"degree\",0.0174532925199433],\n                ID[\"EPSG\",8901]],\n            CS[ellipsoidal,2],\n                AXIS[\"longitude\",east,\n                    ORDER[1],\n                    ANGLEUNIT[\"degree\",0.0174532925199433,\n                        ID[\"EPSG\",9122]]],\n                AXIS[\"latitude\",north,\n                    ORDER[2],\n                    ANGLEUNIT[\"degree\",0.0174532925199433,\n                        ID[\"EPSG\",9122]]]]],\n    TARGETCRS[\n        GEOGCRS[\"WGS 84\",\n            DATUM[\"World Geodetic System 1984\",\n                ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n                    LENGTHUNIT[\"metre\",1]]],\n            PRIMEM[\"Greenwich\",0,\n                ANGLEUNIT[\"degree\",0.0174532925199433]],\n            CS[ellipsoidal,2],\n                AXIS[\"latitude\",north,\n                    ORDER[1],\n                    ANGLEUNIT[\"degree\",0.0174532925199433]],\n                AXIS[\"longitude\",east,\n                    ORDER[2],\n                    ANGLEUNIT[\"degree\",0.0174532925199433]],\n            ID[\"EPSG\",4326]]],\n    ABRIDGEDTRANSFORMATION[\"Transformation from unknown to WGS84\",\n        METHOD[\"Geocentric translations (geog2D domain)\",\n            ID[\"EPSG\",9603]],\n        PARAMETER[\"X-axis translation\",0,\n            ID[\"EPSG\",8605]],\n        PARAMETER[\"Y-axis translation\",0,\n            ID[\"EPSG\",8606]],\n        PARAMETER[\"Z-axis translation\",0,\n            ID[\"EPSG\",8607]]]]"
grep(":sp$", search())
#> integer(0)

Created on 2020-05-16 by the reprex package (v0.3.0)

@mdsumner
Copy link
Owner Author

The spex extent will be gotten from embedded bbox or by traversing the coordinates (geometries pkg), and we can allow its use in raster and so on along with buffer_extent. The rest can go, or just a new package.

crsmeta will do the crs

@mdsumner
Copy link
Owner Author

mdsumner commented May 16, 2020

Oh,can we generate a raster extent as S4 object? I think we can if only by using a copy

@mdsumner
Copy link
Owner Author

mdsumner commented May 16, 2020

A problem is terra and S2 and whatever else with opaque pointers, but I think the success of these new packages will ultimately depend on some kind of consensus and consolidation of this basic stuff. (Spatial was a great start, a clever abstraction but the fact it didn't work doesn't mean it can't. raster made it really good, and still has the good bits even though it's otherwise abandoned)

@mdsumner
Copy link
Owner Author

mdsumner commented May 16, 2020

I don't think we can beat S4, you can't set the "class" attribute, this invokes a search for the class def

attr(attr(x, "class"), "package") <- "raster"

(but that's allright, we don't need to construct them just get their values)

@mdsumner
Copy link
Owner Author

replace with wk!

https://twitter.com/paleolimbot/status/1409504922433957896?s=20

this implies that spex drops raster/sp and so on and virtualizes around the rct type ... should be a good example and a fix for hypertidy/ceramic#40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant