2

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:

  1. use Search Cursor to Select by Location where Manholes intersect Storm Sewer start points

  2. use getValue to store the FACILITYID of the Manhole that intersects the Storm Sewer Start Point in a list

  3. 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')

1 Answer 1

2

Updated: I would suggest trying to use the Spatial Join tool, as it may be better suited to what you are trying to do and then using a similar script to what you have above to store the output in a dictionary, instead of a list. By storing it in a dictionary instead of a list you will be able to store more information, and reference the FIDs as "keys" rather than by iterating through the list. you might try using a unique ID for the Storm Drain as the key.

Either way the below method, should get you closer to what you are trying to do.

for example:

    ss_dict= {}
    #Add Spatial Join here <<<  Output SS_START2_SJ (Spatial Join)
     
    with arcpy.da.SearchCursor("SS_Start2_SJ",["UID","FACILITYID"]) as cursor:
        for row in cursor: 
                ss_dict[row[0]] = row[1] #removed list wrapper
    with arcpy.da.UpdateCursor(StormSewer2,['UID',Field2]) as cursor:
            for row in cursor:
                Field2_value = ss_dict.get(row[0],None) #returns ss_dict[UID]
                if Field2_value is not None:
                    row[1]=Field2_value 
                    print('updated UID {}'.format(row[0]))
                    cursor.updateRow(row)
                else: 
                    continue
2
  • I am getting the following error on the cursor.updateRow(row) line:TypeError: value #1 - unsupported type: list
    – RJ Fulton
    Oct 5, 2020 at 14:53
  • See above, I updated ss_dict[row[0]] = [row[1] ] to ss_dict[row[0]] = row[1] #removed list wrapper, Field2_value was giving you a list, instead of a value.
    – bwp8nt
    Oct 5, 2020 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.