Getting the orientation in degrees of an Oriented Point in Oracle

340 Views Asked by At

In my database I have some Oriented Point type geometries.

For example:

{3001,4326,null,{1,1,1,4,1,0},{32.4302549,37.5066298,0,0.16,-0.92,0}}

If I'm correct, my gps coordinates are
lat: 32.4302549, lon: 37.5066298
and the virtual point determining the orientation is a Point(0.16 -0.92 0)

I would like to get the orientation in degrees or radians using a query.

So far I can extract the orientation point:

SELECT SDO_UTIL.GET_COORDINATE(MY_GEOMETRY_COLUMN, 2) as orientation_vector 
FROM GCOL;

But don't know how to get the orientation. I know it can be calculated vie arctan2 function, but don't know the correct oracle syntax.

2

There are 2 best solutions below

1
David Lapp On

You need to use ATAN2 to get radians with the correct quadrant.

WITH X AS (
  SELECT
     SDO_GEOMETRY(3001,4326,NULL,
       SDO_ELEM_INFO_ARRAY(1, 1, 1, 4, 1,0),
       SDO_ORDINATE_ARRAY(32.4302549, 37.5066298, 0, 0.16, - 0.92,0)) AS G
    FROM DUAL
)
SELECT
  ATAN2(
   SDO_UTIL.GET_COORDINATE(G, 2).SDO_POINT.Y , 
   SDO_UTIL.GET_COORDINATE(G, 2).SDO_POINT.X) 
FROM X;

To convert to degrees please see SDO_UTIL.CONVERT_UNIT .

0
Dusan On

Based on @David Lapp's answer, I'm posting a solution which works for me. In my application I need 0 degrees to point upwards. The correct order of parameters to the ATAN2() function is first X, then Y.

I converted the result to degrees and rounded to 2 decimal points.

WITH X AS (
    SELECT MY_GEOMETRY_COLUMN as G
    from MY_GEOMETRY_TABLE
)
SELECT ROUND(SDO_UTIL.CONVERT_UNIT(
                     ATAN2(
                             SDO_UTIL.GET_COORDINATE(G, 2).SDO_POINT.X,
                             SDO_UTIL.GET_COORDINATE(G, 2).SDO_POINT.Y),
            'Radian', 'Degree'),
        2) as orientation;