intersecting_units | R Documentation |
Find which of the units in a spatial data object intersect with the units in another spatial data object.
intersecting_units(x, y)
## S4 method for signature 'Raster,ANY'
intersecting_units(x, y)
## S4 method for signature 'ANY,Raster'
intersecting_units(x, y)
## S4 method for signature 'Spatial,ANY'
intersecting_units(x, y)
## S4 method for signature 'ANY,Spatial'
intersecting_units(x, y)
## S4 method for signature 'SpatRaster,SpatRaster'
intersecting_units(x, y)
## S4 method for signature 'sf,sf'
intersecting_units(x, y)
## S4 method for signature 'SpatRaster,sf'
intersecting_units(x, y)
## S4 method for signature 'sf,SpatRaster'
intersecting_units(x, y)
x |
|
y |
|
The performance of this function for large terra::rast()
objects
can be improved by increasing the GDAL cache size.
The default cache size is 25 MB.
For example, the following code can be used to set the cache size to 4 GB.
terra::gdalCache(size = 4000)
An integer
vector of indices of the units in x
that intersect
with y
.
See fast_extract()
for extracting data from spatial datasets.
## Not run:
# create data
r <- terra::rast(matrix(1:9, byrow = TRUE, ncol = 3))
r_with_holes <- r
r_with_holes[c(1, 5, 9)] <- NA
ply <- sf::st_as_sf(terra::as.polygons(r))
ply_with_holes <- sf::st_as_sf(terra::as.polygons(r_with_holes))
# intersect raster with raster
par(mfrow = c(1, 2))
plot(r, main = "x = SpatRaster", axes = FALSE)
plot(r_with_holes, main = "y = SpatRaster", axes = FALSE)
print(intersecting_units(r, r_with_holes))
# intersect raster with sf
par(mfrow = c(1, 2))
plot(r, main = "x = SpatRaster", axes = FALSE)
plot(ply_with_holes, main = "y = sf", key.pos = NULL, reset = FALSE)
print(intersecting_units(r, ply_with_holes))
# intersect sf with raster
par(mfrow = c(1, 2))
plot(ply, main = "x = sf", key.pos = NULL, reset = FALSE)
plot(r_with_holes, main = "y = SpatRaster")
print(intersecting_units(ply, r_with_holes))
# intersect sf with sf
par(mfrow = c(1, 2))
plot(ply, main = "x = sf", key.pos = NULL, reset = FALSE)
plot(ply_with_holes, main = "y = sf", key.pos = NULL, reset = FALSE)
print(intersecting_units(ply, ply_with_holes))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.