centroids function

Centroids

Centroids

Get the centroids of polygons or lines, or centroid-like points that are guaranteed to be inside the polygons or on the lines.

## S4 method for signature 'SpatVector' centroids(x, inside=FALSE)

Arguments

  • x: SpatVector
  • inside: logical. If TRUE the points returned are guaranteed to be inside the polygons or on the lines, but they are not the true centroids. True centroids may be outside a polygon, for example when a polygon is "bean shaped", and they are unlikely to be on their line

Returns

SpatVector of points

Examples

f <- system.file("ex/lux.shp", package="terra") v <- vect(f) x <- centroids(v) y <- centroids(v, TRUE)
  • Maintainer: Robert J. Hijmans
  • License: GPL (>= 3)
  • Last published: 2025-02-26