Description Usage Arguments Details Value Examples

View source: R/pts2poly_centroids.R

Create polygon(s) from a data frame with coordinates of the polygon centroid(s)

1 | ```
pts2poly_centroids(x, y, ...)
``` |

`x` |
data frame with at least two columns; the first two columns must contain longitude and latitude coordinates, respectively. See 'Details' section for how additional columns are handled |

`y` |
numeric; the perpendicular distance from the polygon centroid (center) to its edge (i.e. half the length of one side of a polygon) |

`...` |
passed to st_sf or to st_sfc,
e.g. for passing named arguments |

This function was designed for someone who reads in a .csv file with a grid of coordinates representing SDM prediction points and needs to create prediction polygons with the .csv file coordinates as the polygon centroids. However, the function can be used to create square polygons of any size around the provided points, regardless of if those polygons touch or overlap. The created polygons are oriented so that, in a 2D plane, their edges are parallel to either the x or the y axis.

If `x`

contains more than two column, then additional columns will be treated as simple feature attributes,
i.e. passed along as the first argument to st_sf

If a `crs`

is not specified in `...`

,
then the `crs`

attribute of the polygon(s) will be `NULL`

.

Object of class `sfc`

(if `x`

has exactly two columns) or class `sf`

(if `x`

has exactly more than two columns). The object will have a geometry type of `POLYGON`

.
If the object is of class `sf`

, the name of the geometry list-column will be "geometry"

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ```
# Create an sfc object from a data frame of two columns
x <- data.frame(
lon = c(5, 10, 15, 20, 5, 10, 15, 20),
lat = c(5, 5, 5, 5, 10, 10, 10, 10)
)
pts2poly_centroids(x, 2.5, crs = 4326)
# Create an sf object from a data frame of more than two columns
x <- data.frame(
lon = c(5, 10, 15, 20, 5, 10, 15, 20),
lat = c(5, 5, 5, 5, 10, 10, 10, 10),
sdm.pred = runif(8),
sdm.pred2 = runif(8)
)
pts2poly_centroids(x, 2.5, crs = 4326, agr = "constant")
``` |

eSDM documentation built on May 4, 2021, 9:07 a.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.