Oracle - Converting SDO_GEOMETRY to WKT?

柔情痞子 提交于 2019-12-23 10:26:46

问题


I am very new to oracle spatial.

I have a spatial table with one SDO_GEOMETRY column. After inserting POINT data in this table, I want to retrieve data in WKT format.

Here is what I did:

Inserting data -

INSERT INTO new_test (name, geom) VALUES (
'Test', 
SDO_GEOMETRY(
             2001,
             4326, 
             SDO_POINT_TYPE(12,14,NULL), 
             NULL, 
             NULL));

Fetching data -

SELECT NAME, SDO_UTIL.TO_WKTGEOMETRY(GEOM) AS point FROM NEW_TEST;

Output -

NAME | POINT
-------------
Test | (null)

Why do I get null here? Shouldn't it display the co-ordinate points?


回答1:


The function SDO_UTIL.TO_WKTGEOMETRY seems not to be available in the Express version (Source - Siva Ravada-Oracle):

Oracle Express does not have a Javavm in the database and the WKT conversion routines need this as the feature is implemented as Java stored procedures. So these WKT routines are not supported on the Express edition.

You can still build your own WKT like this (for points):

SELECT name, 'POINT ('||t.X||' '||t.Y||')' AS point FROM NEW_TEST p, TABLE(SDO_UTIL.GETVERTICES(p.GEOM)) t;



回答2:


Too long for a comment - not sure why it doesn't work for you but I cannot replicate your results:

Oracle Setup:

CREATE TABLE new_test ( name varchar2(20), geom SDO_GEOMETRY );

INSERT INTO new_test (name, geom)
VALUES (
  'Test', 
  SDO_GEOMETRY( 2001, 4326, SDO_POINT_TYPE(12,14,NULL), NULL, NULL)
);

Query:

SELECT NAME, SDO_UTIL.TO_WKTGEOMETRY(GEOM) AS point FROM NEW_TEST;

Output:

NAME POINT                                                                          
---- -----------------
Test POINT (12.0 14.0)


来源:https://stackoverflow.com/questions/44832223/oracle-converting-sdo-geometry-to-wkt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!