[GIS] How to clip multiple raster datasets with county polygons

arcgis-desktoparcpy

The example below shows three raster (i.e. in black) and a single county polygon feature class. How can I clip/extract by mask the rasters by their corresponding county polygons (i.e. Edwards, Clark, Barber) in an automated fashion? For this example, the output should include three separate rasters clipped to the county boundaries. A python or ArcGIS solution suitable for batch processing would be ideal. Thanks for the help.

enter image description here

Best Answer

Presumably since you want to automate this, you'll want each raster to figure out which polygon should be used to clip itself? Pseudo code:

  • iterate through the list of list of input rasters
  • convert the raster to a polygon
  • obtain the polygon's centroid
  • determine which county polygon the centroid (and therefore the raster) falls within
  • convert that polygon to a County raster, with a value of 1 (and everything else 0 or NULL)
  • multiply the county raster with the original raster