I have a point layer of Manholes and a point layer of start points for StormSewer pipes. I need to determine where Manholes intersect a start point of a StormSewer pipe (I used the Vertices to Points tool), grab the FACILITYID of the Manhole and then update a field (UPSTREAMFID) in my StormSewer pipe layer (different from the StormSewer start point layer)
I believe my workflow should look something like this:
use Search Cursor to Select by Location where Manholes intersect Storm Sewer start points
use getValue to store the FACILITYID of the Manhole that intersects the Storm Sewer Start Point in a list
use UpdateCursor to update the StormSewer UPSTREAMFID field with the Manhole facility ID
a) an if statement needs to be used to ensure that the correct StormSewer line is updated with the Manhole facility ID (the StormSewer start point layer has a FACILITYID field that matches the StormSewer line it originated from)
b) something like if StormSewer Start Point facility ID = StormSewer facility ID update UPSTREAMFID with Manhole facility ID
Here is the code I have so far (I am struggling at this point):
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True
env.workspace = r"\\cold\redirect\Profiles\fultor\desktop\GIS\Projects\Stormwater Python\Shapefiles"
Manhole = r"\\cold\redirect\Profiles\fultor\desktop\GIS\Projects\Stormwater Python\Shapefiles\Manhole.shp"
StormSewer = r"\\cold\redirect\Profiles\fultor\desktop\GIS\Projects\Stormwater Python\Shapefiles\StormSewer.shp"
SS_Start = r"\\cold\redirect\Profiles\fultor\desktop\GIS\Projects\Stormwater Python\Shapefiles\SS_StartPoints.shp"
Manhole2 = arcpy.MakeFeatureLayer_management(Manhole, "Manhole_lyr")
SS_Start2 = arcpy.MakeFeatureLayer_management(SS_Start, "SS_Start_lyr")
StormSewer2 = arcpy.MakeFeatureLayer_management(StormSewer, "StormSewer_lyr")
field1 = 'FACILITYID'
field2 = 'UPSTREAMFA'
# Create Feature Layers
print ("Layers created!")
#Get all the unique strings from the first layer
FIDlist = []
with arcpy.da.SearchCursor(SS_Start2, 'FACILITYID') as cursor:
for row in cursor:
FIDlist.append(row[0])
print (FIDlist)
#Select each feature in sequence and get intersecting feature, then update
for FID in FIDlist:
arcpy.SelectLayerByAttribute_management(SS_Start2, 'NEW_SELECTION', "FACILITYID = '{}'".format(FID))
arcpy.SelectLayerByLocation_management(Manhole2, 'INTERSECTS', SS_Start2)
with arcpy.da.UpdateCursor(StormSewer2, field2) as cursor:
for row in cursor:
row[0] = FID
cursor.updateRow(row)
#Clear the selections before the next iteration
arcpy.SelectLayerByAttribute_management(SS_Start2, 'CLEAR_SELECTION')
arcpy.SelectLayerByAttribute_management(Manhole2, 'CLEAR_SELECTION')