AnsweredAssumed Answered

Convert x,y to lat, long

Question asked by CCweedcontrol on Jul 22, 2015
Latest reply on Jul 28, 2015 by 2Quik1

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[w]]=parrow[w]      
    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

Outcomes