Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Calculate Bearing Angle Between Two Points Or calculate the direction of a line

Sule UYSALDec 13 2018 — edited Dec 13 2018

Hi,

I'm trying to calculate the bearing of a line in Oracle Spatial.

I've found a solution for this like in below but it doesn't work;

When I check the angle between the solution and CAD PROGRAME;

I realize that does not match

and CAD PROGRAME is right

I mean cad programes calculate it right

Is there any different solution?

For example;

select

SPATIAL.sdo_bearing(

SDO_GEOMETRY(2001, 5254, SDO_POINT_TYPE(394618.51,4561749.1, NULL), NULL, NULL),

SDO_GEOMETRY(2001, 5254, SDO_POINT_TYPE(394655.68, 4561740.98, NULL), NULL, NULL))* 180 / 3.1415926535897932384626433832795

from dual;

THE RESULT IS=158.878608  DEGREE

BUT IT MUST BE  =102           DEGREE

CREATE OR REPLACE function SPATIAL.sdo_bearing(

a mdsys.sdo_geometry,

b mdsys.sdo_geometry)

return number is

azimuth number;

bearing number;

h1 number;

h2 number;

pi number := 3.1415926535897932384626433832795;

begin

h1 := sin(b.sdo_point.x - a.sdo_point.x);

h2 := cos(a.sdo_point.y) * tan(b.sdo_point.y) - sin(a.sdo_point.y) * cos(b.sdo_point.x -

a.sdo_point.x);

if(h2 = 0) then

if(h1 > 0) then

azimuth := pi/2;

else

azimuth := -pi/2;

end if;

else

azimuth := atan(h1/h2);

end if;

if(b.sdo_point.y < a.sdo_point.y) then

bearing := azimuth + pi;

else

bearing := azimuth;

end if;

if(bearing < 0) then bearing := bearing + 2 * pi; end if;

return bearing;

end sdo_bearing;

/

Comments
Post Details
Added on Dec 13 2018
10 comments
3,221 views