Calculating lat/long values

872
2
09-22-2011 01:47 PM
by Anonymous User
Not applicable
I am not normally a programmer myself, but I've used ESRI's model builder and exported models to python scripts that can be executed as part of a batch file. It's not too hard to do, but I don't see a standard toolbox to use and may need to be handled by python.

Basically I need to build a model to trigger ESRI's "Calculate Geometry" function, returning results in decimal degrees or DMS. I don't see any toolboxes to serve that purpose. After searching online, all I can find are python scripts using the CalculateValue toolbox to return the X-Y values. But they're returned in feet and I need to have decimal degrees.

I found a script that looked like what I needed, but it required the Defense Mapping extension in order to use it, which I don't have.

Any easy answers?
Tags (2)
0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
When calculating area or length for a feature class, the units will be based off of the coordinate system.  For example, if your feature class is projected to State Plane Feet the calculated area/length will be in feet.  If you use the 'arcpy.UpdateCursor' function you can calculate the area/length based off of another coordinate system.  A geographic coordinate system (i.e. WGS 1984) will return the area/length as decimal degrees.

Here is an example:

import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"

fc = "Mains"

rows = arcpy.UpdateCursor(fc, "", "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj")

for row in rows:
    geom = row.shape
    row.Area_DD = geom.area
    rows.updateRow(row)

del row, rows 


The mains feature class is projected to 'NAD_1983_StatePlane_Michigan_South_FIPS_2113_IntlFeet', but I specified the geographic coordinate system 'WGS 1984' within the UpdateCursor function.  Now when I calculate the area to field 'Area_DD' it will be in Decimal Degrees rather than feet.
0 Kudos
RussellProvost
New Contributor II
I am not normally a programmer myself, but I've used ESRI's model builder and exported models to python scripts that can be executed as part of a batch file. It's not too hard to do, but I don't see a standard toolbox to use and may need to be handled by python.

Basically I need to build a model to trigger ESRI's "Calculate Geometry" function, returning results in decimal degrees or DMS. I don't see any toolboxes to serve that purpose. After searching online, all I can find are python scripts using the CalculateValue toolbox to return the X-Y values. But they're returned in feet and I need to have decimal degrees.

I found a script that looked like what I needed, but it required the Defense Mapping extension in order to use it, which I don't have.

Any easy answers?


I know this post is a couple years old, but I too was looking for a way to automatically populate Lat/Long values with python. Using what Jake described, I took the following approach....


import arcpy
dsc = arcpy.Describe(FC)
cursor = arcpy.UpdateCursor(FC, "", "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj")
for row in cursor:
    shape=row.getValue(dsc.shapeFieldName)
    geom = shape.getPart(0)
    x = geom.X
    y = geom.Y
    row.setValue('LONG_DD', x)
    row.setValue('LAT_DD', y)
    cursor.updateRow(row)

del cursor, row

Hope this is useful for people.