import arcpy, os from arcpy import env arcpy.env.overwriteOutput = True mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] lyr = arcpy.mapping.ListLayers(mxd, "Points")[0] arcpy.env.workspace = os.path.dirname(mxd.filePath) wp = os.path.dirname(mxd.filePath) #env.workspace = r"C:\GIS\Addressing\test" Points = "Points" Points_2 = "Points_2" Fileds = "APA_CODE" selection = 1 while selection < 3: rows = arcpy.SearchCursor(Points) #opens search cursor on the info table for row in rows: facltyType = row.FacltyType # extracts the name of the destination field # Process: Select Layer By Location print "select by location" arcpy.SelectLayerByLocation_management(Points, "INTERSECT", Points_2, "", "NEW_SELECTION") if int(arcpy.GetCount_management(Points).getOutput(0)) > 0: arcpy.MakeFeatureLayer_management(Points, "PointsLyr") arcpy.MakeFeatureLayer_management(Points_2, "PointsLyr_2") arcpy.JoinField_management("PointsLyr", "Account", "PointsLyr_2", "Account", "") # Update the FacltyType field with the CPUC values rows = arcpy.UpdateCursor(Points) for row in rows: row.FacltyType = row.CPUC rows.updateRow(row) del rows del row selection +=1 arcpy.RemoveJoin_management("PointsLyr2")
import arcpy, os from arcpy import env arcpy.env.overwriteOutput = True mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] lyr = arcpy.mapping.ListLayers(mxd, "Points")[0] arcpy.env.workspace = os.path.dirname(mxd.filePath) wp = os.path.dirname(mxd.filePath) #env.workspace = r"C:\GIS\Addressing\test" Points = "Points" Points_2 = "Points_2" Fileds = "APA_CODE" selection = 1 while selection < 3: rows = arcpy.SearchCursor(Points) #opens search cursor on the info table for row in rows: facltyType = row.FacltyType # extracts the name of the destination field # Process: Select Layer By Location print "select by location" arcpy.SelectLayerByLocation_management(Points, "INTERSECT", Points_2, "", "NEW_SELECTION") if int(arcpy.GetCount_management(Points).getOutput(0)) > 0: arcpy.MakeFeatureLayer_management(Points, "in_memory\PointsLyrA") arcpy.MakeFeatureLayer_management(Points_2, "in_memory\Points2") arcpy.JoinField_management("PointsLyrA", "Account", "Points2", "Account", "") # Update the FacltyType field with the CPUC values rows = arcpy.UpdateCursor(Points) for row in rows: row.FacltyType = row.CPUC rows.updateRow(row) del rows del row selection +=1 arcpy.Delete_management("in_memory")
Solved! Go to Solution.
import arcpy, time arcpy.env.overwriteOutput = True arcpy.env.workspace = r"C:\Temp\Defult.gdb" fcTarget = 'Points_1' fcJoin = 'Points_2' fcOutput = 'Points_joined' arcpy.SpatialJoin_analysis(fcTarget, fcJoin, fcOutput, 'JOIN_ONE_TO_ONE', 'KEEP_COMMON') curR = arcpy.SearchCursor(fcOutput, '', '', '', 'AddressID A') curW = arcpy.UpdateCursor(fcTarget, '', '', '', 'AddressID A') # init rowW and rowR rowW = curW.next() rowR = curR.next() while rowR: currentAddress = rowR.AddressID print 'current add: ' + currentAddress while rowW.AddressID != currentAddress: rowW = curW.next() if rowR.CPUC == 'DWELL': rowW.FacltyType = 'Single Family Home' rowW.APA_CODE = '1110' rowW.StructType = 'Primary, Private' rowW.Verified = 'Yes, GRM, TA, ' + time.strftime('%m-%d-%Y') rowW.Status = 'Active' rowW.StructCat = 'Residential' else: rowW.FacltyType = 'MobileHome' rowW.APA_CODE = '1150' # put any additional conditional field statements here # put any 'global' field statements here (applies to both SF/MH) curW.updateRow(rowW) rowR = curR.next() # changed the delete statement, targeting the cursor objs (rather than the row objs) if curW: del curW if curR: del curR