This content has been marked as final. Show 9 replies
As an if-then condition has to be met, I'm afraid you cannot do it through tool dialog.
Most probably you'll need to write a python script manipulating the fieldmap object based on the if condition. Which version of ArcGIS you are using?
For 9.3 and 9.3.1 the help link is:
Fieldmap object: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/FieldMap/000v00000081000000/
Fieldmappings object: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/FieldMappings/000v0000008q000000/
Oh dear! I am using v10, but I havent done anything like that yet, so I better start reading....
Thanks for your advice :)
Here is a non-scriptin way. You can create a Model in ModelBuilder by chaining the processes.
To learn about how to use the Field Mapping control review this topic:
Target features: sections (polygons)
Join features: roads (lines)
Add a field (type double) named Length to the roads feature class to store the shape length values.
Right-click on the newly added field and select Field Calculator ... select Shape_Length from the Fields group. Hit Ok.
Run spatial join - in the tool dialog set parameter values as follows:
Chose match option of your interest (say, CONTAINS)
Output feature class: spj_1
In the fieldmap, delete all shape-related fields (Shape_area, shape_length etc). Add a new output field of type Double and name it ShpLength. Set a merge rule of Maximum. Right-click on ShpLength and select Add Input Field. Select roads.Length field from the available fields.
Run the tool
Re-run spatial join by double-clicking on the result node (Results window). Give a different name to the output and change only these parameter values:
Change the ShpLenght fieldmap's merge rule to First.
Output feature class: spj_2 (must be different from the first output)
Run the tool.
Run Join Field tool as follows:
Input table: spj_1
Input Join Field: ShpLength
Join Table: spj_2
Output Join Field: ShpLength
Join Fields: JOIN_FID
Run Join Field again. This time use parameter values as follows:
Input Table: spj_1
Input Join Field: JOIN_FID
Join Table: roads
Output Join Field: OBJECTID (or whatever the name of the OID field)
Join Fields: Condition and Classification
Wow! That worked well for me, THANK YOU SO MUCH!!!
Really appreciate your help :)
As you were so knowledgeable on my previous question, I was just wondering if you happen to know anything about changing the field mapping rules slightly? I noticed that the mode rule will choose the highest numeric value when there is a tie, however is there anyway for me to change it, or use a combination of rules to say "choose the mode (most frequent occuring value) and if there is a tie then choose the lowest numeric value" ...
Please let me know if you have any insight?!
I noticed that the mode rule will choose the highest numeric value when there is a tie
I think it is the opposite. I've just tested. I have 3 mode values (2, 3, 7) with equal frienquencies (14). When I set Mode as merge rule - the output gets 2 (the lowest value). Which version of ArcGIS you are using?
.. use a combination of rules to say "choose the mode (most frequent occuring value) and if there is a tie then choose the lowest numeric value" ...
I guess we are out of luck this time (unless someone comes up with a good answer). We need to use Python to get things done. I'll get back if I can find a good solution.
Oh, I think your right, this is what the help page says:
"�?�Mode�??Use the value with the highest frequency (most common). If there is more than one value with the highest frequency (i.e., a tie), then the list of Mode values will be sorted (smallest first for numeric, alphabetical for text), and the first one will be used."
So in that case, I was mixed up, I actually need a rule that looks at all the values and first chooses the value that repeats itself the most, and if that is not possible then it chooses the highest value. So for your example, it would choose 7 (from 2,3,7)
Hhmmm, let me know if you think of a work around?!
Thanks again for alll your help :)
I have a workaround in Python but we need to test it to make sure it works. Email me email@example.com and I'll send you instructions so that you can try with your data. If the solution is workable we'll then upload the script/instructions to this thread.
Thank you so much! The python script did the trick!
I have attached the zip file for others to use :)
For users: make sure you first run a spatial join with the one-to-one option, and construct one field map with the mode merge rule, and then re-run the spatial join, but only change the option for the one-to-many and its output name. Afterwards, connect to the script tool, and use the first spatial join in the fist parameter and the second spatial join in the second parameter and then in the third parameter use the field you used with the mode merge rule. And it will update the first spatial join feature class.
FieldmapMode.zip 2.4 K