- Notifications
You must be signed in to change notification settings - Fork6
Targets extensions for geospatial data
License
Unknown, MIT licenses found
Licenses found
ropensci/geotargets
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
geotargets extendstargets towork with geospatial data formats, such as rasters and vectors (e.g.,shapefiles). Currently we support raster and vector formats for theterra package.
If you are unfamiliar with targets, we recommend watching“targets in 4minutes”.
One example citation of geotargets could be as follows: “R packages usedin this analysis included (list R packages used), targets, andgeotargets (Tierney, N., Scott, E., & Brown, A, 2024). Here is the fullbibliographic reference for your references:
Tierney N, Scott E, Brown A (2024). “geotargets: ‘Targets’ Extensionsfor Geospatial Formats.”https://docs.ropensci.org/geotargets/.
You can install the development version of geotargets like so:
install.packages("geotargets",repos= c("https://ropensci.r-universe.dev","https://cran.r-project.org"))
If you want to use geospatial data formats (such asterra) with thetargets package to buildanalytic reproducible pipelines, it involves writing a lot of customtargets wrappers. We wrotegeotargets so you can use geospatial dataformats withtargets.
To provide more detail on this, a common problem when using popularlibraries liketerra withtargets is running into errors with readand write. Due to the limitations that come with the underlying C++implementation in theterra library, there are specific ways to writeand read these objects. See?terra for details.geotargets helpshandle these write and read steps, so you don’t have to worry about themand can use targets as you are used to.
In essence, if you’ve ever come across the error:
Error in .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: 0x0>, : NULL value passed as symbol addressor
Error: external pointer is not validWhen trying to read in a geospatial raster or vector in targets, thengeotargets for you :)
We currently provide support for theterra package withtargets.Below we show three examples of target factories:
tar_terra_rast()tar_terra_vect()tar_terra_sprc()tar_terra_sds()tar_terra_tiles()tar_stars()
You would use these in place oftar_target() in your targets pipeline,e.g., when you are doing work withterra raster, vector, or rastercollection data.
If you would like to see and download working examples for yourself, seethe repos:
library(targets)tar_dir({# tar_dir() runs code from a temporary directory. tar_script({ library(geotargets)get_elev<-function() {terra::rast(system.file("ex","elev.tif",package="terra")) }list( tar_terra_rast(terra_rast_example, get_elev() ) ) }) tar_make()x<- tar_read(terra_rast_example)x})#> + terra_rast_example dispatched#> ✔ terra_rast_example completed [65ms, 8.52 kB]#> ✔ ended pipeline [383ms, 1 completed, 0 skipped]#> class : SpatRaster#> size : 90, 95, 1 (nrow, ncol, nlyr)#> resolution : 0.008333333, 0.008333333 (x, y)#> extent : 5.741667, 6.533333, 49.44167, 50.19167 (xmin, xmax, ymin, ymax)#> coord. ref. : lon/lat WGS 84 (EPSG:4326)#> source : terra_rast_example#> name : elevation#> min value : 141#> max value : 547
tar_dir({# tar_dir() runs code from a temporary directory. tar_script({ library(geotargets)lux_area<-function(projection="EPSG:4326") {terra::project(terra::vect(system.file("ex","lux.shp",package="terra")),projection ) }list( tar_terra_vect(terra_vect_example, lux_area() ) ) }) tar_make()x<- tar_read(terra_vect_example)x})#> + terra_vect_example dispatched#> ✔ terra_vect_example completed [72ms, 172.03 kB]#> ✔ ended pipeline [264ms, 1 completed, 0 skipped]#> class : SpatVector#> geometry : polygons#> dimensions : 12, 6 (geometries, attributes)#> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax)#> source : terra_vect_example#> coord. ref. : lon/lat WGS 84 (EPSG:4326)#> names : ID_1 NAME_1 ID_2 NAME_2 AREA POP#> type : <num> <chr> <num> <chr> <num> <num>#> values : 1 Diekirch 1 Clervaux 312 1.808e+04#> 1 Diekirch 2 Diekirch 218 3.254e+04#> 1 Diekirch 3 Redange 259 1.866e+04tar_dir({# tar_dir() runs code from a temporary directory. tar_script({ library(geotargets)elev_scale<-function(z=1,projection="EPSG:4326") {terra::project(terra::rast(system.file("ex","elev.tif",package="terra"))*z,projection ) }list( tar_terra_sprc(raster_elevs,# two rasters, one unaltered, one scaled by factor of 2 and# reprojected to interrupted goode homolosinecommand=terra::sprc(list( elev_scale(1), elev_scale(2,"+proj=igh") )) ) ) }) tar_make()x<- tar_read(raster_elevs)x})#> + raster_elevs dispatched#> ✔ raster_elevs completed [191ms, 37.90 kB]#> ✔ ended pipeline [470ms, 1 completed, 0 skipped]#> class : SpatRasterCollection#> length : 2#> nrow : 90, 115#> ncol : 95, 114#> nlyr : 1, 1#> extent : 5.741667, 1558890, 49.44167, 5556741 (xmin, xmax, ymin, ymax)#> crs (first) : lon/lat WGS 84 (EPSG:4326)#> names : raster_elevs, raster_elevstar_dir({# tar_dir() runs code from a temporary directory. tar_script({ library(geotargets)list( tar_stars(test_stars,stars::read_stars(system.file("tif","olinda_dem_utm25s.tif",package="stars" )) ) ) }) tar_make()x<- tar_read(test_stars)x})#> + test_stars dispatched#> ✔ test_stars completed [63ms, 49.90 kB]#> ✔ ended pipeline [275ms, 1 completed, 0 skipped]#> stars object with 2 dimensions and 1 attribute#> attribute(s):#> Min. 1st Qu. Median Mean 3rd Qu. Max.#> test_stars -1 6 12 21.66521 35 88#> dimension(s):#> from to offset delta refsys point x/y#> x 1 111 288776 89.99 UTM Zone 25, Southern Hem... FALSE [x]#> y 1 111 9120761 -89.99 UTM Zone 25, Southern Hem... FALSE [y]Please note that the geotargets project is released with aContributorCode of Conduct. By contributingto this project, you agree to abide by its terms.
Logo design by Hubert Hałun at Appsilon.
About
Targets extensions for geospatial data
Topics
Resources
License
Unknown, MIT licenses found
Licenses found
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.
