AnsweredAssumed Answered

Select points and update attributes base on parcels

Question asked by CCweedcontrol on Jul 8, 2015
Latest reply on Jul 9, 2015 by rfairhur24

I am working a code/button that will help me update address points attributes based on the parcel they are in.

I am trying to to use filed list to create a mach and update the points with dictionaries. I don't not get error but my address points don't get updated from the parcels. I would appreciate any help with my code.



import arcpy       
from datetime import datetime as d       
startTime =       

#set to folder where features are located       
arcpy.env.workspace = r"Database Servers\DSD15_SQLEXPRESS.gds\TEST (VERSION:dbo.DEFAULT)" #r"Database Servers\DSD15_SQLEXPRESS.gds\TonyTwoWay (VERSION:dbo.DEFAULT)" #on windows use \ instead of /       
arcpy.env.overwriteOutput = True
arcpy.env.qualifiedFieldNames = False

#define variables for cursor       
FC = "TEST.DBO.CCAPTEST"  #pointlayer     
TaxPar = "TaxParcels" #Parcels
poly = "ACCOUNT"#'SiteAddres_1','SiteAddres_1', 'SiteNum_1', 'SiteNumSfx_1','Predir_1','SiteStreet_1', 'StreetType_1', 'Postdir_1', 'SiteCity_1', 'SiteZIP_1', 'OwnerName_1' 
Pnt =  "Account"#
TaxPar1 = "selectedParcels"

parcelsCount = int(arcpy.GetCount_management(FC).getOutput(0))     
dsc = arcpy.Describe(FC) 
selection_set = dsc.FIDSet         
if len(selection_set) == 0:       
    print "There are no features selected"  
elif parcelsCount >= 1:
    #Select parcel within selected Address Points
    arcpy.SelectLayerByLocation_management(TaxPar, "CONTAINS", FC)

    #Create in memory parcel layer  
    selectedParcels = arcpy.MakeFeatureLayer_management(TaxPar, TaxPar1)

    arcpy.SelectLayerByAttribute_management(TaxPar1, "NEW_SELECTION", "OBJECTID= "+OID)
    # define the field list from the parcels
    sourceFieldsList = ["ACCOUNT", poly,"SiteAddres",'SiteNum', 'SiteStreet','SiteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZIP', 'OwnerName']    

    # define the field list to the points
    updateFieldsList = ["Account", Pnt,"SiteAddres", 'SiteNum', 'SiteStreet', 'SiteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip', 'OwnerName']
    # Start an edit session. Must provide the workspace.    
    edit = arcpy.da.Editor(arcpy.env.workspace)    
    # Edit session is started without an undo/redo stack for versioned data    
    #  (for second argument, use False for unversioned data)    
    # Start an edit operation    

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

    with arcpy.da.UpdateCursor(FC, 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]
    # Stop the edit operation.    
    # Stop the edit session and save the changes