geoThin | R Documentation |
This function thins geographic points such that none have nearest neighbors closer than some user-specified distance. The results are almost deterministic (see Details).
geoThin(x, minDist, longLat = NULL, distFunct = NULL, verbose = FALSE, ...)
x |
Data frame, matrix, SpatialPoints, or SpatialPointsDataFrame object. |
minDist |
Numeric. Minimum distance needed between points to retain them. Points falling < this distance will be discarded. If |
longLat |
Two-element character list or two-element integer list. If |
distFunct |
Either a function or |
verbose |
Logical. If |
... |
Arguments to pass to |
The procedure for removing points is as follows:
Find points with largest number of neighbors (< minDist
away). If just one such point exists, remove it, but if there is more than one then...
Of these find the points with the closest neighbor within minDist
. If just one such point exists, remove it, but if there is more than one then...
Of these find the point that is closest to the centroid of all non-removed points. If just one such point exists, remove it, but if there is more than one...
Of these find the point that has the smallest median distance to all points (even if > minDist
). If just one such point exists, remove it, but if there is more than one then...
Of these randomly select a point and remove it.
Repeat.
Thus the results are deterministic up to the last tie-breaking step.
Object of class x
.
geoThinApprox
# example using data frame x <- data.frame(long=c(-90.1, -90.1, -90.15, -90.17, -90.2, -89), lat=c(38, 38, 38, 38, 38, 38), point=letters[1:6]) x geoThin(x, minDist=500, longLat=1:2, verbose=TRUE) geoThin(x, minDist=5000, longLat=c(1, 2), verbose=TRUE) # example of potential randomness set.seed(111) geoThin(x, minDist=1000, longLat=c(1, 2)) geoThin(x, minDist=1000, longLat=c(1, 2)) geoThin(x, minDist=1000, longLat=c(1, 2)) # example using SpatialPointsDataFrame data(lemurs) fulvus <- lemurs[lemurs$species == 'Eulemur fulvus', c('longitude', 'latitude')] fulvus <- sp::SpatialPointsDataFrame( fulvus, data=fulvus, proj4string=getCRS('wgs84', TRUE) ) data(mad0) sp::plot(mad0, main='Madagascar') points(fulvus, col='red') thinned <- geoThin(fulvus, 50000) points(thinned, pch=16) legend('topright', legend=c('retained', 'discarded'), col=c('black', 'red'), pch=c(16, 1)) # test to see function works when no points need removed thinned <- geoThin(fulvus, 200, verbose=TRUE) sp::plot(mad0, main='Madagascar') points(fulvus, col='red') points(thinned, pch=16) legend('topright', legend=c('retained', 'discarded'), col=c('black', 'red'), pch=c(16, 1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.