How do I calculate field from a different feature class?

3807
2
Jump to solution
08-30-2013 10:50 AM
RebeccaBrown1
New Contributor
Bear with me, as today is the first time I've learned anything about Python and I'm a Model Builder n00b. Here's what I'm trying to do:

    Select one feature in the Place feature class
    Select all features in Tracts within a distance of negative 500 meters of the selected Place (I know this seems odd, but I have my reasons)
    Use the "Name" field value from the selected Place feature to calculate the values of the "City" field of the selected Tracts features
    Repeat for every feature in the Place feature class
What I can't figure out is how to assign the "Name" value of the selected Place feature to the "City" field of the selected features in Tracts. The Field Calculator tool seems to only allow me to assign values from within the feature class.

Here's what it looks like in Model Builder: (BTW, the "Value" output from "Iterate Feature Selection" just produces the number 25 for some reason. I can't seem to use that output as the input for the Calculate Field function.)

[ATTACH=CONFIG]27121[/ATTACH]

Thank you in advance for your help!
-Rebecca
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
Bear with me, as today is the first time I've learned anything about Python and I'm a Model Builder n00b. Here's what I'm trying to do:

    Select one feature in the Place feature class
    Select all features in Tracts within a distance of negative 500 meters of the selected Place (I know this seems odd, but I have my reasons)
    Use the "Name" field value from the selected Place feature to calculate the values of the "City" field of the selected Tracts features
    Repeat for every feature in the Place feature class

What I can't figure out is how to assign the "Name" value of the selected Place feature to the "City" field of the selected features in Tracts. The Field Calculator tool seems to only allow me to assign values from within the feature class.

Here's what it looks like in Model Builder: (BTW, the "Value" output from "Iterate Feature Selection" just produces the number 25 for some reason. I can't seem to use that output as the input for the Calculate Field function.)

[ATTACH=CONFIG]27121[/ATTACH]

Thank you in advance for your help!
-Rebecca


Don't use an iterator at all.  Do it with the Spatial Join tool.  Make the Places the target feature and the Tracts the Join features and use the One To Many option and a negative 500 foot tolerance.  This will do all of the overlays in one process and preserve the ObjectIDs and attributes of both the target (Places) and each Join Feature (Tract) in the output.  You then can use the Make Feature Layer on the Tracts, and then use the Add Join tool on the Tract's ObjectID to the JoinFID field and use the Field Calculator tool to transfer the Place Name attribute to the Tract City field in a single calculation.  No iterators needed.

If for some reason the Negative 500 foot tolerance does not work directly with the Spatial Join tool, first run the Buffer tool with the negative buffer distance and then use the Spatial Join tool with the Buffer output as the Target Features or Join Features.

If you were going to fix your present model you would have to create a variable such as  %Name% to get the City name of the currently iterated Place feature and use that variable  (%Name%) in the Field Calculator, since you have no common field to perform a Join without using the Spatial Join tool.  You could do this with an iterate field values iterator or you needed to make Name part of the Group By field list of the Feature Selection iterator to have the Value variable populated by the City name.  You probably left that blank, so the iterator is actually using the entire selection of 25 features to do one pass, which you definitely do not want.

View solution in original post

0 Kudos
2 Replies
RichardFairhurst
MVP Honored Contributor
Bear with me, as today is the first time I've learned anything about Python and I'm a Model Builder n00b. Here's what I'm trying to do:

    Select one feature in the Place feature class
    Select all features in Tracts within a distance of negative 500 meters of the selected Place (I know this seems odd, but I have my reasons)
    Use the "Name" field value from the selected Place feature to calculate the values of the "City" field of the selected Tracts features
    Repeat for every feature in the Place feature class

What I can't figure out is how to assign the "Name" value of the selected Place feature to the "City" field of the selected features in Tracts. The Field Calculator tool seems to only allow me to assign values from within the feature class.

Here's what it looks like in Model Builder: (BTW, the "Value" output from "Iterate Feature Selection" just produces the number 25 for some reason. I can't seem to use that output as the input for the Calculate Field function.)

[ATTACH=CONFIG]27121[/ATTACH]

Thank you in advance for your help!
-Rebecca


Don't use an iterator at all.  Do it with the Spatial Join tool.  Make the Places the target feature and the Tracts the Join features and use the One To Many option and a negative 500 foot tolerance.  This will do all of the overlays in one process and preserve the ObjectIDs and attributes of both the target (Places) and each Join Feature (Tract) in the output.  You then can use the Make Feature Layer on the Tracts, and then use the Add Join tool on the Tract's ObjectID to the JoinFID field and use the Field Calculator tool to transfer the Place Name attribute to the Tract City field in a single calculation.  No iterators needed.

If for some reason the Negative 500 foot tolerance does not work directly with the Spatial Join tool, first run the Buffer tool with the negative buffer distance and then use the Spatial Join tool with the Buffer output as the Target Features or Join Features.

If you were going to fix your present model you would have to create a variable such as  %Name% to get the City name of the currently iterated Place feature and use that variable  (%Name%) in the Field Calculator, since you have no common field to perform a Join without using the Spatial Join tool.  You could do this with an iterate field values iterator or you needed to make Name part of the Group By field list of the Feature Selection iterator to have the Value variable populated by the City name.  You probably left that blank, so the iterator is actually using the entire selection of 25 features to do one pass, which you definitely do not want.
0 Kudos
RebeccaBrown1
New Contributor
That is a much, much, much better solution than the mess I was trying to put together. I had forgotten that the Spatial Join (Analysis) tool offers options that Join > Spatial Join does not. (Apparently my brain is on vacation.)

Thank you for your rapid and helpful reply.
0 Kudos