Thursday, 10 May 2007

What Are My X and Y Co-ordinates

In Oracle a geometry column hides the number of vertices and their values from you the casual coder.

Here is one method to extract (and display) the values of the geometry vertices.

You start by "loading" a working variable with the geometry in question.
Select geoloc into work_geom from dual;


Then you can get the number of vertices
Select sdo_util.getnumvertices (work_geom) into vert from dual;


For nv in 1..vert loop
Select work_geom.sdo_ordinates ( (nv - 1 ) * 2 + 1) as x,
work_geom.sdo_ordinates ( (nv - 1 ) * 2 + 2) as y
Into x_out ,
y_out
from dual;
dbms_output.put_line( 'x = '||x_out||' and y = '||y_out );
End loop;


Obviously this is merely an example but it can be expanded to suit your needs.

No comments: