selectGridcells: Select gridcells

View source: R/selectGridcells.R

selectGridcellsR Documentation

Select gridcells

Description

Select gridcells from a Field (or a data.table or a data.frame) using either gridcell coordinates or polgyons (from, for example, a shapefile).

Usage

selectGridcells(
  x,
  gridcells,
  spatial.extent.id = NULL,
  tolerance = NULL,
  decimal.places = NULL,
  cover.threshold = NULL,
  ...
)

Arguments

x

The Field, data.table or data.frame from which the gridcells should be selected. Note that a data.table or data.frame should have columns "Lon" and "Lat" included.

gridcells

The gridcells to be extracted. These can be specified as one of the following:

  • A simple two-element numeric to pull out one gridcell (ordering is lon, lat)

  • A data.frame or data.table in which the first two columns are assumed to be longitude and latitude.

  • An sf:sf object. By default points will be selected that lie under a polygon (feature), but see the argument cover.threshold to select based on an overlap threshold. Note also that is very easy to get sf objects representing countries from the rnaturalearth package, which, in combination with this function, provides a very easy way to subset by country.

spatial.extent.id

A character string to describe the gridcells selected. When selecting gridcells from a Field you *must* specify a spatial.extent.id for meta-data consistency (you have free choice here, but avoid spaces).

tolerance

A single numeric specifying how close a required gridcell in gridcells must be to one in x. Doesn't currently work, non-exact matching is not implemented! Contact the author if this is a critical feature for you.

decimal.places

A single numeric specifying how many decimal place to which the coordinates should rounded to facilitate a match. If not specified not rounding is done.

cover.threshold

An optional numeric specifying what fraction of the gridcell must be covered by a feature in the case the gricells argument is a SpatialPolygonsDataFrame. Note that is done using the getCover argument of raster::rasterize() which is only sensitive to about 1% cover. fractions

...

Further arguments. Currently not used.

Value

A Field, data.frame or data.table depending on the class of the main input x.

Author(s)

Matthew Forrest matthew.forrest@senckenberg.de


MagicForrest/DGVMTools documentation built on Aug. 23, 2024, 8:05 a.m.