natario
natario

Reputation: 25194

Extracting points that belong to a certain area of a RasterLayer (raster)

As per title.

I have a "classified" RasterLayer object which has (apart from NAs) two fixed values, 0 and 1. It is a kind of logical image.

I also have a data frame of points with their coordinates, in form of a SpatialPointsDataFrame.

How can I extract points belonging to a certain area (0 or 1)? Been searching into raster-package help but I couldn't find a solution.

Upvotes: 2

Views: 552

Answers (1)

maRtin
maRtin

Reputation: 6516

You can use extract from the raster package:

"Extract values from a Raster* object at the locations of other spatial data (that is, perform a spatial query). You can use coordinates (points), lines, polygons or an Extent (rectangle) object. You can also use cell numbers to extract values."

values <- extract(x="YourRasterLayer", y="YourSpatialPointsDataFrame")

For more information type:

?raster::extract

or visit this page.

Upvotes: 2

Related Questions