English

How To: Project Decimal Degree X/Y coordinate values

Procedure

Summary

You can Project Decimal Degree coordinate points using Avenue. For example, suppose you have a table of DD coordinates that you want to overlay with a coverage in in a projected coordinate system. This document details how to project these coordinate values into UTM. The script below assumes that the table contains Decimal Degree values in separate X and Y fields and that the locations are somewhere in the Northern Hemisphere.

Soulution

1. Paste the following code into a new script window.

2. Compile and run the script.

3. Select which UTM Zone you want the coordinates converted into.

4. Select the table that contains the Decimal Degree coordinates.

5. Select the X-longitude and the Y-latitude value fields.

Code:
'------------ DD2UTM.AVE ------------

'--- This script takes a table of points in DD and projects them
'--- into UTM coordinates for a user-defined Zone.

'-- Each UTM Zone has an X-coordinate which
'-- extends from 0 to 1,000,000 meters, where 500,000 is the false easting
'-- coordinate for the central meridian, although the actual coordinates
'-- rarely get as low as 0, nor as high as 1,000,000, otherwise the
'-- coordinates would actually fall into an adjacent UTM Zone.

'-- Each UTM Zone for the Northern Hemisphere has a Y-coordinate which
'-- extends from 0 at the equator to 10,000,000 meters at the North Pole.

'-- Hence, when I create the Rectangle below, the X extends from 0 to
'-- 1 million, and the Y extends from 0 to 10 million.
'-- Then the 'Trnmerc.Make' request turns the rectangle into a UTM

myRect = Rect.Make(0@0,1000000@10000000)
myUTM = Trnmerc.Make(myRect)

a = MsgBox.Input("Enter the UTM Zone into which"+NL+
"you want to project the points.",
"Zone Choice","")
if (a = nil) then
return nil
end

'-- Conversion factor to turn a UTM Zone into its Central Meridian
b = ((a.AsNumber * 6) - 183)

myUTM.SetCentralMeridian(b)
myUTM.SetFalseEasting(500000)
myUTM.SetFalseNorthing(0)
myUTM.SetReferenceLatitude(0)
myUTM.SetScale(0.9996)

theDocList=av.GetProject.GetDocs
theTabList=List.Make
for each d in theDocList
if (d.Is(Table))
then
theTabList.Add(d)
end '-- is table
end '-- for each d

theSelTab=MsgBox.Choice(theTabList,
"Choose the table that contains the DD coord that you want to project",
"Table Choice")

if (theSelTab = nil) then
return nil
end
theVtab=theSelTab.GetVTab
theFields=theVtab.GetFields

theDDXfld=MsgBox.Choice(theFields,
"Select the field which contains the X-longitude coordinate",
"Where is X?")
theDDYfld=MsgBox.Choice(theFields,
"Select the field which contains the Y-Latitude coordinate",
"Where is Y?")

theNewDDXfld=Field.Make("XlongDD",#FIELD_DECIMAL,12,6)
theNewDDYfld=Field.Make("YlatDD",#FIELD_DECIMAL,12,6)
theNewUTMXfld=Field.Make("XlongUTM",#FIELD_DECIMAL,16,2)
theNewUTMYfld=Field.Make("YlatUTM",#FIELD_DECIMAL,16,2)
theNewFldList={theNewDDXfld,theNewDDYfld,theNewUTMXfld,theNewUTMYfld}

theNewFile=FileDialog.Put("*.dbf".AsFileName,"dBASE Files",
"Save dBASE table file")
if (theNewFile = nil) then
return nil
end
theNewVTab=VTab.MakeNew(theNewFile,dBASE)
theNewVTab.AddFields(theNewFldList)

for each rec in theVtab
theDDXval=theVtab.ReturnValue(theDDXfld,rec)
theDDYval=theVtab.ReturnValue(theDDYfld,rec)
theNewrec=theNewVTab.AddRecord
theNewVTab.SetValue(theNewDDXfld,theNewrec,theDDXval)
theNewVTab.SetValue(theNewDDYfld,theNewrec,theDDYval)
theDDpoint=Point.Make(theDDXval,theDDYval)
myUTM.ProjectPt(theDDpoint)
theUTMXval=theDDpoint.GetX
theUTMYval=theDDpoint.GetY
theNewVTab.SetValue(theNewUTMXfld,theNewrec,theUTMXval)
theNewVTab.SetValue(theNewUTMYfld,theNewrec,theUTMYval)
end

t = Table.Make(theNewVTab)
t.SetName(theNewVTab.GetName)
t.GetWin.Open
t.StopEditing

'------------ End of Script ------------


Note:
You may want to modify this script so that it makes the user select a unique ID field from the first table in (A) above. This field can be cloned into the new table in Step 2, which then can be used as the basis for a one-to-one table join, where the new coordinate fields can be rejoined back to the original table.