简体   繁体   中英

Get X coordinate from SDO_GEOMETRY point

I have a SDO_GEOMETRY point:

 --yields SDO_GEOMETRY type, which contains an SDO_POINT
 select point from tbl 

  --yields a vertex_set_tye
 select SDO_UTIL.GETVERTICES(point) from tbl

How can I extract the X coordinate value using: SDO_UTIL.GETVERTICES(point) ?

I think you can access the SDO_POINT object type via the .x attribute.

--generates test data; feel free to ignore:
with cte as (
select  sdo_geometry(2001, NULL, SDO_POINT_TYPE(123, 456, NULL), NULL, NULL) as shape 
from    dual)
    
select
    (shape).sdo_point.x as x,
    (shape).sdo_point.y as y
from
    cte

         X          Y
---------- ----------
       123        456

2.2.3 SDO_POINT

The SDO_POINT attribute is defined using the SDO_POINT_TYPE object type, which has the attributes X, Y, and Z, all of type NUMBER.


Important:

You can't just do this: shape.sdo_point.x , since Oracle thinks shape is a table alias.

You either need to create a table alias such as "a" and use it like this: a.shape.sdo_point.x . Or wrap shape in brackets so that Oracle knows it's not a table alias: (shape).sdo_point.x .

Related:

This is my table and its contents; column GEOM is SDO_GEOMETRY .

SQL> desc test
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ID                                        NOT NULL NUMBER
 GEOM                                               MDSYS.SDO_GEOMETRY

SQL> select id, geom from test where rownum = 1;

        ID GEOM(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
---------- ------------------------------------------------------------------------------------------
   1062937 SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(16,9176067, 46,2172763, NULL), NULL, NULL)

SQL>

Extracting X and Y coordinates is quite simple:

SQL> select a.x,
  2         a.y
  3  from test t cross join table(sdo_util.getvertices(t.geom)) a
  4  where t.id = 1062937;

         X          Y
---------- ----------
16,9176067 46,2172763

SQL>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM