Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

A simple (I think) Model Builder question. I have 25 field sites, for each of which I have mapped land use as separate layers for different years. In one folder I have veg layers for 1994, named tara{site number}veg94 (eg., tara01veg94.shp, tara02veg94.shp, through to tara25veg94.shp). In the other folder I have the same for 2007, similarly named by site number (tara01veg07.shp, tara02veg07.shp ... tara25veg07.shp).

I am wanting to union the layers for each site for successive years together using a model, for example tara01veg94.shp unioned with tara01veg07.shp to create tara01veg9407 and so on. I presume that I need to use an iterator to specify the site number for each run of the union function and then insert the %value% created by the iterator into the input and output file names. The problem I'm having is that I need to iterate the same site number for two input files simultaneously, so I figured the "for" iterator was the one to use, but the union function doesn't let me put %Value% into the input fields (though it accepts it in the output field ok). Any help would be greatly appreciated... thanks.

share|improve this question
add comment

3 Answers 3

Thanks for recommending Python. Having never used it before, I've had to take a crash course in Python programming. I stumbled when it came to iterating through a dictionary as you suggested, so I tried another approach -- which seems to work. I'll paste it here for anyone else if it is of use.

import arcpy
arcpy.env.workspace = "c:/Temp/TRC_processing/processing_auto"
for i in range(1,25):
    veg2012 = "c:/Temp/TRC_processing/2012_layers/tara" + str(i) + "v12_Dissolve.shp"
    veg1994 = "c:/Temp/TRC_processing/1994_layers/tara" + str(i) + "v94_Dissolve.shp"
    vegchange9412 = "tara" + str(i) + "v9412_change.shp" 
    arcpy.Union_analysis([veg2012, veg1994], vegchange9412, "ALL", "", "NO_GAPS")
share|improve this answer
    
An easy way to iterate over the key/value pairs is to use tuple unpacking and dict.items() or dict.iteritems(), e.g. for k, v in {"a":1, "b":2}.iteritems(): print k, v –  blah238 Mar 14 '13 at 1:55
    
You might also be interested in this question: What are some resources for learning Python and arcpy? –  blah238 Mar 14 '13 at 2:54
    
Thanks blah238. Greatly appreciated. –  harley Mar 17 '13 at 22:05
add comment

I would use Python instead of ModelBuilder for something like this.

The gist of it would be to do something like this:

  1. Read the contents of the first folder into a list using ListFeatureClasses
  2. Do the same for the second folder
  3. zip() the two lists into a dictionary: Example
  4. Iterate over the dictionary's key/value pairs (Example) and perform the Union for each pair
share|improve this answer
    
+1 for recommending zip() –  Aaron Mar 13 '13 at 13:19
add comment

Unless you must use different projections among your sites or you have polygons that must overlap, or have another valid reason not to combine all your sites, Merge all the data for each year so you can then efficiently perform one union between each pair of years.

Prior to merging ensure that each site-veg layer has a field that identifies the site ID. The ACCRU Tools 1.2.1 Merge With Filename has an automated way to add/calculate this in, if not already present in the tables of the files to be merged.

  1. merge all files in folder 1994 (tara01veg94.shp, tara02veg94.shp, ... tara25veg94.shp) = veg94.shp
  2. merge all files in folder 2007 (tara01veg07.shp, tara02veg07.shp, ... tara25veg07.shp) = veg07.shp
  3. and then union veg94.shp and veg07.shp to get a layer that you can calculate an updated area field and perform Summary Statistics using the site ID field as one of the case fields.

You will likely want all combinations in one final table for further statistical analysis, so doing the merges up front means you don't have to iterate all geoprocessing, including adding/calculating fields, etc.

If your sites overlap, then you will need to union your veg layers and probably do some clean up in the attribute table and also maintain a separate layer for your site polygons (these will need that unique site ID field) to be used to intersect with the unioned pair of years. I can provide more explanation of all this if needed (if no overlap among sites, then ignore this last paragraph).

share|improve this answer
    
Thank you ccn. I also had this approach suggested to me by a colleague here. There's no overlap between the sites so this approach would be useful (and more efficient) too. Have added your comments to my notes. –  harley Mar 17 '13 at 22:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.