CFLib.org – Common Function Library Project

calculateUTMZone(lat, lon)

Last updated February 3, 2006
Download UDF

author

Wayne Graham                                      Wayne Graham

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

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:

<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:

<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>

Search CFLib.org


Latest Additions

Raymond Compton Raymond Compton added
structBlend
19 day(s) ago

Duncan Duncan added
IsZIPUK
19 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
25 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson