getMap.Rd
A function that checks if the DEMs for a given set of sectors exist in the workspace, and if not downloads them or crops them from a larger file
getMap(
tiles,
polys,
tile_id = "TILEID",
vals = "location",
z_min = NULL,
filt = 0,
verbose = FALSE,
dir = tempdir()
)
A character vector--such as the output to
whichTiles
---containing the unique tile IDs for sectors that
should be in the workspace.
A polygon of class SpatVector representing
the partitioning grid for the maximum possible area, in the same format as the
output of the makeGrid
function.
a character string representing the name of the column
in the polys
polygon containing the unique Tile IDs. Default is tile_id = 'TILEID'
A character string or a SpatRast or Raster* object. Optional if the
polys
polygon is the output of the makeGrid
function as the default is
the character string 'location'
. If no DEM was provided when makeGrid
was initially run (i.e. polys$location == NA), then the function will
use get_elev_raster
to download data.
If not from makeGrid
, the vals
parameter should be
set to the column name containing the URL or filepath to the DEM for that
sector.
The minimum allowable elevation. Useful if DEM source includes
ocean bathymetry as does the SRTM data from AWS. Default is z_min = NULL
,
but set to 0
for SRTM data.
Numeric. Size of moving window to apply a low-pass filter.
Default is filt = 0
.
Should the number of remaining sectors be printed? Default
is FALSE
A filepath to the directory being used as the workspace.
Default is tempdir()
but unless the analyses will only be performed a few
times it is highly recommended to define a permanent workspace.
Function does not return any objects, but sets up the workspace such that the necessary DEM files are downloaded/cropped and accessible.
# Generate a DEM, export it
n <- 5
dem <- expand.grid(list(x = 1:(n * 100),
y = 1:(n * 100))) / 100
dem <- as.data.table(dem)
dem[, z := 250 * exp(-(x - n/2)^2) +
250 * exp(-(y - n/2)^2)]
#> x y z
#> 1: 0.01 0.01 1.0146139
#> 2: 0.02 0.01 1.0404641
#> 3: 0.03 0.01 1.0675194
#> 4: 0.04 0.01 1.0958300
#> 5: 0.05 0.01 1.1254477
#> ---
#> 249996: 4.96 5.00 1.0711366
#> 249997: 4.97 5.00 1.0428260
#> 249998: 4.98 5.00 1.0157707
#> 249999: 4.99 5.00 0.9899205
#> 250000: 5.00 5.00 0.9652271
dem <- rast(dem)
ext(dem) <- c(10000, 20000, 30000, 40000)
crs(dem) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"
dir <- tempdir()
writeRaster(dem, paste0(dir,"/DEM.tif"),overwrite=TRUE)
# Import raster, get the grid
dem <- rast(paste0(dir,"/DEM.tif"))
grid <- makeGrid(dem = dem, nx = n, ny = n, sources = TRUE)
# Generate five random points that fall within the grid
points <- data.table(x = runif(5, ext(dem)[1], ext(dem)[2]),
y = runif(5, ext(dem)[3], ext(dem)[4]))
# Run whichTiles and getMap to prepare appropriate sector files
tile_list <- whichTiles(region = points, polys = grid)
getMap(tiles = tile_list, polys = grid, dir = dir)
#> [1] "Cropping Tile SECTOR_05 (1 of 5)"
#> [1] "Cropping Tile SECTOR_09 (2 of 5)"
#> [1] "Cropping Tile SECTOR_12 (3 of 5)"
#> [1] "Cropping Tile SECTOR_06 (4 of 5)"
#> [1] "Cropping Tile SECTOR_25 (5 of 5)"