View source: R/spatial_tools.R
invert_poly | R Documentation |
This function inverts a (spatial) polygon so that the ‘inside’ of the original polygon becomes the ‘outside’ and vice-versa. The function was motivated by marine applications in which polygons that define the coastline ‘contain’ land and need to be inverted to define the sea.
invert_poly(x, boundaries = raster::extent(x), ...)
x |
An |
boundaries |
A |
... |
Additional arguments passed to |
The function returns a SpatialPolygons-class
object.
Edward Lavender
#### Example (1): Compare original and inverted polygon
# In this example, we have a polygon that defines the coastline
# ... with the polygon enclosing the land. We can invert
# ... the polygon to return a polygon that defines the sea.
pp <- graphics::par(mfrow = c(1, 2))
raster::plot(dat_coast, col = "darkgreen")
dat_sea <- invert_poly(dat_coast)
raster::plot(dat_sea, col = "skyblue")
graphics::par(pp)
# The CRS of the two objects is identical
raster::crs(dat_coast)
raster::crs(dat_sea)
# Compare the classes of the two objects
class(dat_coast)
class(dat_sea)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.