geoThinApprox: Thin geographic points stochastically

View source: R/geoThinApprox.r

geoThinApproxR Documentation

Thin geographic points stochastically

Description

This function thins a set of geographic points so of the remainder, none are closer than a given distance. The function is nearly the same as the function thin.algorithm in the spThin package, except that it accepts a data frame, matrix, SpatialPoints, or SpatialPointsDataFrame as a main argument and the user can specify the distance function to be used and that it returns an object of the same kind.

Usage

geoThinApprox(
  x,
  minDist,
  longLat = NULL,
  distFunct = NULL,
  verbose = FALSE,
  ...
)

Arguments

x

Data frame, matrix, or SpatialPoints* object. See Details for further information on the coordinate reference system.

minDist

Numeric. Minimum distance (usually in m) thinned points must be from their nearest neighbor.

longLat

Two-element character list or two-element integer list. If x is a data frame then this should be a character list specifying the names of the fields in x or a two-element list of integers that correspond to longitude and latitude (in that order). For example, c('long', 'lat') or c(1, 2). If x is a matrix then this is a two-element list indicating the column numbers in x that represent longitude and latitude. For example, c(1, 2). If x is a SpatialPoints object then this argument is ignored.

distFunct

Either a function or NULL. If NULL then distGeo is used to calculate distances. More accurate distances can be obtained by using other functions (see distHaversine and references therein). Alternatively, a custom function can be used so long as its first argument is a 2-column numeric matrix with one row for the x- and y-coordinates of a single point and its second argument is a two-column numeric matrix with one or more rows of other points.

verbose

Logical. If TRUE then display progress.

...

Extra arguments to pass to distFunct.

Details

If x is a data frame or a matrix then it will be assumed to be unprojected (WGS84 coordinate reference system) and minDist should be in units of meters.

Value

Object of class x.

See Also

distGeo, geoThin

Examples

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])
set.seed(123)
geoThinApprox(x, 10000, longLat=c(1, 2)) # run #1
geoThinApprox(x, 10000, longLat=c(1, 2)) # run #2
geoThinApprox(x, 10000, longLat=c(1, 2)) # run #3
geoThinApprox(x, 10, longLat=c(1, 2))

# example using SpatialPointsDataFrame
data(lemur)
data(mad0)
par(mfrow=c(1, 3))
for (count in 1:3) {
    plot(mad0, main='Madagascar')
    points(lemur, col='red')
    thinned <- geoThinApprox(lemur, 50000)
    points(thinned, pch=16)
    legend('topright', legend=c('retained', 'discarded'),
    col=c('black', 'red'), pch=c(16, 1))
}

adamlilith/enmSdm documentation built on Jan. 6, 2023, 11 a.m.