where to adjust unit in the python code for calculate geometry

1955
3
04-29-2012 01:07 AM
ElaineKuo
Occasional Contributor
Hello,

I used calculate geometry to get X and Y coordinates for point shapefiles.
However, the unit is in meters. (Behrmann)
Please kindly advise if any method available in python to adjust the unit to decimal degree of longitude and latitude.
Thanks.

(ArcGIS 9.3 and pythonwin 2.5)

Code

# Calculate x and y centroid fields using the geometry property Centroid (by David Wynne)
import arcgisscripting, sys
gp = arcgisscripting.create()

inputfc = sys.argv[1]

gp.AddField_management(inputfc, "xCentroid", "DOUBLE", 18, 11)
gp.AddField_management(inputfc, "yCentroid", "DOUBLE", 18, 11)

# Centroid property returns a string with x and y separated by a space
xExpression = "float(!SHAPE.CENTROID!.split()[0])"
yExpression = "float(!SHAPE.CENTROID!.split()[1])"

gp.CalculateField_management(inputfc, "xCentroid", xExpression, "PYTHON")
gp.CalculateField_management(inputfc, "yCentroid", yExpression, "PYTHON")
Tags (2)
0 Kudos
3 Replies
curtvprice
MVP Esteemed Contributor

Please kindly advise if any method available in python to adjust the unit to decimal degree of longitude and latitude.


The easiest approach I think is to project the dataset into geographic coordinates (say GCS WGS84 or NAD83) before running the script. If you want to add those DD fields to the original projected (meters) shapefile, copy the fields over using the Join Field tool.
0 Kudos
ElaineKuo
Occasional Contributor
The easiest approach I think is to project the dataset into geographic coordinates (say GCS WGS84 or NAD83) before running the script. If you want to add those DD fields to the original projected (meters) shapefile, copy the fields over using the Join Field tool.


Thanks for the good idea.
However, two items still unsure.
1. Please kindly explain what DD field mean. (Are they abbreviation of ?)
2. Please kindly explain why using the Join Field tool.
(For instance, InputDataset=> the original projected shapefile; InputJoinField => ? ; JoinTable=>? OutputJoinField=>?)
0 Kudos
curtvprice
MVP Esteemed Contributor
Thanks for the good idea.
However, two items still unsure.
1. Please kindly explain what DD field mean. (Are they abbreviation of ?)
2. Please kindly explain why using the Join Field tool.
(For instance, InputDataset=> the original projected shapefile; InputJoinField => ? ; JoinTable=>? OutputJoinField=>?)


Sorry "DD" is my shorthand for decimal degrees

Join Field can be used to do a "permanent join" that is copy fields from one feature class to another. In this case the Join table would be the projected version of your feature class (in decimal degrees) that you created to get those x y values. The Input and Output join fields are the fields used to match the input table records.
0 Kudos