Re: database function to get distance between 2 latitude/longitude points

  • From: Jason Heinrich <jheinrichdba@xxxxxxxxx>
  • To: dd.yakkali@xxxxxxxxx
  • Date: Thu, 30 Apr 2009 10:04:56 -0500

Oracle Locator is a subset of the Spatial option, and is included in all
editions of Oracle.  As Peter mentioned, the SDO_GEOM.SDO_DISTANCE function
will give you your answer.  Here's the definition (
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14255/sdo_objgeom.htm#i857957
):

SDO_GEOM.SDO_DISTANCE(
     geom1 IN SDO_GEOMETRY,
     geom2 IN SDO_GEOMETRY,
     tol IN NUMBER
     [, unit IN VARCHAR2]
     ) RETURN NUMBER;

And here's an example:

distance = SDO_GEOM.SDO_DISTANCE(
MDSYS.SDO_GEOMETRY (2001, 8307, MDSYS.SDO_POINT_TYPE(longitude1, latitude1,
NULL), NULL, NULL),
MDSYS.SDO_GEOMETRY (2001, 8307, MDSYS.SDO_POINT_TYPE(longitude2, latitude2,
NULL), NULL, NULL),
1,
'MILE');

Spatial data and the functions to work with it can be a little complex, but
it's a powerful tool and can be a lot of fun.  I strongly recommend studying
the Spatial documentation and the MDSYS.SDO_* tables.

--
Jason Heinrich


2009/4/29 dd yakkali <dd.yakkali@xxxxxxxxx>

> Has anybody written a database funtion to get this?
>
> I got this code from http://www.movable-type.co.uk/scripts/latlong.html
>
> R = earth's radius (mean radius = 6,371km)
> Δlat = lat2- lat1
> Δlong = long2- long1
> a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
> c = 2.atan2(√a, √(1-a))
> d = R.c
>
>
> I am not a math guy, i am just wondering has any one written any db
> function for this.
>
> thanks
> Deen
>

Other related posts: