topo-unary-gCentroid: Centroid of Geometry

Description Usage Arguments Details Author(s) See Also Examples

Description

Function calculates the centroid of the given geometry.

Usage

1
gCentroid(spgeom, byid=FALSE, id = NULL)

Arguments

spgeom

sp object as defined in package sp

byid

Logical determining if the function should be applied across subgeometries (TRUE) or the entire object (FALSE)

id

Character vector defining id labels for the resulting geometries, if unspecified returned geometries will be labeled based on their parent geometries' labels.

Details

Returns a SpatialPoints object of the centroid(s) for spgeom.

Author(s)

Roger Bivand & Colin Rundel

See Also

gBoundary gConvexHull gEnvelope gPointOnSurface

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
x = readWKT(paste("GEOMETRYCOLLECTION(POLYGON((0 0,10 0,10 10,0 10,0 0)),",
 "POLYGON((15 0,25 15,35 0,15 0)))"))

# Centroids of both the square and circle independently
c1 = gCentroid(x,byid=TRUE) 
# Centroid of square and circle together
c2 = gCentroid(x)

plot(x)
plot(c1,col='red',add=TRUE)
plot(c2,col='blue',add=TRUE)

rgeos documentation built on Sept. 7, 2020, 5:08 p.m.