scott.w.anderson

Select subset of raster within a polygon and use only selected cells (raster layer?)

Discussion created by scott.w.anderson on Jun 10, 2014
Hello All,

I'm relatively new to python and arcpy, and was recently working to create a tool that performs calculations of raster values within an area defined by input polygons (a la zonal stats). Currently, I make a feature layer out of the polygon, select polygons within that layer that have a certain attribute, use that selection as a clip on the input raster, and then input the clipped raster into a numpy array to perform calculations. At the end of the process, I delete the clipped raster. This all works well enough, but it's definitely not as fast (about 3x-4x slower) as the built in zonal stats functions, and most of that extra time seems to be coming from the process of clipping and creating a whole new raster, and subsequently deleting it at the end.

I'm curious if it's possible to do a "select by location" style operation on a raster or raster layer, in the same fashion that I can select certain features in a feature layer and have various tools use only those selected features. So instead of actually creating a new raster, I simply create some sort of selection or mask so that when I dump the raster into a numpy array, only those selected cells show up. The actual 'select by location' doesn't accept raster layers as input, only mosaics or catalogs. At the moment, I don't care if the output retains spatial relationships - I just want a list of values.

The ultimate goal is to be able to perform zonal calculations quickly - so if my specific idea above is misguided, I'm very open to alternate ideas! 

Thanks!

Outcomes