How do you use Clip_management in a python loop to clip rasters?

4152
2
01-30-2015 01:54 PM
PamFroemke
New Contributor

Hello,

I'm trying to use Clip_management to clip 8 rasters to about 200 different polygon boundaries. I've got it in a python loop, but am stymied by the 'rectangle' part of the syntax for that tool. I can't hard-code that info as it changes for each polygon, I'm assuming.

 

Can I specify a rectangle extent that encompasses all of the polygons (generally in the state of Colorado)?

 

Thank you!

Tags (4)
0 Kudos
2 Replies
JoshuaBixby
MVP Esteemed Contributor

It is easier for fellow GeoNet community members to provide feedback if you post relevant, functional parts of your code.

0 Kudos
XanderBakker
Esri Esteemed Contributor

This thread shows how you can loop through polygons and extract the raster by mask: Re: Zonal statistics - percentiles .

When you loop through the polygons, each polygon has a extent property. This can be used in the Clip Management tool like this:

ext = polygon.extent
rect = "{0} {1} {2} {3}".format(ext.XMin, ext.YMin, ext.XMax, ext.YMax)

... and yes I would be a lot better if you would post the code.

0 Kudos