AnsweredAssumed Answered

SearchCursor\UpdateCursor with spatial join

Question asked by CCweedcontrol on Oct 18, 2017
Latest reply on Nov 2, 2017 by CCweedcontrol

I am trying to update points, so say i select 30 points in arcmap and i want to update just those 30 points attributes from the parcels polygons BUT only for those 30 and they it must have "Match" in the Verifi3 field if the feature has "No" or is "Null" i want it to be ignored or just pass.

 

I have the following code it works but it updates all the selected points whether it has "Match" or "No" or "Null".

I appreciate the help.

 

import arcpy, os 
from datetime import datetime as d
startTime = d.now()
import traceback

arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'C:\Temp\Default.gdb'

ptSelection = "PointsTest" 
pointLayer = arcpy.env.workspace + os.sep + "PointsTest"
parcel = 'TaxParcels' #Taxparcels
sjpoints = "In_memory\sjpoints"
poly = "ACCOUNT_1"
Pnt =  "Account"


with arcpy.da.SearchCursor(ptSelection , "Verifi2") as cursor: 
    for row in cursor:
        if row[0] == "Match":
            #Run the Spatial Join tool, using the defaults for the join operation and join type
            arcpy.SpatialJoin_analysis(ptSelection, parcel, sjpoints)

            # define the field list from the spatial join
            sourceFieldsList = ['ACCOUNT_1', poly,'SiteAddress','SiteNum_1', 'SiteStreet_1','SiteNumSfx_1','Predir_1', 'Postdir_1', 'SiteCity_1', 'SiteZIP_1', 'OwnerName_1','StreetType_1', 'SubName_1']    #,'StreetType_1'

            # define the field list to the original points
            updateFieldsList = ['Account', Pnt,'SiteAddres', 'SiteNum', 'StreetName', 'SiteNumSfx','Predir', 'Postdir', 'SiteCity', 'SiteZip', 'OwnerName','StreetType', 'SubName'] #, 'StreetType'

            # populate the dictionary from the polygon
            valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints, sourceFieldsList)}   

            with arcpy.da.UpdateCursor(ptSelection, updateFieldsList) as updateRows:   
                for updateRow in updateRows:   
                    keyValue = updateRow[0]
                    if keyValue in valueDict:
                        for n in range (1,len(sourceFieldsList)):     
                            updateRow[n] = valueDict[keyValue][n-1]
                        updateRows.updateRow(updateRow)
                del updateRows
                del updateRow
       
        else:
            row[0] == 'No'
            pass

if arcpy.Exists("In_memory\sjpoints"):
    arcpy.Delete_management("In_memory\sjpoints")

Outcomes