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

spoly

Convert a data.frame of boundary points into a SpatialPolgonsDataFrame


Description

A polygon can be described as a sequence of points defining the polygon's boundary. When given such a sequence (anti clockwise!) this function creates a SpatialPolygonsDataFrame holding the polygon decribed. By default, the first two columns of data are assumed to define the x and y coordinates of the points. This behavior can ba changed using the cols parameter, which points out the names of the columns holding the coordinates. The coordinate reference system of the resulting spatial polygon can be set via the crs paraemter. Posterior conversion to a different CRS is supported using the to.crs parameter.

Usage

spoly(
  data,
  cols = colnames(data)[1:2],
  crs = CRS(NA_character_),
  to.crs = NULL
)

Arguments

data

A data.frame of points describing the boundary of the polygon

cols

Column names of the x and y coordinates within the data

crs

Coordinate reference system of the points

to.crs

Coordinate reference system for the SpatialLines ouput.

Value

SpatialPolygonsDataFrame

Examples

# Create data frame of boundary points (anti clockwise!)
pts <- data.frame(
  x = c(1, 2, 1.7, 1.3),
  y = c(1, 1, 2, 2)
)

# Convert to SpatialPolygonsDataFrame
pol <- spoly(pts)

# Plot it!
ggplot() +
  gg(pol)

inlabru

Bayesian Latent Gaussian Modelling using INLA and Extensions

v2.3.1
GPL (>= 2)
Authors
Finn Lindgren [aut, cre, cph] (<https://orcid.org/0000-0002-5833-2011>, Finn Lindgren continued development of the main code), Fabian E. Bachl [aut, cph] (Fabian Bachl wrote the main code), David L. Borchers [ctb, dtc, cph] (David Borchers wrote code for Gorilla data import and sampling, multiplot tool), Daniel Simpson [ctb, cph] (Daniel Simpson wrote the basic LGCP sampling method), Lindesay Scott-Howard [ctb, dtc, cph] (Lindesay Scott-Howard provided MRSea data import code), Seaton Andy [ctb] (Andy Seaton provided testing and bugfixes)
Initial release

We don't support your browser anymore

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