Get the names of tiles that would be needed to perform an analysis over a given region-of-interest within the maximum possible extent defined by a source grid.

whichTiles(region, polys, tile_id = "TILEID", x = "x", y = "y")

Arguments

region

An object of class SpatRaster, SpatVector Raster*, Spatial*, data.frame, or data.table indicating the region-of-interest. If input is of class SpatialPoints*, data.table, or data.frame the region represents sectors containing the individual points.

polys

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.

tile_id

a character string representing the name of the column in the polys polygon containing the unique Tile IDs. Default is tile_id = 'TILEID'

x

a character string representing column name containing the "x" coordinates. Required for SpatialPoints*, data.frame, and data.table region, otherwise ignored.

y

a character string representing column name containing the "y" coordinates. Required for SpatialPoints*, data.frame, and data.table region, otherwise ignored.

Value

A character vector containing the TILEIDs overlapping with the region

Examples


#### Example 1:
# If the grid is the product if the makeGrid function
# Make the grid
n <- 6
dem <- rast(ncol = n * 600, nrow = n * 600, vals = 1)
ext(dem) <- c(1000, 2000, 3000, 4000)
crs(dem) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"
# Export it so it doesn't just exist on the memory
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)

# Select 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]))

tile_list <- whichTiles(region = points, polys = grid)

#### Example 2 (Do not execute):
## If it is a custom polygon "polys", where Tile IDs are stored in 
## a "NAME" column, and coordinates in "Easting" and "Northing"
# tile_list <- whichTiles(region = points, grid = polys, 
#                         tile_id = "NAME", x = "Easting", y = "Northing")