I have a question concerning the extraction of spatial points that match a certain value of an additional raster in R. The operation itself should actually be pretty simple, but I'm stuck somehow. (I am using R at a "lower intermediate" level).
I am using two data sets. The first one is a shapefile containing point data.
training1 <- shapefile ("re_27042015projcrop_all.shp")
The second one is a "binary mask" raster object consisting solely of 0 and 1 values.
radar1 <- brick ("binary_01_180115_240415.envi")
How do I extract all points whose coordinates match raster pixels with a value of 1?
I tried some logical expressions like
output <- training1@coords & radar1==1
and various raster functions like crop, mask etc., but none seemed to work.
Best Answer
You need to create a logic test to select those points. With an example:
r
is a binary raster andpts
is a point layer with 100 features, let's see raster values of points position:We have 0 and 1 values, to select only the points with position over values equal to 0, it's necessary to create a logic vector and select rows with this vector:
Now, let's see values of this new layer: