12
12
# ' @param variable Name of the desired variable. Current options include "dem",
13
13
# ' and "nlcd".
14
14
# ' @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.
15
18
# ' @param nlcd_year Year of nlcd data. Acceptable values are 2019 (default),
16
19
# ' 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
19
22
# ' 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
21
24
# ' precedent.
22
25
# ' @param output_file Path and file name of raster to be saved.
23
26
# '
@@ -30,9 +33,10 @@ download_terrain_variables <- function(bbox,
30
33
data_source ,
31
34
variable ,
32
35
label ,
36
+ res_ned = " 1" ,
33
37
nlcd_year = NULL ,
34
- res = NULL ,
35
- res_example = NULL ,
38
+ res_final = NULL ,
39
+ res_final_example = NULL ,
36
40
output_file ){
37
41
38
42
# -----------------
@@ -47,6 +51,7 @@ download_terrain_variables <- function(bbox,
47
51
if (variable == " dem" ){
48
52
terrain_raster <- FedData :: get_ned(template = bbox ,
49
53
label = label ,
54
+ res = res_ned ,
50
55
force.redo = TRUE )
51
56
method <- " bilinear"
52
57
}
@@ -62,24 +67,24 @@ download_terrain_variables <- function(bbox,
62
67
# -----------------
63
68
# Reproject
64
69
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 )
66
71
67
72
# -----------------
68
73
# Change resolution
69
74
70
75
# 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
73
78
# the terra::res function keeps the xmin and ymin extents the same, but
74
79
# 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.
76
81
77
82
# 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
80
85
} else {
81
86
terrain_raster_empty <- terrain_raster_reproject
82
- terra :: res(terrain_raster_empty ) <- res
87
+ terra :: res(terrain_raster_empty ) <- res_final
83
88
}
84
89
85
90
# Resample
@@ -93,6 +98,7 @@ download_terrain_variables <- function(bbox,
93
98
# -----------------
94
99
# Write output
95
100
101
+ setGDALconfig(" GDAL_PAM_ENABLED" , " FALSE" ) # Prevent xml files from being generated
96
102
terra :: writeRaster(terrain_raster_res , filename = output_file , overwrite = TRUE )
97
103
98
104
return (terrain_raster_res )
0 commit comments