|
POST
|
my thought was to get the x,y and convert them to lat and long right when the point is created. i made the change to your suggestion and it did change the x,y to lat & long but the coordinates are not right. x = pointA.centroid.X y = pointA.centroid.Y the point should be at x = -116.538104 and Y=43.723481 but instead it's at X= -125.292411 and Y= 41.269025
... View more
07-22-2015
02:33 PM
|
0
|
0
|
999
|
|
POST
|
if i run it against the target point it take 1 min. 7 secs, with no error. The point is created but the x,y are not lat long.
... View more
07-22-2015
01:26 PM
|
0
|
2
|
3043
|
|
POST
|
I made the change from 115702 to 4269 the code ran but the POINT_X and POINT_Y did not get converted, no error. with arcpy.da.UpdateCursor(point,["POINT_X","POINT_Y"]) as cursor:
for row in cursor:
point_utm = arcpy.PointGeometry(arcpy.Point(row[0],row[1]),arcpy.SpatialReference(103269))
pointA = point_utm.projectAs(arcpy.SpatialReference(4269))
row[0]= pointA.centroid.X
row[1]= pointA.centroid.Y
cursor.updateRow(row)
... View more
07-22-2015
12:01 PM
|
0
|
1
|
3043
|
|
POST
|
it's going from projected coordinates to geographic coordinates.
... View more
07-22-2015
11:59 AM
|
0
|
0
|
3043
|
|
POST
|
i have tried the follwoing but getting an error. Traceback (most recent call last): File "C:\GIS\Python\UpdateAddressPoints\CreatePointUdateAttributesTest6.py", line 29, in <module> pointA = point_utm.projectAs(arcpy.SpatialReference(115702)) File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 927, in __init__ self._arc_object.createFromFile(item) RuntimeError: ERROR 999999: Error executing function. the input is not a geographic or projected coordinate system #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 = "CCAP2" #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)
#convert x,y to lat & long
with arcpy.da.UpdateCursor(point,["POINT_X","POINT_Y"]) as cursor:
for row in cursor:
point_utm = arcpy.PointGeometry(arcpy.Point(row[0],row[1]),arcpy.SpatialReference(103269))
pointA = point_utm.projectAs(arcpy.SpatialReference(115702))
row[0]= pointA.centroid.X
row[1]= pointA.centroid.Y
cursor.updateRow(row)
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)
arcpy.RefreshActiveView()
del tprows
#convert x,y to lat & long
... View more
07-22-2015
11:40 AM
|
0
|
5
|
3043
|
|
POST
|
I currently have a code that creates a point with a mouse click and works great, but i need the x,y to be calculated to lat and long. The current codes does that but it is slow and i use updatecursor. I would like to like to do the conversion when the ptGeometry, basically store it in the point when it gets created because with the current code it takes about 30 secs. I have tried to makefeaturelayer with the ptGeometry but and insert the lat long fields and then use the to update the point but i get nothing. so i need some help on how i can do this with the 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 = "CCAP" #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 ={}
#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)
arcpy.RefreshActiveView()
del tprows
#convert x,y to lat & long
latLonRef = "Coordinate Systems\Geographic Coordinate Systems\North America\NAD 1983.prj"
featureClasses = arcpy.GetParameterAsText(0)
featureClassesList = featureClasses.split(";")
for featureClass in featureClassesList:
rows = arcpy.UpdateCursor(targetpoint, "", latLonRef)
for row in rows:
feat = row.getValue("shape")
cent = feat.centroid
# To get the polygon area: cent = feat.area
row.POINT_X = cent.Y
row.POINT_Y = cent.X
rows.updateRow(row)
#arcpy.AddMessage(str(lat) + ", " + str(lon))
else:
arcpy.AddMessage("Number of parcels selected incorrect for this process") Message was edited by: 2CDSD 2C
... View more
07-22-2015
10:09 AM
|
0
|
14
|
8264
|
|
POST
|
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?
... View more
07-22-2015
08:09 AM
|
0
|
2
|
1425
|
|
POST
|
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.
... View more
07-22-2015
07:39 AM
|
0
|
4
|
1425
|
|
POST
|
sorry, forgive my dumbness but i am not sure i understand?
... View more
07-21-2015
07:37 AM
|
0
|
9
|
1692
|
|
POST
|
So the fldList.remove removes the fields from list fldList. Awesome! thanks.
... View more
07-21-2015
07:34 AM
|
1
|
0
|
1692
|
|
POST
|
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
... View more
07-21-2015
07:03 AM
|
0
|
2
|
1692
|
|
POST
|
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) .
... View more
07-20-2015
02:28 PM
|
0
|
4
|
1692
|
|
POST
|
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 ]=parrow TypeError: tuple indices must be integers, not float Failed to execute (Pointtest). the "SiteStreet" & StreetType" fields both being in the point feature class.
... View more
07-20-2015
02:13 PM
|
0
|
16
|
1692
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2022 11:37 AM | |
| 1 | 10-31-2023 10:16 AM | |
| 1 | 02-16-2023 01:50 PM | |
| 1 | 08-11-2021 11:13 AM | |
| 1 | 01-06-2021 10:45 AM |
| Online Status |
Offline
|
| Date Last Visited |
09-10-2024
10:42 AM
|