spatialKMeans: Smooth/thin out a large number of points or polygons by...

View source: R/spatialKMeans.R

spatialKMeansR Documentation

Smooth/thin out a large number of points or polygons by taking a spatially weighted k means

Description

In other words: 1) get k spatially representative points by performing k-means on a 2D matrix of lng lat 2) for each of these centroids, aggregate some function (e.g. median) of the covariates var over the numClosestPoints closest points spatially to get an idea of the value of var in a neighbourhood

Usage

spatialKMeans(
  shp,
  var,
  numCentroids = NULL,
  propToKeep = NULL,
  numClosestPoints = 10,
  aggFct = function(x) {
     median(x, na.rm = T)
 },
  iter.max = 10^3
)

Arguments

var

- string - variable to summarise

numCentroids

number of representative points to take (use EITHER numCentroids or numClosestPoints)

numClosestPoints

- analogous to bandwidth - larger number reduces the variance (use EITHER numCentroids or numClosestPoints)

aggFct

- function to use to summarise - e.g. median or mean

iter.max

max number of iterations for kmeans

Value

shpCentroids with column var


cgauvi/sfSpHelpers documentation built on June 30, 2023, 10:48 p.m.