-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvert_poly.Rd
41 lines (39 loc) · 1.55 KB
/
invert_poly.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spatial_tools.R
\name{invert_poly}
\alias{invert_poly}
\title{Invert a (spatial) polygon}
\usage{
invert_poly(x, boundaries = raster::extent(x), ...)
}
\arguments{
\item{x}{An \code{\link[sp]{SpatialPolygons-class}} or \code{\link[sp]{SpatialPolygonsDataFrame-class}} object.}
\item{boundaries}{A \code{\link[raster]{extent}} object that defines the boundaries of the area under consideration. By default, this is defined by the extent of \code{x}.}
\item{...}{Additional arguments passed to \code{\link[rgeos]{gDifference}}.}
}
\value{
The function returns a \code{\link[sp]{SpatialPolygons-class}} object.
}
\description{
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.
}
\examples{
#### 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)
}
\author{
Edward Lavender
}