Select to view content in your preferred language

Converting decimal degrees to bearing and quadrant

9119
2
06-21-2011 03:44 PM
DrewDowling
Frequent Contributor
I'm working with the parcel fabric and it seems the database stores line bearings as decimal degrees. Has anybody had to use flex to convert from decimal degrees back to bearings and quadrants?

e.g. 109.4256 to S 70 34' 28" E

If anybody has had to do this already and has an actionscript function / formula or something similar they could give me that would be super.

Thanks for any help
Tags (2)
0 Kudos
2 Replies
DasaPaddock
Esri Regular Contributor
Here's a class called DegToDMS.as that comes with the Viewer's Coordinate widget:

////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2010 Esri
//
// All rights reserved under the copyright laws of the United States.
// You may freely redistribute and use this software, with or
// without modification, provided you include the original copyright
// and use restrictions.  See use restrictions in the file:
// <install location>/License.txt
//
////////////////////////////////////////////////////////////////////////////////
package widgets.Coordinate
{

//--------------------------------------
//  Other metadata
//--------------------------------------
/**
 * Utility class to pretty print decimal degree numbers.
 * @private
 */
public final class DegToDMS
{
    // Constants to define the format.
    public static const LAT:String = "lat";

    public static const LON:String = "lon";

    /**
     * Utility function to format a decimal degree number into a pretty string with degrees, minutes and seconds.
     * @param decDeg the decimal degree number.
     * @param decDir "lat" for a latitude number, "lon" for a longitude value.
     * @return A pretty print string with degrees, minutes and seconds.
     */
    public static function format(decDeg:Number, decDir:String):String
    {
        var d:Number = Math.abs(decDeg);
        var deg:Number = Math.floor(d);
        d = d - deg;
        var min:Number = Math.floor(d * 60);
        var av:Number = d - min / 60;
        var sec:Number = Math.floor(av * 60 * 60);
        if (sec == 60)
        {
            min++;
            sec = 0;
        }
        if (min == 60)
        {
            deg++;
            min = 0;
        }
        var smin:String = min < 10 ? "0" + min + "' " : min + "' ";
        var ssec:String = sec < 10 ? "0" + sec + "\" " : sec + "\" ";
        var sdir:String = (decDir == LAT) ? (decDeg < 0 ? "S" : "N") : (decDeg < 0 ? "W" : "E");
        return deg + "\xB0 " + smin + ssec + sdir;
    }
}

}
0 Kudos
DrewDowling
Frequent Contributor
Thanks Dasa

I accomplished this in pretty much the same way. I'm posting the code below in case it helps anybody but I think it does the same as what you posted but in a much less elegant way.

The code takes a result set that is returned from a relationship query. this result set has only one feature set, a collection of line features. Each feature has an attribute called Bearing that has values in decimal degrees. This attributed is then formatted formatted to bearing distance format and then added to an array collection that is bound to a data grid.

            private function onRelatedLines(results:Object, token:Object = null):void
            {
                var intBearing:Number;
                var strPrefix:String;
                var steSuff:String;
                var strDegrees:String;
                var strMinutes:String;
                var strSeconds:String;
                for each( var RelatedResultFS:FeatureSet in results)
                {
                    graphicsLayer.graphicProvider = RelatedResultFS.features;

                    for each( var RelateResultGraphic:Graphic in RelatedResultFS.features)
                    {
                        intBearing = RelateResultGraphic.attributes.Bearing;
                        if (intBearing >= 0 && intBearing <= 360)
                        {
                            if (intBearing >= 0 && intBearing < 90)
                            {
                                strPrefix = "N";
                                steSuff = "E";
                                intBearing = intBearing;
                            }
                            else if (intBearing >= 90 && intBearing < 180)
                            {
                                strPrefix = "S";
                                steSuff = "E";
                                intBearing = 180 - intBearing;
                            }
                            else if (intBearing >= 180 && intBearing < 270)
                            {
                                strPrefix = "S";
                                steSuff = "W";
                                intBearing = intBearing - 180;
                            }
                            else if (intBearing >= 270 && intBearing <= 360)
                            {
                                strPrefix = "N";
                                steSuff = "W";
                                intBearing = 360 - intBearing;
                            }

                            strDegrees = String(Math.floor(intBearing)) + String.fromCharCode(186);
                            strMinutes = String(Math.floor((intBearing - Math.floor(intBearing))* 60)) + "'";
                            strSeconds = String(Math.floor((((intBearing - Math.floor(intBearing))* 60) - Math.floor((intBearing - Math.floor(intBearing))*60))*60*100)/100) + "''";
                            RelateResultGraphic.attributes.Bearing = strPrefix + strDegrees + " " + strMinutes + " " + strSeconds + " " + steSuff;

                           
                            arrcParcelLinework.addItem(RelateResultGraphic.attributes)
                        }
                    }
                }
            }
0 Kudos