Spatial Join Intersect

2632
4
12-09-2013 02:55 AM
JackieWoodruff
New Contributor
Ultimately I want to attribute a lake with the fields from a stream that runs through the lake. There are several streams that end within the lake polygon so any of the spatial intersection tools will capture both the streams running through and ending in the lake.

How might I choose the stream that runs through the lake and use this for the Spatial Join? Python? Is there a spatial select tool i'm not aware of which will refine the intersect option?
0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Jackie,

Assuming the river that runs through the lake will be the longest in length, you can set a Merge Rule for the Shape_Length of the rivers feature class to Maximum.  This will only join the lake with the largest length.

[ATTACH=CONFIG]29683[/ATTACH]
0 Kudos
JackieWoodruff
New Contributor
Thank you very much for your reply, Jake.

I found that using the Merge Rule chose the maximum value for the Shape_Length field except the values for the other fields are not from the same record. All of the other joined fields have values from the record with the smallest OBJECTID. I assume this is because it is the first result returned and this is the default method used for matching?

Do you have any other suggestions? My only other idea is to use the Merge Rule to find the longest length and then join the streams based on the shape_length.

Thanks!
Jackie
0 Kudos
JakeSkinner
Esri Esteemed Contributor
You could accomplish this with a python script.  Here is an example:

import arcpy
from arcpy import env
env.overwriteOutput =1
env.workspace = r"C:\temp\python\test.gdb"

#create a one-to-many spatial join
arcpy.SpatialJoin_analysis("lakes", "rivers", "lakes_join", "JOIN_ONE_TO_MANY", "KEEP_ALL", "", "INTERSECT")

#create empty dictionary to store target_fid and shape length
dict = {}

#sort by river's shape length, iterate through each row, and populate dictionary with largest river length
rows = arcpy.SearchCursor("lakes_join", "", "", "", "SHAPE_LENGTH_1 A")
for row in rows:
    length = '%.14f' % row.SHAPE_LENGTH_1
    dict[row.TARGET_FID] = length

del row, rows

#delete all values that are not the larget river
for key in dict:
    print key, dict[key]
    arcpy.MakeFeatureLayer_management("lakes_join", "lakes_join_lyr", "TARGET_FID = " + str(key) + " AND NOT SHAPE_Length_1 = " + str(dict[key]))
    arcpy.DeleteFeatures_management("lakes_join_lyr")

print "finished"
0 Kudos
HeathBrackett1
Occasional Contributor II
You could also create a process that intersects the rivers with the outline of the lake (convert the polygon to line). The river that runs through the lake will intersect the lake line twice, which you can identify by dissolving the points based on river name (and summarizing the OID by COUNT).  That will ensure that you are identifying the river that runs through the lake.

Heath
0 Kudos