HowTo: Calculate Latitude and Longitude values using Field Calculator - ArcView 10.

14023
8
12-05-2011 01:21 AM
MelanieMageean
New Contributor
Hi All,

I have a dataset in a .gdb with WSG_84 projection. Have added two fields Latitude, Longitude using field type Double.
Would like to calculate Latitude/Longitude for this dataset using Field Calculator using VB Script in ArcView 10.
Have tried coding below from Knowledge Base > Technical Article 31863:

Dim Output As Double
Dim pPoint As IPoint
Set pPoint = [Shape]
Output = pPoint.X

Long = Output

Does not work; 'Failure during processing' error generated and field values 'Null'.

Any suggestions as to how I can generate Lat/Long values using Field Calculator in ArcView 10?

Thank you.
Kind regards,
Melanie
Tags (2)
0 Kudos
8 Replies
TimothyHales
Esri Notable Contributor
You can calculate geometry without using the Field Calculator.  Right click the field > Calculate Geometry.  You can chose the desired geometry and the coordinate system to use.
0 Kudos
RichardFairhurst
MVP Honored Contributor
I believe if you use the Python parser it is just:

!SHAPE.X!

or else perhaps:

!SHAPE.FirstPoint.X!
TimothyHales
Esri Notable Contributor
You're right Richard, you can also use: !SHAPE.FirstPoint.X! and !SHAPE.FirstPoint.Y!
0 Kudos
BonniePionke
New Contributor
I tried the !SHAPE.FirstPoint.X! and !SHAPE.FirstPoint.Y! python code after I geocated locations with an X and a Y and I did get results without any error codes.
My results looked like this: 2554640.03118 (latitude), 395983.7615536 (longitude)  for all of my addresses that are located in Wisconsin, USA.

However, I am skeptical of using the results because the results for Latitude(x) were positive instead of negative. 

So I am not using what I get from  !SHAPE.FirstPoint.X! and !SHAPE.FirstPoint.Y! in version 10 SP1 of ArcGIS.

(In the USA, longitude is negative being west of the Prime meridian, and latitude is positive
as it is north of the equator.)
0 Kudos
HardolphWasteneys
Occasional Contributor III
I tried the !SHAPE.FirstPoint.X! and !SHAPE.FirstPoint.Y! python code after I geocated locations with an X and a Y and I did get results without any error codes. 
My results looked like this:   2554640.03118 (latitude), 395983.7615536 (longitude) for all of my addresses that are located in Wisconsin, USA. 

However, I am skeptical of using the results because the results for   Latitude(x) were positive instead of negative.  

So I am not using what I get from !SHAPE.FirstPoint.X! and !SHAPE.FirstPoint.Y! in version 10 SP1 of ArcGIS. 

(In the USA, longitude is negative being west of the Prime meridian, and latitude is positive 
as it is north of the equator.)



Bonnie,

In case you hadn't noticed, the output you quote for lat-long are projected UTM coordinates not degrees of lat and long so they are always positive within the region applicable to the UTM zone (and a lot longer than degrees). To output latitude and longitude just run Field Calculator on the new fields you added as Timothy Hales previously suggested "You can calculate geometry without using the Field Calculator. Right click the field > Calculate Geometry. You can chose the desired geometry and the coordinate system to use."
or in other words, just select the Units as decimal degrees from the pull down menu when you activate it.

Hardolph
0 Kudos
AndrewRoberts2
New Contributor III
Hey guys,

I have an issue similar to this...

I know how to fill a field with the coordinates of points using the calculate geometry function. However, of the scales that I can select from, I cannot select Lat and Long but I can select decimal degrees. What I'm wondering is if it's possible to create, for example, a new field and use a python statement to manipulate the field filled with the decimal degrees to convert them to lat and long coordinates.

Thanks,
-Andrew
0 Kudos
TimothyHales
Esri Notable Contributor
Hey guys,

I have an issue similar to this...

I know how to fill a field with the coordinates of points using the calculate geometry function. However, of the scales that I can select from, I cannot select Lat and Long but I can select decimal degrees. What I'm wondering is if it's possible to create, for example, a new field and use a python statement to manipulate the field filled with the decimal degrees to convert them to lat and long coordinates.

Thanks,
-Andrew


Hi Andrew,

When you refer to lat/long coordinates, are you referring to Degrees, Minutes, Seconds?  Decimal degrees is technically lat/long.  There is a tool to convert between coordinate formats:

Convert Coordinate Formats (Data Management > Projections and Transformations)

I hope this helps.  Please let me know if you are looking for something different.

Thanks,
Timothy
0 Kudos
AndrewRoberts2
New Contributor III
Hey Tim,

Thanks I didn't know about this tool.

Sorry for the confusion, I have coordinates in decimal degrees (DD) and want to convert them to Lat and Longitude (DMS.) This tool seems like it will definitely do the job.

Thanks,
-Andrew
0 Kudos