AnsweredAssumed Answered

add XY not work for calculate XY coordinate

Question asked by helenak on Apr 29, 2012
Latest reply on May 1, 2012 by mdenil
Dear all,

I have a python code to calculate longitude and latitude for points in shapefiles.
(ArcGIS 9.3 and python 2.5)

However, the function of AddXY did not work.
Please kindly help and thank you in advance.


Code
##Script Name: XY coordinates
##Description: Get centroid X and Y of shapefiles
##Created By: Elaine Kuo
##Date: 29/04/2012


#Import standard library modules
import win32com.client, sys, os

#Create the Geoprocessor object
GP = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

#Set the input workspace
#GP.workspace = sys.argv[1]
#Set the workspace.
GP.Workspace= "G:/temp_stage_3_centroid_of_B_NB/Sylviidae_86"

#Set the output workspace
#outWorkspace = sys.argv[2]
#Set the workspace. List all of the feature classes in the dataset
outWorkspace= "G:/temp_stage_3_centroid_of_B_NB/Sylviidae_86"


try:
    #Get a list of the featureclasses in the input folder
    fcs = GP.ListFeatureClasses()

    # Loop through the above list
    fcs.reset
    fc = fcs.next()


    while fc:
           
            #Validate the new feature class name for the output workspace.
            outFeatureClass =GP.ValidateTableName(fc,outWorkspace)

           # Get centroids of the feature classes
            # a single feature class
            GP.Toolbox = "Data Management"
           
           
            # add two new fields

            GP.AddField_management(fc, "Logitude", "DOUBLE", 4, 4)
            GP.AddField_management(fc, "Latitude", "DOUBLE", 4, 4)

   
            # Add X Y coordinate to the feature classes
            GP.Toolbox = "Data Management"
            GP.AddXY(fc)
         
   

except:
    GP.AddMessage(GP.GetMessages(2))
    print GP.GetMessages(2)

Outcomes