2 Replies Latest reply: Jan 23, 2013 12:41 AM by Simon Greener RSS

    Haversine formula vs. MDSYS.SDO_GEOM.SDO_DISTANCE

      We need to calculate the distance between 2 lat/longs (from GPS unit).

      What is more accurate, the use of MDSYS.SDO_GEOM.SDO_DISTANCE or a hand coded Haversine Formula?

        • 1. Re: Haversine formula vs. MDSYS.SDO_GEOM.SDO_DISTANCE
          Stefan Jager
          Hi JB,

          Accuracy depends on your data. What accuracy do you need? Do you need to control your calculations (I know a few businesses where that is of extreme importance)?

          Or do you need reliability and ease of implementation? Don't forget that your own function might have/introduce bugs that SDO_GEOM.SDO_DISTANCE doesn't have.

          One thing that SDO_DISTANCE cannot do, and you can do when you build your own function, is take the accuracy of the GPS measurement into account (PDOP). At least, if your GPS unit provides you with the DOP's, which it should if accuracy is that important. For example: one of your points is measured with a PDOP of 2.5 meter due to awkward psotioning of satellites. Nothing you can do about that, but a calculation of centimeters becomes rather unnessesary at that point. SDO_DISTANCE does not do anything with that, your own function can.

          • 2. Re: Haversine formula vs. MDSYS.SDO_GEOM.SDO_DISTANCE
            Simon Greener
            Well, easiest thing to do is to conduct a test.

            I looked at this website: http://www.movable-type.co.uk/scripts/latlong-vincenty.html

            The answer to the default functional demo is 969954.114 meters.

            Testing with SDO_DISTANCE we get (I converted the DMS values to DD):
            select sdo_geom.sdo_distance(
                      sdo_geometry(2001,8307,sdo_point_type(-5.71475,      50.0663222222,null),null,null),
                      0.05) as dist
              from dual;
            -- Result
            Which is pretty similar!!

            So, don't bother coding your own Haversine (you would have to add extra parameters to pass in the ellisodal params for non-WGS84 SRIDs...), use what comes out of the box.

            Does that answer you question? If so, please award points.