Batch Clip with Multiple Inputs

2267
5
12-12-2013 11:21 AM
MelissaSlater
New Contributor III
I am trying to run a batch clip for 60+ rasters and am looking for a way to incorporate a text/csv file with the location of the inputs and clip features. Is there a way to run the batch clip with out adding each item line by line?
Any help is appreciated.
Thanks.
Mel
0 Kudos
5 Replies
ChristopherBlinn1
Occasional Contributor III
Mel,

Rather than using the Clip Raster is Batch mode, have you considered creating a model to iterate through your rasters and clip them?

For a better explanation on ModelBuilder and Iterators see this page.

Hope this helps!

Best,
Chris B.
0 Kudos
MelissaSlater
New Contributor III
Chris, Thanks. I had looked at iterators but had read that I can only use 1 iterator per model. I am not sure how to iterate the raster dataset and call the extent polygon clip features in the same model with 1 iterator. Each raster and clip poly have a 1 to 1 relationship.
Any other suggestions?
Thanks,
Mel
0 Kudos
ChristopherBlinn1
Occasional Contributor III
Mel,

Just so I understand everything correctly, and I should have asked this first but:


  1. Are you clipping each raster with the same extent polygon?

  2. Are all of the rasters in the same folder, or geodatabase?


If the answer is yes to both of these, then I can walk you through setting up a very easy to use model.

Just let me know.

Thanks,
Chris B.
0 Kudos
MelissaSlater
New Contributor III
Chris,
Each raster has a unique polygon clip feature but yes, they are all in a single file/workspace.
And I need to retain each individual projection (hence I am not able to merge polys into a single dataset).
-Mel
0 Kudos
ChristopherBlinn1
Occasional Contributor III
Mel,

Embedding iterators is possible but not a very easy process, considering some of the naming conventions and parameter assignments that need to be made.

Inline variable substitution could be used if you happen to have rasters with similar names as the polygon clipping extents.

For example, if Raster_1 needs to be clipped by Extent_1, then only one iterator is necessary and a simple model using the inline variable identifying each raster and extent could be used.

Your CSV idea would work if you used python to read the CSV:

import arcpy
import csv

csvfile  = open('test.csv', "rb")
reader = csv.reader(csvfile)

i = 1
for row in reader:
    text = row.split(",")
    inraster = text[0]
    extent = text[1]
    outraster = text[2]
    
    arcpy.Clip_management(inraster, extent, outraster, "", "", "NONE")

     i += 1



This is not tested, but simply put, it reads a csv file (second row since first row is probably headers), and splits the row at the commas.  The first value of the row is the input raster, second is the polygon extent feature class, the third is the output raster location and name.

Hopefully this gets you going in the right direction.

Best,
Chris B.
0 Kudos