-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* raster digest working in principle * reliéfy se vcelku líbí * tests complete locally * vignette updated * tests rewrite * typo tuning
- Loading branch information
Showing
17 changed files
with
171 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ inst/doc | |
/data-raw/vodstvo/* | ||
/data-raw/TRANS/* | ||
/data-raw/HYDRO/* | ||
/data-raw/eu_dem* | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,65 @@ | ||
#' Vyskopis | ||
#' | ||
#' Terrain of the Czech Republic as a {raster} package object. | ||
#' Terrain of the Czech Republic as a {terra} package object. | ||
#' | ||
#' The function returns a raster file of either actual relief (values are meters above sea level) or rayshaded relief (created via highly recommended {rayshader} package). | ||
#' The function returns a raster file of either actual terrain (values are meters above sea level) or rayshaded relief.. | ||
#' | ||
#' The raster is 5084 by 3403 cells, meaning each pixel is about 90 × 90 meters. It works the best at level of country or regions, at the level of a city or lower it may be somewhat grainy. | ||
#' The raster is created from EU DEM 1.1 file by Copernicus Land Monitoring service. The original file has pixel resolution 25×25 meters, which is too detailed for purposes of the package and was downsampled by factor of 4. | ||
#' | ||
#' The extent of the raster file is bouding box of the Czech Republic; this is a change to prior versions in order to better facilitate use of the raster in natural sciences context. To preserve compatibility optional argument `cropped` has been created, defaulting to `TRUE` (i.e. behaviour before v1.10.0). | ||
#' | ||
#' Due to package size constraints both versions are stored externally (and a working internet connection is required to use the package). | ||
#' | ||
#' The data is current to September 2016. Downloaded size of the rayshaded raster is 8.4 MB, actual raster is 31.4 MB. | ||
#' The data is current to year 2011 (but it is not expected to materially change over time). Downloaded size of the rasters is 52 MB. | ||
#' | ||
#' @param format Should the function return actual terrain (meters above sea level) or shaded relief (rayshaded). Allowed values are "actual" and "rayshaded". | ||
#' | ||
#' @param format Should the function return actual relief (meters above sea level) or shaded relief (rayshaded). Allowed values are "actual" and "rayshaded". | ||
#' @param cropped Should the raster provide data over Czech Republic's bounding box (cropped = FALSE) or just actual borders (cropped = TRUE). Defaults to TRUE to preserve compatiblity with earlier versions. | ||
#' | ||
#' @return \code{raster} package RasterLayer. | ||
#' @return \code{terra} package SpatRaster | ||
#' | ||
#' @source © ArcČR, ARCDATA PRAHA, ZÚ, ČSÚ, 2016 \url{https://www.arcdata.cz/produkty/geograficka-data/arccr-4} | ||
#' @source Copernicus Land Monitoring service, with funding by the European Union. \url{https://land.copernicus.eu/imagery-in-situ/eu-dem} | ||
#' | ||
#' @examples | ||
#' \donttest{ | ||
#' library(raster) | ||
#' library(terra) | ||
#' | ||
#' # original extent - bounding box over Czech Republic | ||
#' original_extent <- vyskopis("rayshaded", cropped = FALSE) | ||
#' | ||
#' plot(original_extent, col = gray.colors(16)) | ||
#' | ||
#' relief <- vyskopis("rayshaded") | ||
#' # add plot of country borders, for context | ||
#' plot(RCzechia::republika(), | ||
#' border = "red", | ||
#' col = NA, | ||
#' add = TRUE) | ||
#' | ||
#' # cropped to size - default behaviour | ||
#' cropped_extent <- vyskopis("rayshaded") | ||
#' | ||
#' plot(cropped_extent, col = gray.colors(16)) | ||
#' | ||
#' plot(relief, col = gray.colors(16)) | ||
#' } | ||
#' @export | ||
|
||
|
||
vyskopis <- function(format = "rayshaded") { | ||
vyskopis <- function(format = "rayshaded", cropped = TRUE) { | ||
if (!is.element(format, c("actual", "rayshaded"))) { | ||
stop(paste(format, "is not a valid format; recognized values are \"actual\" or \"rayshaded\".")) | ||
} # /if - valid resolution | ||
} # /if - valid format | ||
if (!is.element(cropped, c(TRUE, FALSE))) { | ||
stop(paste(cropped, "is not a valid value for cropped; recognized values are \"TRUE\" or \"FALSE\".")) | ||
} # /if - valid valid cropped | ||
|
||
if (format == "rayshaded") { | ||
result <- .downloader("Vyskopis-stiny.rds") | ||
result <- .downloader("vyskopis-shaded-dem.tif") | ||
} else { | ||
result <- .downloader("Vyskopis-vyska.rds") | ||
result <- .downloader("vyskopis-dem.tif") | ||
} # /if - download of result | ||
|
||
# need to handle CRAN policy | ||
if(cropped & !is.null(result)) result <- terra::crop(result, terra::vect(RCzechia::republika("low")), mask = TRUE) | ||
|
||
result | ||
} # /function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# spojí DEM data z https://land.copernicus.eu/imagery-in-situ/eu-dem/eu-dem-v1.1 | ||
# a ořízne dle potřeby | ||
|
||
library(terra) | ||
library(dplyr) | ||
library(sf) | ||
|
||
dolni <- terra::rast("./data-raw/eu_dem_v11_E40N20.TIF") | ||
horni <- terra::rast("./data-raw/eu_dem_v11_E40N30.TIF") | ||
|
||
celek <- terra::merge(horni, dolni) | ||
|
||
# okolí republiky (ne jej) | ||
maska <- RCzechia::republika() %>% | ||
st_bbox() %>% | ||
st_as_sfc() %>% | ||
st_transform(st_crs(celek)) | ||
|
||
cast <- crop(celek, maska, mask = T) | ||
|
||
cast <- terra::aggregate(cast, fact = 4) # 25 m >> 100 m pixel size | ||
|
||
# https://dieghernan.github.io/202210_tidyterra-hillshade/ | ||
slope <- terrain(cast, "slope", unit = "radians") | ||
aspect <- terrain(cast, "aspect", unit = "radians") | ||
hill <- shade(slope, aspect, 30, 270) | ||
|
||
# normalize names | ||
names(hill) <- "shades" | ||
|
||
cast <- terra::project(cast, "EPSG:4326") | ||
hill <- terra::project(hill, "EPSG:4326") | ||
|
||
writeRaster(cast, "./data-backup/vyskopis-dem.tif", overwrite = T) | ||
writeRaster(hill, "./data-backup/vyskopis-shaded-dem.tif", overwrite = T) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.