field calculator

3382
2
11-04-2011 02:16 PM
by Anonymous User
Not applicable
Original User: luke.kaim

I need some help with this code. I need to be able to change the units of X and Y within model builder. Therefore, I can not use calculate geometry. How do I convert the X and Y locations into decimal degrees using the field calculator? The below code is not working. I want to find X and Y location of points and then be able to change the units of the points from meters to decimal degrees. I need to be able to automate this process. Please help.

X-coordinate of a point

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

Y-coordinate of a point

Dim dblY As Double
Dim pPoint As IPoint
Set pPoint = [Shape]
dblY = pPoint.Y

"Shape and length properties of the geometry field can be modified with unit types expressed with an @ sign".



Thank you,
Luke Kaim

Thank you
Luke Kaim (SIE)
Lucas.Kaim@maine.edu
(914)263-7866
0 Kudos
2 Replies
RichardFairhurst
MVP Honored Contributor
Here is what Melita Kennedy gave in response to a similar question I had about converting Angular Units (degrees) into Linear Units (km, miles, meters, feet, etc.):

"I know the 3D team calculates a conversion value when horizontal coordsys is geographic to match up with the z values. It helps that data is usually large scale, so you can make an assumption. A rough equivalency is that 1 deg north-south is about 110 km. However, this only holds east-west at the equator. A rough estimate for east-west is 110 km * cos(latitude). Thus, at 60N or 60S, a degree is around 55 km. How the 3D team balances that out, I don't know."

Latitude is the Y coordinate. You should not use the VBA method of extracting point data anymore, because at ArcGIS 10 it does not work in the field calculator, only Python will work.  So for Python using Melita's formula your Y coordinate would be:

110 * cos(!shape.Y!) * #unit_conversion_factor#

Replace the #unit_conversion_factor# above to be the unit conversion factor that will convert from km to the linear units that you ultimately want.  For example, km to meters is 1000, and km to feet is approximately 3280.838862.

Edit:  (This is backwards from what you want to do.  Sorry.)
0 Kudos
RichardFairhurst
MVP Honored Contributor
Check out this help link.  It indicates that if you provide a cursor object with the Spatial Reference desribed from a feature class (a Projected Coordinate System in your case giving Linear Units in meters) and then convert the cursor to another Spatial Reference (a Geographical Coordinate System giving units in Decimal Degrees) the output of the cursor will convert the input feature coordinates to the new coordinate system.  Should work with any pair of Coordinate Systems (Projected or Geographic).  This may not work in the field calculator, but it would work in a Python script that could be used in Model Builder or with Windows Scheduler for the automation.

If you open the properties of your feature class you should see the Projected Coordinate System it is using and the Linear Units it uses (meters).  It should also indicate a Geographic Coordinate System that underlies the Projection based in Angular Units (usually Decimal Degrees).  That would be the natural transformation to use unless you were specifically trying to match another Geographic Coordinate System, such as the one Google users.  I hope this helps.
0 Kudos