Skip to content

Commit d7bb6a1

Browse files
committed
Added option to download 10 m DEM in addition to 30 m DEM. Added missing processing of subbasins. Bug fixes.
1 parent 4b85040 commit d7bb6a1

6 files changed

+36
-19
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Description: RHESSys Preprocessing is a set of functions that will produce the f
1111
License: MIT + file LICENSE
1212
Encoding: UTF-8
1313
LazyData: true
14-
RoxygenNote: 7.2.3
14+
RoxygenNote: 7.3.0
1515
Imports:
1616
terra,
1717
sf,

R/clip_landscape_rasters_by_basin.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ clip_landscape_rasters_by_basin <- function(work_folder,
3131

3232
raster_to_clip <- terra::rast(file.path(work_folder, rasters_to_clip[x]))
3333
clipped_raster <- terra::mask(raster_to_clip, mask = basin)
34-
terra::writeRaster(clipped_raster, filename = file.path(work_folder, names_output[x]), overwrite=TRUE)
34+
terra::writeRaster(clipped_raster, filename = file.path(work_folder, paste0(names_output[x], ".tif")), overwrite=TRUE)
3535

3636
return(clipped_raster)
3737
})

R/download_terrain_variables.R

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
#' @param variable Name of the desired variable. Current options include "dem",
1313
#' and "nlcd".
1414
#' @param label The name of the study area.
15+
#' @param res_ned The resolution of the NED product. '1' indicates the 1 arc-second
16+
#' (~30 m) NED (the default). A '13' indicates the 1/3 arc-second (~10 m)
17+
#' dataset.
1518
#' @param nlcd_year Year of nlcd data. Acceptable values are 2019 (default),
1619
#' 2016, 2011, 2008, 2006, 2004, and 2001.
17-
#' @param res Desired resolution in meters.
18-
#' @param res_example An spatraster with desired resolution for the downloaded
20+
#' @param res_final Desired final resolution in meters.
21+
#' @param res_final_example An spatraster with desired resolution for the downloaded
1922
#' data to be resampled to. In many cases, this will be same raster as bbox.
20-
#' If both `res` and `res_example` are not null, `res_example` takes
23+
#' If both `res_final` and `res_final_example` are not null, `res_final_example` takes
2124
#' precedent.
2225
#' @param output_file Path and file name of raster to be saved.
2326
#'
@@ -30,9 +33,10 @@ download_terrain_variables <- function(bbox,
3033
data_source,
3134
variable,
3235
label,
36+
res_ned = "1",
3337
nlcd_year = NULL,
34-
res = NULL,
35-
res_example = NULL,
38+
res_final = NULL,
39+
res_final_example = NULL,
3640
output_file){
3741

3842
# -----------------
@@ -47,6 +51,7 @@ download_terrain_variables <- function(bbox,
4751
if (variable == "dem"){
4852
terrain_raster <- FedData::get_ned(template = bbox,
4953
label = label,
54+
res = res_ned,
5055
force.redo = TRUE)
5156
method <- "bilinear"
5257
}
@@ -62,24 +67,24 @@ download_terrain_variables <- function(bbox,
6267
# -----------------
6368
# Reproject
6469

65-
terrain_raster_reproject <- terra::project(terrain_raster, y = terra::crs(paste0("epsg:", proj_epsg)))
70+
terrain_raster_reproject <- terra::project(terrain_raster, y = terra::crs(paste0("epsg:", proj_epsg)), method = method)
6671

6772
# -----------------
6873
# Change resolution
6974

7075
# Resample function in Terra requires an example of the raster with the
71-
# correct new resolution. If 'res_example' is available, we use it. Otherwise,
72-
# we create an empty 'res_example' raster with the new resolution. Note that
76+
# correct new resolution. If 'res_final_example' is available, we use it. Otherwise,
77+
# we create an empty 'res_final_example' raster with the new resolution. Note that
7378
# the terra::res function keeps the xmin and ymin extents the same, but
7479
# slightly adjusts the xmax and ymax extents to permit the new resolution. We
75-
# then resample from the original raster to the 'res_example' raster.
80+
# then resample from the original raster to the 'res_final_example' raster.
7681

7782
# Create raster with new resolution
78-
if (!is.null(res_example)){
79-
terrain_raster_empty <- res_example
83+
if (!is.null(res_final_example)){
84+
terrain_raster_empty <- res_final_example
8085
} else {
8186
terrain_raster_empty <- terrain_raster_reproject
82-
terra::res(terrain_raster_empty) <- res
87+
terra::res(terrain_raster_empty) <- res_final
8388
}
8489

8590
# Resample
@@ -93,6 +98,7 @@ download_terrain_variables <- function(bbox,
9398
# -----------------
9499
# Write output
95100

101+
setGDALconfig("GDAL_PAM_ENABLED", "FALSE") # Prevent xml files from being generated
96102
terra::writeRaster(terrain_raster_res, filename = output_file, overwrite=TRUE)
97103

98104
return(terrain_raster_res)

R/make_landscape_rasters.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ make_landscape_rasters <- function(dem,
101101
output = file.path(work_folder, "streams_landscape.tif"),
102102
threshold = stream_threshold)
103103

104+
# Subbasins
105+
whitebox::wbt_subbasins(d8_pntr = file.path(work_folder, "d8_pointer_landscape.tif"),
106+
streams = file.path(work_folder, "streams_landscape.tif"),
107+
output = file.path(work_folder, "subbasin_landscape.tif"))
108+
104109
# -----------------
105110
# Create patch maps
106111

man/RHESSysPreprocessing.Rd

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/download_terrain_variables.Rd

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)