CFLib.org – Common Function Library Project

calculateUTMZone(lat, lon)

Last updated February 3, 2006

Version: 1 | Requires: ColdFusion 5 | Library: UtilityLib

 
Rated 2 time(s). Average Rating: 4.5

Description:
Calculates correct UTM zone for a given latitude/longitude point. Longitude and latitude points are given in degree format.

Return Values:
Returns a number.

Example:

view plain print about
<cfset lat = 90>
<cfset lon = 33>
<cfoutput>
    #calculateUTMZone(lat,lon)#
</cfoutput>

Parameters:

Name Description Required
lat Latitude value. Yes
lon Longitude value. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Calculates correct UTM zone for a given latitude/longitude point.
 * 
 * @param lat      Latitude value. (Required)
 * @param lon      Longitude value. (Required)
 * @return Returns a number. 
 * @author Wayne Graham (wsgrah@wm.edu) 
 * @version 1, February 3, 2006 
 */

function calculateUTMZone(lat,lon){
    // make sure the longitude is between -180 and 179.9
    var lonTemp = (arguments.lon + 180) - int((arguments.lon + 180) / 360) * 360 - 180;
    var zoneNumber = int((lonTemp + 180)/6) + 1;
            
    // Special zones for Svalbard
    if(arguments.lat GTE 72 and arguments.lat GT 84) {
        if(lonTemp GTE 0 AND lonTemp LT 9) zoneNumber = 31;
        else if(lonTemp GTE 9 AND lonTemp LT 21) zoneNumber = 33;
        else if(lonTemp GTE 21 AND lonTemp LT 33) zoneNumber = 35;
        else if(lonTemp GTE 33 AND lonTemp LT 42) zoneNumber = 37;
    }            
    return zoneNumber;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson