spatialEco (version 1.3-2)

wt.centroid: Weighted centroid

Description

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

Examples

Run this code
# 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'))

# }

Run the code above in your browser using DataLab