Spatial Join in Model Buider

4983
14
01-29-2014 04:21 AM
DawnBaldridge
New Contributor III
I am trying to spatially join road areas with road center lines after the center line snow removal status has been updated. A spatial join between these two would capture the status of the center line and place it in the road area. I get the results I need when I right-click on the feature class and do a spatial join with attributes. When I build a model and use the spatial join from the Analysis toolbox I don't get the attributes. Is there a work a round for this in model builder?

I am using ArcInfo 10.0 with no service packs.
Just in case....I cannot do a regular join because we have a lot of roads that currently do not have names. 
Any input is appreciated.
0 Kudos
14 Replies
RichardFairhurst
MVP Honored Contributor
You can do a spatial join by right clicking. You have to select it from the drop down. There are several processes that run prior to the spatial join.[/UNQUOTE]


I have never heard of such a thing for Spatial Join and certainly cannot do it from Desktop or ArcCatalog with the out of the box context menu of any layer or feature class.  The "Joins and Relates" items in the drop down of the right click menu in Desktop is just a standard Attribute Join, which can accept a Table View.  But those Joins are a completely different thing from a Spatial Join, so don't confuse them together.  The Spatial Join tool always requires all of its inputs to be spatial feature classes or layers, and should not accept a non-spatial table view for any of its input.

You don't have to run the Make Feature Layer tool, but the input has to be a Feature Class or Feature Layer.  Also you would have to extract the path from the input parameter and replace all of the joined field hard coded paths and feature class names in the Spatial Join tool with that path and feature class name variable value, unless the input always came from that hard path and feature class name.  Any other input parameter value that did not use that exact path and feature class name for the join input should cause the tool to either fail or drop the fields.

So every part of the Spatial Join tool field list text would have to be modified to replace K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines with a path/feature class name variable extracted from the input.  Technically you should also include code to validate that the fields names exist in any given input.  Not sure how you would use the parameters in Model Builder to replace these hard coded values, but in the Python script it can be done.
0 Kudos
MichaelVolz
Esteemed Contributor
rfairhur24

Under Join Data you have a drop-down list in ArcGIS Desktop that allows you to choose "Join data from another layer based on spatial location" which I believe is a Spatial Join.
0 Kudos
RichardFairhurst
MVP Honored Contributor
rfairhur24

Under Join Data you have a drop-down list in ArcGIS Desktop that allows you to choose "Join data from another layer based on spatial location" which I believe is a Spatial Join.


You have taught me something new.  I vaguely recall looking at it long ago, but I never tried it before and forgot it even existed (probably because I wanted options that it does not include that the Toolbox version does include).  But you are right, that is a dumbed-down version of the Spatial Join.  The Context menu Join and Statistics versions are independently coded tools, so they can have different behaviors or bugs from the Toolbox version.  I probably will continue to use the Toolbox version, since it gives more options, especially for the summary values of the field list, and the context menu seems limited to the One To One option settings, while I use the One To Many option more often than not.

Anyway, the key difference between your model and desktop is that you are using a parameter rather than a hard coded input.  That is something you cannot do through desktop and it presents complexities that require advanced Model Builder knowledge to troubleshoot.
0 Kudos
DawnBaldridge
New Contributor III
I will work through the model and see if this is doable or if it is a bug. Thank you.

mvolz47...I'm glad you taught rfairhur24 something new cause he sure wasn't listening to me.
MichaelVolz
Esteemed Contributor
I would focus on the configuration of the Spatial Join tool in Model Builder as the export to python shows that the Snow Removal Area feature layer has not been defined in the model.

I would also suggest using python (not that big of a learning curve), so you could have more control of the geoprocess that you are building.
0 Kudos