Skip to content

Commit

Permalink
initial commit 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
njtierney committed Mar 3, 2024
0 parents commit 52670f0
Show file tree
Hide file tree
Showing 24 changed files with 521 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^geotargets\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.Rproj.user
.Rhistory
.Rdata
.httr-oauth
.DS_Store
.quarto
35 changes: 35 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Package: geotargets
Title: Targets extensions for geospatial
Version: 0.0.0.9000
Authors@R: c(
person(
given = "Nicholas",
last = "Tierney",
email = "nicholas.tierney@gmail.com",
role = c("aut", "cre"),
comment = c(ORCID = "https://orcid.org/0000-0003-1460-8722")
),
person(
given = "",
last = "",
email = "",
role = c("aut"),
comment = c(ORCID = "https://orcid.org/XXXX")
)
)
Description: Provides extensions for various geospatial file formats,
including shapefiles, rasters, and more. See the vignettes for worked
examples and demonstrations and explanations of how to use the various
package extensions
License: MIT + file LICENSE
Encoding: UTF-8
Language: en-GB
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
targets,
terra,
utils
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by roxygen2: do not edit by hand

9 changes: 9 additions & 0 deletions R/geotargets-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
#' @import rlang
#' @importFrom glue glue
#' @importFrom lifecycle deprecated
## usethis namespace: end
NULL
65 changes: 65 additions & 0 deletions R/tar-geotiff.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
tar_geotiff <- function(name,
command,
pattern = NULL,
tidy_eval = targets::tar_option("tidy_eval"),
library = targets::tar_option_get("library"),
repository = targets::tar_option_get("repository"),
iteration = targets::tar_option_get("iteration"),
error = targets::tar_option_get("error"),
memory = targets::tar_option_get("memory"),
garbage_collection = targets::tar_option_get("garbage_collection"),
deployment = targets::tar_option_get("deployment"),
priority = targets::tar_option_get("priority"),
resources = targets::tar_option_get("resources"),
storage = targets::tar_option_get("storage"),
retrieval = targets::tar_option_get("retrieval"),
cue = targets::tar_option_get("cue")) {
name <- targets::tar_deparse_language(substitute(name))

envir <- tar_option_get("envir")

command <- targets::tar_tidy_eval(
expr = as.expression(substitute(command)),
envir = envir,
tidy_eval = tidy_eval
)
pattern <- targets::tar_tidy_eval(
expr = as.expression(substitute(pattern)),
envir = envir,
tidy_eval = tidy_eval
)

format_geotiff <- targets::tar_format(
read = function(path) terra::rast(path),
write = function(object, path) {
terra::writeRaster(
x = object,
filename = path,
filetype = "GTiff",
overwrite = TRUE
)
},
marshal = function(object) terra::wrap(object),
unmarshal = function(object) terra::unwrap(object)
)

targets::tar_target_raw(
name = name,
command = command,
pattern = pattern,
packages = packages,
library = library,
format = format_geotiff,
repository = repository,
iteration = iteration,
error = error,
memory = memory,
garbage_collection = garbage_collection,
deployment = deployment,
priority = priority,
resources = resources,
storage = storage,
retrieval = retrieval,
cue = cue
)
}
86 changes: 86 additions & 0 deletions R/tar-shapefile.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
format_shapefile <- targets::tar_format(
read = function(path) {
terra::vect(
paste0(
"/vsizip/",
file.path(
path,
replace_dot_zip_with_shp(path)
)
)
)
},
write = function(object, path) {
terra::writeVector(
x = object,
filename = replace_dot_zip_with_shp(path),
filetype = "ESRI Shapefile",
overwrite = TRUE
)
zf <- list.files(
pattern = replace_dot_zip(
x = path,
replacement = ""
)
)
utils::zip(
zipfile = path,
files = zf
)
unlink(zf)
},
marshal = function(object) terra::wrap(object),
unmarshal = function(object) terra::unwrap(object)
)

tar_shapefile <- function(name,
command,
pattern = NULL,
tidy_eval = targets::tar_option("tidy_eval"),
library = targets::tar_option_get("library"),
repository = targets::tar_option_get("repository"),
iteration = targets::tar_option_get("iteration"),
error = targets::tar_option_get("error"),
memory = targets::tar_option_get("memory"),
garbage_collection = targets::tar_option_get("garbage_collection"),
deployment = targets::tar_option_get("deployment"),
priority = targets::tar_option_get("priority"),
resources = targets::tar_option_get("resources"),
storage = targets::tar_option_get("storage"),
retrieval = targets::tar_option_get("retrieval"),
cue = targets::tar_option_get("cue")) {
name <- targets::tar_deparse_language(substitute(name))

envir <- tar_option_get("envir")

command <- targets::tar_tidy_eval(
expr = as.expression(substitute(command)),
envir = envir,
tidy_eval = tidy_eval
)
pattern <- targets::tar_tidy_eval(
expr = as.expression(substitute(pattern)),
envir = envir,
tidy_eval = tidy_eval
)

targets::tar_target_raw(
name = name,
command = command,
pattern = pattern,
packages = packages,
library = library,
format = format_shapefile,
repository = repository,
iteration = iteration,
error = error,
memory = memory,
garbage_collection = garbage_collection,
deployment = deployment,
priority = priority,
resources = resources,
storage = storage,
retrieval = retrieval,
cue = cue
)
}
Empty file added R/tarchetypes.R
Empty file.
13 changes: 13 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
replace_dot_zip <- function(x, replacement){
gsub(
pattern = "\\.zip",
replacement = replacement,
x = basename(x)
)
}

replace_dot_zip_with_shp <- function(x){
replace_dot_zip(x, ".shp")
}


38 changes: 38 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# geotargets

<!-- badges: start -->
<!-- badges: end -->

The goal of geotargets is to extend targets to work with geospatial data, like shapefiles and rasters.

## Installation

You can install the development version of geotargets like so:

``` r
remotes::install_github("njtierney/geotargets")
```

## Package still under development

Currently geotargets provides:

- `tar_geotiff`
- `tar_shapefile`

But these are under development.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# geotargets

<!-- badges: start -->
<!-- badges: end -->

The goal of geotargets is to extend targets to work with geospatial
data, like shapefiles and rasters.

## Installation

You can install the development version of geotargets like so:

``` r
remotes::install_github("njtierney/geotargets")
```

## Package still under development

Currently geotargets provides:

- `tar_geotiff`
- `tar_shapefile`

But these are under development.
22 changes: 22 additions & 0 deletions geotargets.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Version: 1.0

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 4
Encoding: UTF-8

RnwWeave: knitr
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
21 changes: 21 additions & 0 deletions man/figures/lifecycle-archived.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions man/figures/lifecycle-defunct.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions man/figures/lifecycle-deprecated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 52670f0

Please sign in to comment.