I'd like to use the Raster package in R to process a single DEM. I'd like to use a pre-determined list of elevation values to extract multiple raster datasets from this DEM. Not all values are of equal interval. For example, my DEM ranges between 5,000 and 6,000 ft. I'd like to use a pre-determined list of 10 values to clip this raster (similar to "extract by attribute" tool in Spatial Analyst). The values do not have equal intervals, for example: 5105 5225 5450 5500 . . . and so on...
At each step, I'd like to extract all values LESS than the specific value (e.g., where Value < 5,105).
If I were to do this manually, I'd set up a batch run to repeatedly use the "extract by attribute" tool in Spatial Analyst. I don't want to do that. I will have a lot of input DEMs to do in the future and I'd like to develop a script to chug through these quickly.
Anyone have any ideas?
Edit - Here is my code (still need help with the for loop to create separate DEMs):
library (rgdal)
library (raster)
#Import the DEM
dem <- raster("Path/to/DEM.tif")
elevs = c(5175.5, 5176.50, 5177.0, 5177.25, 5178.00)
#Extract DEM at at elevations less than elevs list
#This can be done manually as follows:
dem.5175.5 <- dem
dem.5175.5[dem.5175.5>5175.5]=NA
#Trying to do this iteratively through the list of elevs:
dem.copy <- dem
for (i in elevs) {
dem.copy[dem.copy>i]=NA
}
raster[raster > 5105] = NA
with whatever values you want.values = c(5105, 5225, 5450) for (i in values){raster[raster > i] = NA}