filterByProximity: Filter by proximity

View source: R/filterByProximity.R

filterByProximityR Documentation

Filter by proximity

Description

Filter occurrence records by their proximity to each other.

Usage

filterByProximity(xy, dist, returnIndex = FALSE)

Arguments

xy

longitude and latitude in decimal degrees, either as a matrix, dataframe, or spatial points object.

dist

minimum allowed distance in km

returnIndex

if TRUE, will return indices of points that would be dropped, if FALSE, returns the points that satisfy the distance filter.

Details

This function will discard coordinates that fall within a certain distance from other points.

Value

If returnIndex = TRUE, returns a numeric vector of indices. If returnIndex = FALSE, returns coordinates of the same class as the input.

Author(s)

Pascal Title

Examples


data(crotalus)

# within the first 100 points in the dataset, identify the set of points to 
# drop in order to have points no closer to each other than 20 km

subset <- crotalus[1:100,]
tooClose <- filterByProximity(xy= subset[ ,c('decimallongitude','decimallatitude')], 
	dist=20, returnIndex = TRUE)

plot(subset[ ,c('decimallongitude','decimallatitude')], pch=1, col='blue', cex=1.5)
points(subset[tooClose, c('decimallongitude','decimallatitude')], pch=20, col='red')


# testing different input options
samp <- sample(1:nrow(crotalus), 100)
xy <- crotalus[samp, c('decimallongitude', 'decimallatitude')]
sfpts <- sf::st_as_sf(xy, coords = c('decimallongitude', 'decimallatitude'), crs = 4326)
sfptsEA <- sf::st_transform(sfpts, crs = '+proj=eqearth')
spPts <- as(sfpts, 'Spatial')
filterByProximity(xy, dist=20, returnIndex = TRUE)
filterByProximity(sfpts, dist=20, returnIndex = TRUE)
filterByProximity(sfptsEA, dist=20, returnIndex = TRUE)
filterByProximity(spPts, dist=20, returnIndex = TRUE)


rangeBuilder documentation built on March 7, 2023, 5:30 p.m.