OT: decimal degree conversion

Joel Firestone mms at GNETCONSULTING.COM
Thu Jan 13 16:29:53 EST 2005


Ed/Matt:

Thanks for the info.  I appreciate it.

Joel

----- Original Message -----
From: "Ed McNierney" <ed at TOPOZONE.COM>
To: <MAPSERVER-USERS at LISTS.UMN.EDU>
Sent: Thursday, January 13, 2005 12:05 PM
Subject: Re: [UMN_MAPSERVER-USERS] OT: decimal degree conversion


Joel -

As Matt has correctly pointed out, this is an arithmetic operation, not
a string one.  You incorrectly assume that the minutes portion gets
converted into the first two decimal places and the seconds portion into
the the third and remaining decimal places.  You're making it too hard
<g>!

0 degrees, 0 minutes, 59 seconds (00:00:59) equals 59/3600 degrees =
0.01639 degrees, while your algorithm gets 0.001639 - one tenth the
correct value.

$plot = $arrCoords[0] + ($arrCoords[1] / 60) + ($arrCoords[2] / 3600);

Is all you need - note the lack of round () calls; that's intentional.

     - Ed

Ed McNierney
President and Chief Mapmaker
TopoZone.com / Maps a la carte, Inc.
73 Princeton Street, Suite 305
North Chelmsford, MA  01863
ed at topozone.com
(978) 251-4242

-----Original Message-----
From: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU] On
Behalf Of MapServer User
Sent: Thursday, January 13, 2005 8:47 AM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: [UMN_MAPSERVER-USERS] OT: decimal degree conversion

MapServer Users:

I could use some quick help in diagnosing the problem I have with
plotting issues.  I use the following PHP to convert a lat/long
(xx:xx:xx) to decimal degrees.

If anyone could point out the flaws, I would appreciate it.  Some plot
fine.  Others appear to be off.  I'm assuming this is the culprit.

Thanks.

// our plotting function to specify degrees
    function plot_degrees($location) {
        // create an array of our data
        $arrCoords = explode(":", $location);

        // set our data
        $long = $arrCoords[0];
        $longdiv1 = round((($arrCoords[1] / 60) * 100));
        $longdiv2 = round((($arrCoords[2] / 3600) * 100000));

        // create our plotting location
        $plot = $long .= "." . $longdiv1 . $longdiv2;

        // return our appended string
        return $plot;
    }

Joel



More information about the mapserver-users mailing list