elimCellDups: Thin spatial points so that no more than one point falls...

View source: R/elimCellDups.r

elimCellDupsR Documentation

Thin spatial points so that no more than one point falls within each cell of a raster

Description

This function thins spatial points such that no more than one point falls within each cell of a reference raster. If more than one point falls in a cell, the first point in the input data is retained unless the user specifies a priority for keeping points.

Usage

elimCellDups(x, rast, longLat = NULL, priority = NULL)

Arguments

x

Points. This can be either a data.frame, matrix, SpatialPoints*, SpatVector, or sf object.

rast

Raster* or SpatRaster object.

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* or sf object then this is ignored.

priority

Either NULL, in which case for every cell with more than one point the first point in x is chosen, or a numeric or character list indicating preference for some points over others when points occur in the same cell. There should be the same number of elements in priority as there are points in x. Priority is assigned by the natural sort order of priority. For example, for 3 points in a cell for which priority is c(2, 1, 3), the script will retain the second point and discard the rest. Similarly, if priority is c('z', 'y', 'x') then the third point will be chosen. Priorities assigned to points in other cells are ignored when thinning points in a particular cell.

Value

Object of class x.

Examples


x <- data.frame(
		long=c(-90.1, -90.1, -90.2, 20),
	lat=c(38, 38, 38, 38), point=letters[1:4]
)
rast <- raster::raster() # empty raster covering entire world with 1-degree resolution
elimCellDups(x, rast, longLat=c(1, 2))
elimCellDups(x, rast, longLat=c(1, 2), priority=c(3, 2, 1, 0))


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