multiple file, task process in python

2572
6
Jump to solution
11-06-2015 06:23 AM
Madan_KrishnaSuwal
New Contributor

Hi,

I am going to perform repeated task for large data set

here are few tasks I am looking for help

1. I need to convert set of raster from integer to float, then

2. divide all the raster by value 10, then

3. select cells above X and less than Y, then

4. subtract value M from each cell in each raster, then

5. subtract each cell of each raster to Value N, then

6. sum up all the raster, then

7. divide by value Z

I did this using tools in ArcGIS but it seems that I could not document all the steps and there are chances of missing steps when I perform in large data set in repetitive manner.

hence, I am looking for python script.

I am novice in python.

your kind help is highly appreciated.

0 Kudos
1 Solution

Accepted Solutions
LukeSturtevant
Occasional Contributor III

Are you set on using python? You could also just use model builder to string together the tools which maybe an easier way to start. The you could export the model builder tool to python script and work from there.

View solution in original post

6 Replies
RebeccaStrauch__GISP
MVP Emeritus

If you've already stepped thru the entire process manually, one way to get started is to open the Results tab (under Geoprocessin menu), then right click on each of the commands shown and "copy as python snippet". Paste these into a file with a .py extension.  You then need to work to get your parameters/variables set to work with each, and eventually, you can then, in a toolbox (you can create a new one) add the python script (it walks thru a wizard) .

that is a basic overview of how it would work.  I'm away from my machines right now, so can't help with code, but if you get started and the Posting Code blocks in the new GeoNetcode here, others will have a place to start helping you (although, your steps above do seem well laid out).

also, search geonet for some of the threads on learning python/arcpy   ....lots of resources out there.

LukeSturtevant
Occasional Contributor III

Are you set on using python? You could also just use model builder to string together the tools which maybe an easier way to start. The you could export the model builder tool to python script and work from there.

BlakeTerhune
MVP Regular Contributor

Both suggestions from Rebecca and Luke are reasonable. I'm partial to Python because it is more customizable, but it also requires more coding knowledge. If you're not as comfortable coding Python, it might be easier for you to set everything up in Model Builder.

If you want to dive head-first into a purely Python solution, you can start by looking up the arcpy documentation for each tool you plan to use. For example, the Float tool to convert each cell value of a raster into a floating-point representation. At the bottom of the page, they even give you examples of how to use the code.

0 Kudos
Madan_KrishnaSuwal
New Contributor

Thanks everyone,

I decided to go with Model Builder as suggested by Rebecca.

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

I think it was Luke that first recommended model builder. It is a good way to start...but I like the cut and paste from the results.  Just wanted to give Luke the credit for the suggestion if that is the way you are proceeding.

in any case, please mark any comments that were helpful, and one of the comments as correct so they thread can be closed.  Thanks.

0 Kudos
LukeSturtevant
Occasional Contributor III

Madan, If you have decided to go with Model Builder then you should use the Iterate Rasters​ function to have the tool step through the rasters in your workspace. Then string all the processing tools together as you have mentioned in your steps above. Then you could use the Collect Values​ function to collect all the output rasters from step 5 (subtract each cell of each raster to Value N). You can then use Cell Statistics​ with the 'SUM' stats type to sum up all the rasters. Let us know how you are doing!

0 Kudos