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.
Would be willing to upload a sample of the parcel file(4 or 5 parcels) and a sample of the target point file?
I'll get back with you tommorrow
I tweaked the code a little to make it easier to read and tested and everything appears to be working.
#import modules
import arcpy
"""
tool box parameters
point param = feature set
targetpoint = featurelayer
parcel = featurelayer
"""
arcpy.env.qualifiedFieldNames = False
point = arcpy.GetParameterAsText(0) #point feature set
targetpoint = "PointsTest" #target point feature class
parcel = "ParcelsTest" #parcel 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 ={}
#Check that we only have one parcel and get the attributes from it
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
targetFields = ['ACCOUNT', 'OwnerName', 'SiteAddres', 'SiteNum', 'siteNumSfx', 'Predir', 'Postdir', 'SiteCity', 'SiteZip',
'SiteState', 'FacltyType', 'StructType', 'GIS_STEW', 'UpdateBy', 'Verified', 'Status', 'StructCat', 'APA_CODE',
'AddressID', 'POINT_X', 'POINT_Y', 'StreetName']
tprows = arcpy.da.InsertCursor(targetpoint, targetFields)
row = []
#Attributes from parcels
row.append(fldDict['ACCOUNT'])
row.append(fldDict['OwnerName'])
row.append(fldDict['SiteAddres'])
row.append(fldDict['SiteNum'])
row.append(fldDict['siteNumSfx'])
row.append(fldDict['Predir'])
row.append(fldDict['Postdir'])
row.append(fldDict['SiteCity'])
row.append(fldDict['SiteZip'])
#Preset attributes
row.append('ID')
row.append('Single Family Home')
row.append('Primary, Private')
row.append('CanyonCo')
row.append('TA')
row.append("Yes, GRM, TA")
row.append('Active')
row.append('Residential')
row.append('1110')
row.append(AddressID)
row.append(x)
row.append(y)
row.append(fldDict['SiteStreet'] + " " + fldDict['StreetType'])
tupleRow = (row)
tprows.insertRow(tupleRow)
del tprows
Interesting, on the row.append can you explain what the benefit is to this versus List.append
I have added the code to a script and runs but no point is actually created. I get no errors.
For me it's easier to see what's going on and looks cleaner
ok, i wasn't sure if there was an advantage to it or not.
Any ideas on why the point does not get created after i run the script?
Yes i forgot to add the field back, here is the working script.
#import modules
import arcpy
"""
tool box parameters
point param = feature set
targetpoint = featurelayer
parcel = featurelayer
"""
arcpy.env.qualifiedFieldNames = False
point = arcpy.GetParameterAsText(0) #point feature set
targetpoint = "PointsTest" #target point feature class
parcel = "ParcelsTest" #parcel 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 ={}
#Check that we only have one parcel and get the attributes from it
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
targetFields = ['ACCOUNT', 'OwnerName', 'SiteAddres', 'SiteNum', 'siteNumSfx', 'Predir', 'Postdir', 'SiteCity', 'SiteZip',
'SiteState', 'FacltyType', 'StructType', 'GIS_STEW', 'UpdateBy', 'Verified', 'Status', 'StructCat', 'APA_CODE',
'AddressID', 'POINT_X', 'POINT_Y', 'StreetName','SHAPE@XY']
tprows = arcpy.da.InsertCursor(targetpoint, targetFields)
row = []
#Attributes from parcels
row.append(fldDict['ACCOUNT'])
row.append(fldDict['OwnerName'])
row.append(fldDict['SiteAddres'])
row.append(fldDict['SiteNum'])
row.append(fldDict['siteNumSfx'])
row.append(fldDict['Predir'])
row.append(fldDict['Postdir'])
row.append(fldDict['SiteCity'])
row.append(fldDict['SiteZip'])
#Preset attributes
row.append('ID')
row.append('Single Family Home')
row.append('Primary, Private')
row.append('CanyonCo')
row.append('TA')
row.append("Yes, GRM, TA")
row.append('Active')
row.append('Residential')
row.append('1110')
row.append(AddressID)
row.append(x)
row.append(y)
row.append(fldDict['SiteStreet'] + " " + fldDict['StreetType'])
row.append(point1)
tprows.insertRow(row)
del tprows
Got it, thanks for all your help
You set 'x' on line 17, but then give it new values on lines 45 and 49. Use a different variable name in your loops if you want to maintain the value of x.
See below for a very simple example of what's going on with your variable 'x':
>>> x = 15 ... for x in range(100): ... pass ... print x ... 99