I am trying to populate the new created point with X, Y coordinates but i have not been successful. The fields it needs to populate on the point feature class is "Point_X" and "Pont_Y". it seems as only "Point_Y" is the only one that gets populated. I also need to take two fields from the parcels ("SiteStreet" & StreetType") and combine them to populate a field from on the point feature layer (StreetName) i am unsure on how to do that.
#import modules import arcpy """ tool box parameters point param = feature set targetpoint = featurelayer parcel = featurelayer """ arcpy.env.qualifiedFieldNames = False point = arcpy.GetParameterAsText(0) #point boolen targetpoint = "CCAP1" #target point feature class parcel = "parcels" #target feature class parcel_lyr = 'parcel_lyr' for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'): x,y = prow[0] del prow point1 = arcpy.Point(x, y) ptGeometry = arcpy.PointGeometry(point1) CC_list = [] with arcpy.da.SearchCursor(targetpoint, ["AddressID"]) as cursor: for row in cursor: try: if "CC" in row[0]: CC_list.append(int(row[0].strip("CC"))) except TypeError: pass del cursor CC_list.sort() AddressID = CC_list[-1] + 1 AddressID = 'CC' + str(AddressID) arcpy.MakeFeatureLayer_management(parcel,parcel_lyr) arcpy.SelectLayerByLocation_management(parcel_lyr,"INTERSECT",ptGeometry) fldList = ['ACCOUNT','OwnerName','SiteAddres','SiteNum','siteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip'] fldDict ={} if int(arcpy.GetCount_management(parcel_lyr).getOutput(0))==1: for parrow in arcpy.da.SearchCursor(parcel_lyr,fldList): for x in range(len(fldList)): fldDict[fldList]=parrow del parrow fldAttList = [] for x in range(len(fldList)): fldAttList.append(fldDict[fldList]) manualFields = ["SiteState","FacltyType", "StructType","GIS_STEW", "UpdateBy","Verified", "Status", "StructCat", "APA_CODE","AddressID", "POINT_X", "POINT_Y"] for fld in manualFields: fldList.append(fld) fixedAtts = ["ID","Single Family Home","Primary, Private","CanyonCo", "TA", "Yes, GRM, TA","Active","Residential","1110", AddressID, x, y] for att in fixedAtts: fldAttList.append(att) fldAttList.append(point1) fldtuple = (fldAttList) fldList.append( 'SHAPE@XY') tprow = arcpy.da.InsertCursor(targetpoint, fldList) tprow.insertRow(fldtuple) del tprow
Solved! Go to Solution.
I forgot to remove them from the fldList try this
#import modules import arcpy """ tool box parameters point param = feature set targetpoint = featurelayer parcel = featurelayer """ arcpy.env.qualifiedFieldNames = False point = arcpy.GetParameterAsText(0) #point boolen targetpoint = "CCAP1" #target point feature class parcel = "parcels" #target feature class parcel_lyr = 'parcel_lyr' for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'): x,y = prow[0] del prow point1 = arcpy.Point(x, y) ptGeometry = arcpy.PointGeometry(point1) CC_list = [] with arcpy.da.SearchCursor(targetpoint, ["AddressID"]) as cursor: for row in cursor: try: if "CC" in row[0]: CC_list.append(int(row[0].strip("CC"))) except TypeError: pass del cursor CC_list.sort() AddressID = CC_list[-1] + 1 AddressID = 'CC' + str(AddressID) arcpy.MakeFeatureLayer_management(parcel,parcel_lyr) arcpy.SelectLayerByLocation_management(parcel_lyr,"INTERSECT",ptGeometry) fldList = ['ACCOUNT','OwnerName','SiteAddres','SiteNum','siteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip'] fldDict ={} #setvalue = ('SiteStreet'+ 'StreetType') if int(arcpy.GetCount_management(parcel_lyr).getOutput(0))==1: for parrow in arcpy.da.SearchCursor(parcel_lyr,fldList): for w in range(len(fldList)): fldDict[fldList]=parrow del parrow fldAttList = [] #You Can Change this to a name better suited for your concatenated field newfld = str(fldDict["SiteStreet"]) +" "+str(fldDict["StreetType"]) #This Takes them out of the loop del fldDict["SiteStreet"] del (fldDict["StreetType"]) fldList.remove("SiteStreet") fldList.remove("StreetType") for w in range(len(fldList)): fldAttList.append(fldDict[fldList]) manualFields = ["SiteState","FacltyType", "StructType","GIS_STEW", "UpdateBy","Verified", "Status", "StructCat", "APA_CODE","AddressID", "POINT_X", "POINT_Y","StreetName"] for fld in manualFields: fldList.append(fld) fixedAtts = ["ID","Single Family Home","Primary, Private","CanyonCo", "TA", "Yes, GRM, TA","Active","Residential","1110", AddressID, x, y,newfld] for att in fixedAtts: fldAttList.append(att) fldAttList.append(point1) fldtuple = (fldAttList) fldList.append( 'SHAPE@XY') tprow = arcpy.da.InsertCursor(targetpoint, fldList) tprow.insertRow(fldtuple) del tprow
The x isn't populating correctly because it was reused in line 45 and 49 change those to different letters and that should fix that part
edit are the "SiteStreet" & StreetType" fields both being used in the target point feature class or are they going to another field?
I change the following x to w and get this error.
Traceback (most recent call last):
File "C:\GIS\Python\UpdateAddressPoints\CreatePointUdateAttributesTest2.py", line 46, in <module>
fldDict[fldList
TypeError: tuple indices must be integers, not float
Failed to execute (Pointtest).
the "SiteStreet" & StreetType" fields both being in the point feature class.
Weird, I closed out of arcmap and reopen it and it is now populating the X, Y. . but in feet. I have sent my coordinate system to NAD1983 but it still populates feet not Lat and Log (long: -116.5988, Lat: 43.77097) .
See the notes in the code below
#import modules import arcpy """ tool box parameters point param = feature set targetpoint = featurelayer parcel = featurelayer """ arcpy.env.qualifiedFieldNames = False point = arcpy.GetParameterAsText(0) #point boolen targetpoint = "CCAP1" #target point feature class parcel = "parcels" #target feature class parcel_lyr = 'parcel_lyr' for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'): x,y = prow[0] del prow point1 = arcpy.Point(x, y) ptGeometry = arcpy.PointGeometry(point1) CC_list = [] with arcpy.da.SearchCursor(targetpoint, ["AddressID"]) as cursor: for row in cursor: try: if "CC" in row[0]: CC_list.append(int(row[0].strip("CC"))) except TypeError: pass del cursor CC_list.sort() AddressID = CC_list[-1] + 1 AddressID = 'CC' + str(AddressID) arcpy.MakeFeatureLayer_management(parcel,parcel_lyr) arcpy.SelectLayerByLocation_management(parcel_lyr,"INTERSECT",ptGeometry) fldList = ['ACCOUNT','OwnerName','SiteAddres','SiteNum','siteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip'] fldDict ={} if int(arcpy.GetCount_management(parcel_lyr).getOutput(0))==1: for parrow in arcpy.da.SearchCursor(parcel_lyr,fldList): for w in range(len(fldList)): fldDict[fldList]=parrow del parrow fldAttList = [] #You Can Change this to a name better suited for your concatenated field newfld = str(fldDict["SiteStreet"]) +" "+str(fldDict["StreetType"]) #This Takes them out of the loop del fldDict["SiteStreet"] del (fldDict["StreetType"] for w in range(len(fldList)): fldAttList.append(fldDict[fldList]) manualFields = ["SiteState","FacltyType", "StructType","GIS_STEW", "UpdateBy","Verified", "Status", "StructCat", "APA_CODE","AddressID", "POINT_X", "POINT_Y",PutYourConcatenatedFieldHere] for fld in manualFields: fldList.append(fld) #if you change newfld change it here too fixedAtts = ["ID","Single Family Home","Primary, Private","CanyonCo", "TA", "Yes, GRM, TA","Active","Residential","1110",AddressID,x,y,newfld ] for att in fixedAtts: fldAttList.append(att) fldAttList.append(point1) fldtuple = (fldAttList) fldList.append( 'SHAPE@XY') tprow = arcpy.da.InsertCursor(targetpoint,fldList) tprow.insertRow(fldtuple) del tprow else: arcpy.AddMessage("Number of parcels selected incorrect for this process")
I made the suggested changes but i am getting an error:
Traceback (most recent call last):
File "C:\GIS\Python\UpdateAddressPoints\CreatePointUdateAttributesTest3.py", line 57, in <module>
fldAttList.append(fldDict[fldList
KeyError: 'SiteStreet'
Current code
#import modules import arcpy """ tool box parameters point param = feature set targetpoint = featurelayer parcel = featurelayer """ arcpy.env.qualifiedFieldNames = False point = arcpy.GetParameterAsText(0) #point boolen targetpoint = "CCAP1" #target point feature class parcel = "parcels" #target feature class parcel_lyr = 'parcel_lyr' for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'): x,y = prow[0] del prow point1 = arcpy.Point(x, y) ptGeometry = arcpy.PointGeometry(point1) CC_list = [] with arcpy.da.SearchCursor(targetpoint, ["AddressID"]) as cursor: for row in cursor: try: if "CC" in row[0]: CC_list.append(int(row[0].strip("CC"))) except TypeError: pass del cursor CC_list.sort() AddressID = CC_list[-1] + 1 AddressID = 'CC' + str(AddressID) arcpy.MakeFeatureLayer_management(parcel,parcel_lyr) arcpy.SelectLayerByLocation_management(parcel_lyr,"INTERSECT",ptGeometry) fldList = ['ACCOUNT','OwnerName','SiteAddres','SiteNum','siteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip'] fldDict ={} #setvalue = ('SiteStreet'+ 'StreetType') if int(arcpy.GetCount_management(parcel_lyr).getOutput(0))==1: for parrow in arcpy.da.SearchCursor(parcel_lyr,fldList): for w in range(len(fldList)): fldDict[fldList]=parrow del parrow fldAttList = [] #You Can Change this to a name better suited for your concatenated field newfld = str(fldDict["SiteStreet"]) +" "+str(fldDict["StreetType"]) #This Takes them out of the loop del fldDict["SiteStreet"] del (fldDict["StreetType"]) for w in range(len(fldList)): fldAttList.append(fldDict[fldList]) manualFields = ["SiteState","FacltyType", "StructType","GIS_STEW", "UpdateBy","Verified", "Status", "StructCat", "APA_CODE","AddressID", "POINT_X", "POINT_Y","StreetName"] for fld in manualFields: fldList.append(fld) fixedAtts = ["ID","Single Family Home","Primary, Private","CanyonCo", "TA", "Yes, GRM, TA","Active","Residential","1110", AddressID, x, y,newfld] for att in fixedAtts: fldAttList.append(att) fldAttList.append(point1) fldtuple = (fldAttList) fldList.append( 'SHAPE@XY') tprow = arcpy.da.InsertCursor(targetpoint, fldList) tprow.insertRow(fldtuple) del tprow
I forgot to remove them from the fldList try this
#import modules import arcpy """ tool box parameters point param = feature set targetpoint = featurelayer parcel = featurelayer """ arcpy.env.qualifiedFieldNames = False point = arcpy.GetParameterAsText(0) #point boolen targetpoint = "CCAP1" #target point feature class parcel = "parcels" #target feature class parcel_lyr = 'parcel_lyr' for prow in arcpy.da.SearchCursor(point,'SHAPE@XY'): x,y = prow[0] del prow point1 = arcpy.Point(x, y) ptGeometry = arcpy.PointGeometry(point1) CC_list = [] with arcpy.da.SearchCursor(targetpoint, ["AddressID"]) as cursor: for row in cursor: try: if "CC" in row[0]: CC_list.append(int(row[0].strip("CC"))) except TypeError: pass del cursor CC_list.sort() AddressID = CC_list[-1] + 1 AddressID = 'CC' + str(AddressID) arcpy.MakeFeatureLayer_management(parcel,parcel_lyr) arcpy.SelectLayerByLocation_management(parcel_lyr,"INTERSECT",ptGeometry) fldList = ['ACCOUNT','OwnerName','SiteAddres','SiteNum','siteNumSfx','Predir','SiteStreet', 'StreetType', 'Postdir', 'SiteCity', 'SiteZip'] fldDict ={} #setvalue = ('SiteStreet'+ 'StreetType') if int(arcpy.GetCount_management(parcel_lyr).getOutput(0))==1: for parrow in arcpy.da.SearchCursor(parcel_lyr,fldList): for w in range(len(fldList)): fldDict[fldList]=parrow del parrow fldAttList = [] #You Can Change this to a name better suited for your concatenated field newfld = str(fldDict["SiteStreet"]) +" "+str(fldDict["StreetType"]) #This Takes them out of the loop del fldDict["SiteStreet"] del (fldDict["StreetType"]) fldList.remove("SiteStreet") fldList.remove("StreetType") for w in range(len(fldList)): fldAttList.append(fldDict[fldList]) manualFields = ["SiteState","FacltyType", "StructType","GIS_STEW", "UpdateBy","Verified", "Status", "StructCat", "APA_CODE","AddressID", "POINT_X", "POINT_Y","StreetName"] for fld in manualFields: fldList.append(fld) fixedAtts = ["ID","Single Family Home","Primary, Private","CanyonCo", "TA", "Yes, GRM, TA","Active","Residential","1110", AddressID, x, y,newfld] for att in fixedAtts: fldAttList.append(att) fldAttList.append(point1) fldtuple = (fldAttList) fldList.append( 'SHAPE@XY') tprow = arcpy.da.InsertCursor(targetpoint, fldList) tprow.insertRow(fldtuple) del tprow
So the fldList.remove removes the fields from list fldList.
Awesome! thanks.
Because you also have to change it in the for loops. So it's lines 45,46 and 49,50. You should also be getting the coordinated of the data frame even though it's not set explicitly
sorry, forgive my dumbness but i am not sure i understand?