wt.centroid

0th

Percentile

Weighted centroid

Creates centroid of [x,y] coordinates based on a weights field

Usage
wt.centroid(x, p, sp = TRUE)
Arguments
x

sp SpatialPointsDataFrame class object

p

Weights column in x@data slot

sp

Output sp SpatailPoints class object (TRUE | FALSE)

Value

A vector or an sp class SpatialPoints object of the weighted coordinate centroid

Note

The weighted centroid is calculated as: [Xw]=[X]*[p], [Yw]=[Y]*[p], [sXw]=SUM[Xw], [sYw]=SUM[Yw], [sP]=SUM[p] wX=[sXw]/[sP], wY=[sYw]/[sP] where; X=X COORDINATE(S), Y=Y COORDINATE(S), p=WEIGHT

Depends: sp

• wt.centroid
Examples
# NOT RUN {
require(sp)
data(meuse)
coordinates(meuse) = ~x+y
wt.copper <- wt.centroid(meuse, 'copper', sp=TRUE)
wt.zinc <- wt.centroid(meuse, 'zinc', sp=TRUE)
plot(meuse, pch=20, cex=0.75, main='Weighted centroid(s)')
points(wt.copper, pch=19, col='red', cex=1.5)
points(wt.zinc, pch=19, col='blue', cex=1.5)
box()
legend('topleft', legend=c('all','copper', 'zinc'),
pch=c(20,19,19),col=c('black','red','blue'))

# }

Documentation reproduced from package spatialEco, version 1.3-2, License: GPL-3

Community examples

Looks like there are no examples yet.