Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

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

$
0
0
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 Attachment 26184) 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!
Attached Thumbnails
Click image for larger version

Name:	rastermodel.JPG‎
Views:	N/A
Size:	59.7 KB
ID:	26184  

Viewing all articles
Browse latest Browse all 2485

Trending Articles