Extracts points from raster layers using the original raster layer projection.

genericExtract(x, y, field = NULL, ...)

Arguments

x

a raster or polygon object (sp, raster or terra)

y

a points or polygons spatial object (sp, sf, or terra)

field

character. The field(s) to extract when x is a polygon. If NULL, all fields are extracted and returned. IDs of y are always returned (ID column).

...

passed to terra::extract()

Value

a data.table with extracted values and an ID column of y point IDs

Details

If x and y are both polygons, extract often outputs NA due to misalignments (this can happen even when x == y), even after snap(y, x). To circumvent this problem, intersect is used internally and, if the extract argument fun is passed, it is applied to values of y per polygon ID of x.