elimCellDuplicates {enmSdmX} | R Documentation |
Thin spatial points so that there is but one per raster cell
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
elimCellDuplicates(x, rast, longLat = NULL, priority = NULL)
Arguments
x |
Points. This can be either a data.frame , matrix , SpatVector , or sf object.
|
rast |
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 an 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
# This example can take >10 second to run.
library(terra)
x <- data.frame(
long=c(-90.1, -90.1, -90.2, 20),
lat=c(38, 38, 38, 38), point=letters[1:4]
)
rast <- rast() # empty raster covering entire world with 1-degree resolution
elimCellDuplicates(x, rast, longLat=c(1, 2))
elimCellDuplicates(x, rast, longLat=c(1, 2), priority=c(3, 2, 1, 0))
[Package
enmSdmX version 1.1.6
Index]