Reputation: 25194
As per title.
I have a "classified" RasterLayer
object which has (apart from NA
s) 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
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