Adding the values of all the shapefiles in a folder.

2010
3
07-08-2013 09:44 AM
ScottBarron
New Contributor III
Hi,
I have a folder with a number of shapefiles with binary values that I want to add all together (to see which pixels are constantly valued at 1, which are constantly valued at 0, etc.) This is easy to do in raster calculator, as you just select one of the shapefiles then add it to the next one and continue, but I would like to use python to do this automatically no matter how many shapefiles are in the folder. I was thinking of making a for loop to select the shapefiles, then add them to an empty list, and then trying to sum the list but I'm not sure what to use. Advice?

Thanks,
Scott
Tags (2)
0 Kudos
3 Replies
JamesCrandall
MVP Frequent Contributor
Are they shapefiles or raster images? I thought the raster calculators' addition funciton is for adding cell values in a raster image? (I guess I am not understanding why you'd run a shapefile through a raster calculator operation -- I really don't know if that is possible or not).
0 Kudos
ScottBarron
New Contributor III
You're right, my mistake. But my question is still similar, if I have a folder full of rasters, can I add them together in python? Or is there another way to do it with shapefiles?
0 Kudos
JamesCrandall
MVP Frequent Contributor
You're right, my mistake. But my question is still similar, if I have a folder full of rasters, can I add them together in python? Or is there another way to do it with shapefiles?


Here's an example of how to run two rasters through the Addition function of the raster calculator:

http://resources.arcgis.com/en/help/main/10.1/index.html#//005m000000mv000000

What I am unsure of is how you will identify the individual pairs of rasters within the folder.  Also, while it may not be necessary, I'd recommend managing the rasters with a File Geodatabase rather than simply keeping them in a folder.  In some instances issues tend to popup if they simply reside in a folder, it may also aid in your arcpy processing too.

j
0 Kudos