Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

intersecting_units

Find intersecting units


Description

Find which of the units in a spatial data object intersect with the units in another spatial data object.

Usage

intersecting_units(x, y)

## S4 method for signature 'Raster,Raster'
intersecting_units(x, y)

## S4 method for signature 'Spatial,Spatial'
intersecting_units(x, y)

## S4 method for signature 'sf,Spatial'
intersecting_units(x, y)

## S4 method for signature 'Spatial,Raster'
intersecting_units(x, y)

## S4 method for signature 'Spatial,sf'
intersecting_units(x, y)

## S4 method for signature 'Raster,Spatial'
intersecting_units(x, y)

## S4 method for signature 'sf,sf'
intersecting_units(x, y)

## S4 method for signature 'Raster,sf'
intersecting_units(x, y)

## S4 method for signature 'sf,Raster'
intersecting_units(x, y)

## S4 method for signature 'data.frame,ANY'
intersecting_units(x, y)

Arguments

x

Spatial or Raster object.

y

Spatial or Raster object.

Value

integer indices of the units in x that intersect with y.

See Also

Examples

# create data
r <- raster(matrix(1:9, byrow = TRUE, ncol=3))
r_with_holes <- r
r_with_holes[c(1, 5, 9)] <- NA
ply <- rasterToPolygons(r)
ply_with_holes <- st_as_sf(rasterToPolygons(r_with_holes))

# intersect raster with raster
## Not run: 
par(mfrow = c(1, 2))
plot(r, main = "x=Raster")
plot(r_with_holes, main = "y=Raster")

## End(Not run)
print(intersecting_units(r, r_with_holes))

# intersect raster with polygons (sf)
## Not run: 
par(mfrow = c(1, 2))
plot(r, main = "x=Raster")
plot(ply_with_holes, main = "y=sf", key.pos = NULL, reset = FALSE)

## End(Not run)
print(intersecting_units(r, ply_with_holes))

# intersect polygons (Spatial) with raster
## Not run: 
par(mfrow = c(1, 2))
plot(ply, main = "x=Spatial")
plot(r_with_holes, main = "y=Raster")

## End(Not run)
print(intersecting_units(ply, r_with_holes))

# intersect polygons (Spatial) with polygons (sf)
## Not run: 
par(mfrow = c(1, 2))
plot(ply, main = "x=Spatial")
plot(ply_with_holes, main = "y=sf", key.pos = NULL, reset = FALSE)

## End(Not run)
print(intersecting_units(ply, ply_with_holes))

prioritizr

Systematic Conservation Prioritization in R

v7.0.1
GPL-3
Authors
Jeffrey O Hanson [aut] (<https://orcid.org/0000-0002-4716-6134>), Richard Schuster [aut, cre] (<https://orcid.org/0000-0003-3191-7869>), Nina Morrell [aut], Matthew Strimas-Mackey [aut] (<https://orcid.org/0000-0001-8929-7776>), Matthew E Watts [aut], Peter Arcese [aut] (<https://orcid.org/0000-0002-8097-482X>), Joseph Bennett [aut] (<https://orcid.org/0000-0002-3901-9513>), Hugh P Possingham [aut] (<https://orcid.org/0000-0001-7755-996X>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.