-
Notifications
You must be signed in to change notification settings - Fork 4
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
format_shapefile()
utils::zip()
usage
#5
Comments
A reprex of how this can be implemented. Indeed there is no need to have the target end in .zip, nor for the calls to Lines 20 to 29 in 69a08fe
targets::tar_script({
library(terra)
library(targets)
lux_area <- function(projection = "EPSG:4326") {
terra::project(terra::vect(system.file("ex", "lux.shp", package = "terra")),
projection)
}
format_shapefile_zip <- tar_format(
read = function(path) terra::vect(paste0("/vsizip/{", path, "}")),
write = function(object, path) {
terra::writeVector(
x = object,
filename = paste0(path, ".shz"),
filetype = "ESRI Shapefile"
)
file.rename(paste0(path, ".shz"), path)
},
marshal = function(object) terra::wrap(object),
unmarshal = function(object) terra::unwrap(object)
)
tar_target(
lux_area1,
command = lux_area(),
format = format_shapefile_zip
)
})
targets::tar_make()
#> terra 1.7.73
#> ▶ dispatched target lux_area1
#> ● completed target lux_area1 [0.037 seconds]
#> ▶ completed pipeline [0.131 seconds]
targets::tar_load("lux_area1")
lux_area1
#> class : SpatVector
#> geometry : polygons
#> dimensions : 12, 6 (geometries, attributes)
#> extent : 5.74414, 6.528252, 49.44781, 50.18162 (xmin, xmax, ymin, ymax)
#> source : lux_area1} (lux_area1)
#> 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> <int>
#> values : 1 Diekirch 1 Clervaux 312 18081
#> 1 Diekirch 2 Diekirch 218 32543
#> 1 Diekirch 3 Redange 259 18664 |
That looks great to me, thanks @brownag ! How would one implement getting a shapefile via gadm? Currently I've got a function written like so: get_gadm_country <- function(country = "Australia") {
dir.create("data/shapefiles", recursive = TRUE, showWarnings = FALSE)
gadm(
country = country,
level = 0,
path = "data/shapefiles",
version = "4.1",
# low res
resolution = 2
)
}
But this feels against the suggested workflow in that it requires creating a directory and specifying a path? |
So, I think that in the case of After Aariq@f82edd4 you can easily do something like If you want to have the file(s) produced by You might need to have one In general |
Let's move the discussion about |
Yes I think let's close this issue and open a new one about gadm :) |
Also I should say, thank you @brownag for your explanation above! Much appreciated, :) |
An alternative to
utils::zip()
may be to write shapefiles as .shz/.shp.zip extension and readily use seek-optimized ZIPFrom https://gdal.org/user/virtual_file_systems.html#sozip-seek-optimized-zip
While this would allow for us to easily make use of seek-optimize ZIP, I think it still does not get us around the need to have the target object name end in ".shz" or ".zip" so that GDAL can detect the file on read.#4 (comment)The text was updated successfully, but these errors were encountered: