Spatial Join in Model Buider

3797
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
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.


There is no Spatial Join available through right clicking a feature class that I know of, only a standard attribute join.  What are you actually choosing when you right click?  Spatial Join always creates a new feature class.  It never modifies an existing feature class.

Are you making the Model outputs permanent or getting any output?  Model Builder is no different from running the Spatial Join tool in ArcMap directly from the toolbox, except that intermediate data won't be saved and has to be changed to permanent data by right clicking the output and changing that setting.

What are you joining to what?  In the first line it sounds like polygons would join to the center lines and in the next it sounds like the opposite.  The Spatial Join field map list would show what the resulting attributes would be for the Spatial Join.  What does it show?
0 Kudos
DawnBaldridge
New Contributor III
You can join features by right clicking on them in the table of contents and select join. When I perform this join with attributes I get the desired results. Even when I run the spatial join tool from the toolbox I get the desired results. But not from model builder. The output data is permanent and I am joining center lines to road areas.
I think this may fall under NIM076186 but have not gotten confirmation from ESRI.
0 Kudos
MichaelVolz
Esteemed Contributor
Dawn:

You say "When I build a model and use the spatial join from the Analysis toolbox I don't get the attributes."

Can you provide a screenshot of how this is configured as it just might be that your configuration settings are not correct for the results that you want to achieve?
0 Kudos
DawnBaldridge
New Contributor III
I attached a screen shot of the model. I was wondering if my settings were correct. Snow_Removal_Area (2) is a feature layer for data type while the center line file is a table view.

[ATTACH=CONFIG]30937[/ATTACH]
0 Kudos
RichardFairhurst
MVP Honored Contributor
You can join features by right clicking on them in the table of contents and select join. When I perform this join with attributes I get the desired results. Even when I run the spatial join tool from the toolbox I get the desired results. But not from model builder. The output data is permanent and I am joining center lines to road areas.
I think this may fall under NIM076186 but have not gotten confirmation from ESRI.


Well the right click join has nothing to do with a Spatial Join and is only a standard attribute join.  Does the model only consist of the the Spatial Join tool, or does it have several geoprocessing tools that run prior to the Spatial join?  If there are other tools that run, what are they?

Does the model only contain standard toolbox tools and no user developed script tools?  User developed script tools often fail to pass field information to other tools in Model Builder resulting in failure to transfer attribute information.

What output do you get?  Does it contain no fields?  Does it only contain target FC fields?  Is the Spatial Join a One To One join?  Does the field list of the tool in the model show the fields you expect or not?

I have 10.2 and ran the Spatial Join tool from a model with my data and got an output with the expected field list.  I kept all target features and where the search radius tolerance was too small the joined fields contained Null values, but the joined fields were still there.  Are you getting none of the join fields at all or just none of the attributes in the join fields, but the join fields themselves are still there?
0 Kudos
MichaelVolz
Esteemed Contributor
I really need to see how the Spatial Join tool is configured.  Can you get that into a screenshot?

If not, can you export as a python script and paste that into the thread?
0 Kudos
RichardFairhurst
MVP Honored Contributor
I attached a screen shot of the model. I was wondering if my settings were correct. Snow_Removal_Area (2) is a feature layer for data type while the center line file is a table view.

[ATTACH=CONFIG]30937[/ATTACH]


A Table View should not be accepted at all as a Spatial Join input, but because it is a parameter perhaps the validation does not catch that error.  Only a Feature Layer should work as a Spatial Join target or join input.  Desktop would not allow you to make this error, but Model Builder cannot catch it because of the way the parameters are configured.  The input parameter should be restricted to only accept feature layers.  Feature Layers work just as well as a Table View with the Field Calculations you are doing.

Also, because the Join input is a parameter perhaps the tool cannot set up a field list, since it has no idea what fields will be sent to it.  Fields will not be inserted at run time or by standard validation, so you would have to manually add the fields to the Spatial Join field list that are expected from the input parameter within that tool in the model.  Manual field modifications to the field list can be done for such occasions where Model Builder cannot predict the field inputs, but you can.

Desktop has no equivalent input that corresponds to a Model Builder parameter, so you could never cause this situation by running the tool in Desktop, since Desktop always requires explicitly chosen inputs prior to run time.
0 Kudos
DawnBaldridge
New Contributor III
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.

I attached a copy of the script from model builder and copied below too. Right now there are lots of fields. Thanks for your help.


# Import arcpy module
import arcpy

# Script arguments
Snow_Centerlines_ = arcpy.GetParameterAsText(0)
if Snow_Centerlines_ == '#' or not Snow_Centerlines_:
    Snow_Centerlines_ = "Snow_Centerlines" # provide a default value if unspecified

# Local variables:
Snow_Centerlines = Snow_Centerlines_
Snow_Centerlines__2_ = Snow_Centerlines
Snow_Removal_Area_SpatialJoi2 = Snow_Centerlines__2_
Snow_Removal_Area__2_ = "Snow_Removal_Area"

# Process: Calculate Current Time
arcpy.CalculateField_management(Snow_Centerlines_, "Date_Time", "datetime.datetime.now( )", "PYTHON_9.3", "")

# Process: Calculate Status to Green
arcpy.CalculateField_management(Snow_Centerlines, "Status", "\"Green\"", "PYTHON", "")

# Process: Spatial Join
tempEnvironment0 = gp.qualifiedFieldNames
arcpy.env.qualifiedFieldNames = "true"
arcpy.SpatialJoin_analysis(Snow_Removal_Area__2_, Snow_Centerlines__2_, Snow_Removal_Area_SpatialJoi2, "JOIN_ONE_TO_ONE", "KEEP_ALL", "PERIM \"PERIM\" true true false 8 Double 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,PERIM,-1,-1;PERIM_U_D \"PERIM_U_D\" true true false 16 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,PERIM_U_D,-1,-1;FEAT_NAME \"FEAT_NAME\" true true false 30 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,FEAT_NAME,-1,-1;PAVED_D \"PAVED_D\" true true false 16 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,PAVED_D,-1,-1;AREA_SIZE \"AREA_SIZE\" true true false 8 Double 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,AREA_SIZE,-1,-1;AREA_U_D \"AREA_U_D\" true true false 16 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,AREA_U_D,-1,-1;INSTLN_ID \"INSTLN_ID\" true true false 20 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,INSTLN_ID,-1,-1;SUR_USE_D \"SUR_USE_D\" true true false 20 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,SUR_USE_D,-1,-1;PRIORITY \"PRIORITY\" true true false 20 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,PRIORITY,-1,-1;REMARKS \"REMARKS\" true true false 50 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,REMARKS,-1,-1;No_lanes \"No_lanes\" true true false 2 Short 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,No_lanes,-1,-1;Ln_Miles \"Ln_Miles\" true true false 8 Double 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,Ln_Miles,-1,-1;length \"length\" true true false 8 Double 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,length,-1,-1;Road_stat \"Road_stat\" true true false 16 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,Road_stat,-1,-1;Time_Rep \"Time_Rep\" true true false 30 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,Time_Rep,-1,-1;Shape_Length \"Shape_Length\" false true true 8 Double 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,Shape_Length,-1,-1;Shape_Area \"Shape_Area\" false true true 8 Double 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Removal_Area,Shape_Area,-1,-1;NUM_LANES \"NUM_LANES\" true true false 4 Long 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,NUM_LANES,-1,-1;USER_FLAG \"USER_FLAG\" true true false 20 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,USER_FLAG,-1,-1;INSTLN_ID_1 \"INSTLN_ID\" true true false 20 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,INSTLN_ID,-1,-1;LENGTH_U_D \"LENGTH_U_D\" true true false 16 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,LENGTH_U_D,-1,-1;USE_TYP_D \"USE_TYP_D\" true true false 16 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,USE_TYP_D,-1,-1;ROAD_NAME \"ROAD_NAME\" true true false 64 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,ROAD_NAME,-1,-1;ALT_NAME \"ALT_NAME\" true true false 64 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,ALT_NAME,-1,-1;DIRECTION \"DIRECTION\" true true false 50 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,DIRECTION,-1,-1;GG_CREATED \"GG_CREATED\" true true false 8 Date 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,GG_CREATED,-1,-1;GG_REVD \"GG_REVD\" true true false 8 Date 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,GG_REVD,-1,-1;Distance \"Distance\" true true false 8 Double 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,Distance,-1,-1;Distance_Units \"Distance_Units\" true true false 10 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,Distance_Units,-1,-1;Hierarcy \"Hierarcy\" true true false 20 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,Hierarcy,-1,-1;OneWay \"OneWay\" true true false 20 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,OneWay,-1,-1;Speed_MPH \"Speed_MPH\" true true false 4 Long 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,Speed_MPH,-1,-1;Minutes \"Minutes\" true true false 8 Double 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,Minutes,-1,-1;SHAPE_Length_1 \"SHAPE_Length\" false true true 8 Double 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,SHAPE_Length,-1,-1;Status \"Status\" true true false 10 Text 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,Status,-1,-1;Date_Time \"Date_Time\" true true false 8 Date 0 0 ,First,#,K:\\Baldridge\\Snow_Plow_Test\\Snow_test.gdb\\Snow_Centerlines,Date_Time,-1,-1", "INTERSECT", "", "")
arcpy.env.qualifiedFieldNames = tempEnvironment0
0 Kudos
MichaelVolz
Esteemed Contributor
I can see that you get Snow_Centerlines_ from user input

Snow_Centerlines_ = arcpy.GetParameterAsText(0)

but I do not see where the source of Snow_Removal_Area__2_ is defined as it seems to just be given a name

Snow_Removal_Area__2_ = "Snow_Removal_Area"

Maybe this is where rfairhur24 is saying that the Model is getting tripped up.

I think you might need to add the Snow_Removal_Area as a feature layer using MakeFeatureLayer_management before using this layer in the spatial join.
0 Kudos