nearestLand: Find nearest non-NA pixels to a set of points

Description Usage Arguments Value See Also Examples

Description

Given a set of points (points), find the nearest cells in raster which are not NA, up to a maximum search radius of max_distance.

Usage

1
nearestLand(points, raster, max_distance)

Arguments

points

A two-column matrix or dataframe giving x and y coordinates, or a SpatialPoints* object.

raster

A Raster* object from which to find the nearest non-cells.

max_distance

The maximum distance to search before giving up and returning NA. If raster is projected, this is in the map units, otherwise it is in metres.

Value

A two-column matrix giving the coordinates of the nearest cells, or NA values if there was no non-NA cell within max_distance of the points.

See Also

checkOccurrence

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# load the template raster
data(template)

# generate 100 random points on the raster
n <- 100
pts <- matrix(c(runif(n, -10, 10), runif(n, -5, 15)), ncol = 2)

# plot them
plot(template)
points(pts, pch = 16)

# find those which fall in NA areas on the raster
vals <- extract(template, pts)
outside_mask <- is.na(vals)
outside_pts <- pts[outside_mask, ]

# plot these in blue
points(outside_pts, pch = 16, col = 'blue')

# find the nearest land within 5 decimal degrees of these
land <- nearestLand(outside_pts, template, 2)

# count how many were moved
sum(!is.na(land[, 1]))

# and how many were too far out
sum(is.na(land[, 1]))

# plot the new points (for those which were reassigned) in green
points(land, pch = 16, col = 'dark green')

# plot where they moved to
arrows(outside_pts[, 1],
       outside_pts[, 2],
       land[, 1],
       land[, 2], length = 0.1)

SEEG-Oxford/seegSDM documentation built on May 9, 2019, 11:08 a.m.