Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Targets extensions for geospatial data

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

ropensci/geotargets

Project Status: Active – The project has reached a stable, usable state and is being actively developed.R TargetopiaR-CMD-checkCodecov test coveragepkgcheckStatus at rOpenSci Software Peer ReviewR-multiverse statusCRAN status

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”.

How to cite geotargets

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/.

Installation

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"))

Whygeotargets

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 address

or

Error: external pointer is not valid

When trying to read in a geospatial raster or vector in targets, thengeotargets for you :)

Examples

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:

tar_terra_rast(): targets with terra rasters

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_terra_vect(): targets with terra vectors

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+04

tar_terra_sprc(): targets with terra raster collections

tar_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_elevs

tar_stars(): targets with stars objects

tar_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]

Code of Conduct

Please note that the geotargets project is released with aContributorCode of Conduct. By contributingto this project, you agree to abide by its terms.

Acknowledgements

Logo design by Hubert Hałun at Appsilon.

Packages

No packages published

Contributors5

Languages


[8]ページ先頭

©2009-2025 Movatter.jp