| centroids {terra} | R Documentation |
Centroids
Description
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.
Usage
## S4 method for signature 'SpatVector'
centroids(x, inside=FALSE)
## S4 method for signature 'SpatRaster'
centroids(x, weighted=FALSE)
Arguments
x |
SpatVector |
inside |
logical. If |
weighted |
logical. If |
Value
SpatVector of points
Examples
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)
[Package terra version 1.8-93 Index]