I am trying to extract the area below 5000 feet for a 5 state area using the 30 meter (1 arc second) resolution NED (National Elevation Dataset), by state. I have a shapefile of the states, and a large (about 4GB) raster of the NED. I am using the velox package, which speeds things up significantly, but I feel there has to be a faster way to do this (it still takes a long time).
With the velox package, I make the raster into a velox object, then extract the cells using velox's extract function. Since I know the resolution of each cell, I count the # of cells below 5000 feet in each state and multiply by the area of each cell.
DEM_velox <- velox(NED)
DEM_cells <- DEM$extract(DEM_velox,sp=state_shapefile)
Isn't there a better and much faster way to do this? I know there's the area function from the raster package, and the gArea function from the rgeos package, but those are for polygons (shapefiles), not rasters, as far as I can tell. Any help on this would be great.
crop
the NED by your 5-state region or by state so that you're dealing with a much smaller object and thenmask
the smaller raster(s) so that elevations outside the state boundaries are set toNA
. Then you should be able to simply do a summation such as this to get the result:sum(values(cropped_masked_raster) <= 5000, na.rm=TRUE) * 30 * 30
to get the area in m^2 that meet your condition – ThetaFC