Learn R Programming

rangeBuilder (version 2.1)

filterByLand: Filter occurrences based on land vs ocean

Description

Identifies occurrence records that do not occur on land.

Usage

filterByLand(coords, crs = 4326)

Value

returns a logical vector where TRUE means the point falls on land.

Arguments

coords

coordinates in the form of a 2 column numeric matrix, data.frame, numeric vector, or spatial points object (sf or sp). If spatial object, crs must be defined.

crs

crs of input coords. Ignored if input coords are spatial object.

Author

Pascal Title

Details

This function uses a rasterized version of the GSHHG (global self-consistent, hierarchical, high-resolution geography database, https://www.soest.hawaii.edu/pwessel/gshhg/), that has been buffered by 2 km.

Examples

Run this code

data(crotalus)

#identify points that fall off land
filterByLand(crotalus[,c('decimallongitude','decimallatitude')])


# testing different input options
samp <- sample(1:nrow(crotalus), 10)
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')
filterByLand(xy)
filterByLand(sfpts)
filterByLand(sfptsEA)
filterByLand(spPts)

Run the code above in your browser using DataLab