Generalizing Fieldmaps in ModelBuilder

03-04-2014 11:40 AM
New Contributor
I'm learning ModelBuilder and appreciating how it simplifies life, but I've spent most of today swearing at it because I'm having all kinds of issues trying to deal with FieldMaps.

I have a continuous layer of polygons (no gaps) that I'm trying to attribute. Some I can just calculate (based on input data), but in some places, the input data is unavailable, so I want to copy the value from neighbouring polygons of the same type. To do this, I buffer the polygons, intersect the buffers with the source layer, filter out overlaps that are not the right type, summarize the buffer intersections by polygon ID to give MAX area for each source (to find the neighbour with the longest shared side - had issues with the new Polygon Neighbours tool not identifying neighbours) and then selecting out buffers where the area = MAX_Area. In the end, I get a map table with src_ID, nor_ID, src_attrA, nbr_attrA, src_attrB, nor_attrB which i can join to the original dataset based on src_ID and calculate src_attrB = nbr_attrB.

To try and simplify things and keep track of which attributes are from Source vs. Neighbour, I've want to rename fields at various points, which I've been able to do using Feature Class to Feature Class and setting up a field map. It worked OK while I was building it and had it linked to a specific source file, but now I want to make the input dataset a parameter (so I can run it on several different files) and it seems like the field maps have to be specified by absolute reference (i.e. C:\Test\db.gdb\Input_FC, field_1) and when I parameterize the input FC (and select C:\Test\db.gdb\FC_1 for example) it says it can't find the expected field - even though the schema is identical.

Is there any way to generalize field mappings in model builder, or do I have to resort to python (which I don't know and don't have time to learn at the moment). I can export the model as a python script so - if it's a small code block I could just dump that in and connect it with the rest of the generated code.

I've searched all over the net and haven't found anything like this - lots of help about model builder (lacking details about generalizing field maps) and lots of info about details of dealing with field maps in python, but nothing in between.

Any thoughts?
Tags (2)
0 Kudos
1 Reply
MVP Esteemed Contributor

The only way I know to make field mappings dynamic in ModelBuilder is to write Python functions and drop them into the Calculate Value tool with a Field Mappings output which you can then connect to tools like TableToTable and Merge.

This is unfortunate because the FieldMappings and FieldMap methods are more than a little arcane, though once you get the hang of it they are not as bad as they appear at first blush.

0 Kudos