CFLib.org – Common Function Library Project

Decimal2Sexagesimal(pCoordinate[, pCoordinatePart])

Last updated April 23, 2002

author

Christopher Tackett

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Returns a sexagesimal coordinate from a decimal coordinate representation. Also will return just a part of the sexagesimal coordinate if requested.

Return Values:
Returns a string.

Example:

<cfoutput>
#Decimal2Sexagesimal(34.3232123)#
</cfoutput>

Parameters:

Name Description Required
pCoordinate Decimal coordinate. Yes
pCoordinatePart Coordinate part requested. Can be: degree(s),minute(s),second(s) No

Full UDF Source:

/**
 * Converts a decimal Lat/Long coordinate into sexagesimal (degrees, minutes, seconds).
 * 
 * @param pCoordinate      Decimal coordinate. 
 * @param pCoordinatePart      Coordinate part requested. Can be: degree(s),minute(s),second(s) 
 * @return Returns a string. 
 * @author Christopher Tackett (cflib@tackettproxy.com) 
 * @version 1, April 23, 2002 
 */
Function Decimal2Sexagesimal(pCoordinate) {
    var pCoordinatePart = "";
    var myDegrees = "";
    var myMinutes = "";
    var mySeconds = "";
    var retval = "";
    
    myDegrees = Int(pCoordinate);
    myMinutes = (pCoordinate - Int(pCoordinate)) * 60;
    mySeconds = (myMinutes - Int(myMinutes)) * 60;
    
    mySeconds = Round(mySeconds * 10000) / 10000;
    
    if (mySeconds eq 60) {
        myMinutes = myMinutes + 1;
        if (myMinutes eq 60) {
            myDegrees = myDegrees + 1;
            myMinutes = 0;
        }
        mySeconds = 0;
    }
    
    retval = myDegrees & chr(176) & " " & Int(myMinutes) & "' " & mySeconds & chr(34);
    
    if (ArrayLen(Arguments) gt 1) {
    
        pCoordinatePart = Arguments[2];
        
        if (pCoordinatePart eq "degree" or pCoordinatePart eq "degrees" or pCoordinatePart eq 1)
            retval = myDegrees;
        else if (pCoordinatePart eq "minute" or pCoordinatePart eq "minutes" or pCoordinatePart eq 2)
            retval = Int(myMinutes);
        else if (pCoordinatePart eq "second" or pCoordinatePart eq "seconds" or pCoordinatePart eq 3)
            retval = mySeconds;
            
    }
    
    return retval;

}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson