| centroids | R Documentation |
Get the centroids of polygons or lines, or centroid-like points that are guaranteed to be inside the polygons or on the lines.
Or get the (weighted) centroid of the the cells with values (not NA) of a SpatRaster.
## S4 method for signature 'SpatVector'
centroids(x, inside=FALSE)
## S4 method for signature 'SpatRaster'
centroids(x, weighted=FALSE)
x |
SpatVector |
inside |
logical. If |
weighted |
logical. If |
SpatVector of points
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
x <- centroids(v)
y <- centroids(v, TRUE)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
centroids(r)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.