points2nearestcell: Move occurrences to the nearest raster cell with data

Description Usage Arguments Value See Also Examples

View source: R/points2nearestcell.R

Description

Move point occurrences falling in raster cells without data (i.e. NA) to the nearest raster cell with data.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
points2nearestcell(
  locs = NULL,
  ras = NULL,
  layer = 1,
  move = TRUE,
  distance = NULL,
  showchanges = TRUE,
  showmap = TRUE,
  leaflet = FALSE
)

Arguments

locs

A SpatialPoints or SpatialPointsDataFrame.

ras

Raster* object.

layer

Integer. For RasterStack and RasterBrick objects, layer to use.

move

Logical. Change coordinates of points to those of the nearest raster cells?

distance

Numeric (optional). Maximum distance to move points. Point coordinates are only changed if the distance to the nearest raster cell is below distance.

showchanges

Logical. Print table with old and new coordinates.

showmap

Logical. Show map with original and new coordinates?

leaflet

Logical. If TRUE, show leaflet map instead of static map.

Value

A SpatialPointsDataFrame (with corrected coordinates if move is TRUE).

See Also

https://github.com/SEEG-Oxford/seegSDM/blob/master/man/nearestLand.Rd and https://stackoverflow.com/questions/27562076/if-raster-value-na-search-and-extract-the-nearest-non-na-pixel and http://stackoverflow.com/questions/26652629/extracting-a-value-from-a-raster-for-a-specific-point-based-on-the-closest-cell/26688361#26688361 and https://rdrr.io/cran/spatstat/man/nearest.raster.point.html.

Examples

1
2
3
4
5
6
7
## Not run: 
data(acaule)
locs <- locs2sp(acaule)
ras <- getData('worldclim', var = 'tmin', res = 10)
check.coords <- points2nearestcell(locs, ras)

## End(Not run)

Pakillo/rSDM documentation built on Oct. 15, 2020, 3:20 a.m.