AnsweredAssumed Answered

Batch processing within Python to add, calculate, drop multiple fields

Question asked by amontgomery3030 on Jul 24, 2013
Latest reply on Jul 26, 2013 by amontgomery3030
I have been searching the forums and elsewhere online, but have yet to find anything to aid me. 

I am using the Geospatial Modelling Environment toolset, and the tool isectpolyrst, which gives you the raster cell count by type within specified polygons, but not the area, so I am hoping to add new area fields (one per count field), calculate the area field, and delete the old count field. So currently, I have one script that runs GME and appends the count data to the polygons, and then the model (see [ATTACH=CONFIG]26184[/ATTACH]) that adds, calculates and deletes fields. It's the model that I am looking to automate/script.

I know I can run the model part via batch processing and manually entering all the inputs/outputs within ModelBuilder, but ideally, I want a script that can hunt down each count field name, generate a new area field name based on user inputs, calculate this new area field, and then drop the old count field.

Before anyone asks, I am not using Tabulate Area because it keeps crashing when I run it over large shapefiles, so I went with GME.

I know one area of concern is how the original count fields are picked out correctly. I tried listing the fields, but I don't think using the list index will work for this, as the count fields could be anywhere in the attribute table, and there could be different numbers of count fields, which might make the index go out of range or something and error. However, I am not sure if its possible to call fields by a boolean search that only calls up fields whose names match the search input (e.g. is it possible to call up fields named NLCD1, NLCD2, etc by searching with something like "NLCD*"?).

Once I can get script to find the appropriate fields, I know I can just loop through the add field and calculate field, and then drop the fields once that has all run and I will be all set.

If anyone has thoughts (or needs clarification) please let me know! I wish I had real code to show you, but give I am stuck on the first step of finding the fields, I don't have much to show. Thanks in advance!