SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT 3D bug workaround

The SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT function fails for 3D Compound line strings geometries as discussed over here. This is illustrated by the following sample:

2d:

with t1 as
(
select 1 id, SDO_GEOMETRY( 2002,NULL,NULL, 
         SDO_ELEM_INFO_ARRAY(1,4,2, 1,2,1, 3,2,2), 
         SDO_ORDINATE_ARRAY (       10,10, 10,14,6,10,14,10)) geom 
from dual
)
select 	id
      , CASE g.geom.st_isvalid()
          when 1 then 'valid'
          when 0 then 'invalid'
        END validness
      ,	sdo_geom.validate_geometry_with_context( theGeometry => g.geom, tolerance => 0.001) reason 
from t1 g;

produces:

ID VALIDNESS REASON
1  valid     TRUE

While the same geometry in 3d is considered invalid:

with t1 as
(
select 1 id, SDO_GEOMETRY( 3002,NULL,NULL, 
         SDO_ELEM_INFO_ARRAY(1,4,2, 1,2,1,   4,2,2), 
         SDO_ORDINATE_ARRAY(        10,10,0, 10,14,0,  6,10,0,  14,10,0)) geom 
from dual 
)
select 	id
      , CASE g.geom.st_isvalid()
        when 1 then 'valid'
        when 0 then 'invalid'
        END validness
     , sdo_geom.validate_geometry_with_context( theGeometry => g.geom, tolerance => 0.001) reason 
from t1 g;
ID VALIDNESS REASON
1  invalid   54530 Point:0,Edge:1,

A Quick workaround for this is to convert the geometry to 2d:

with t1 as
(
select 1 id, SDO_GEOMETRY( 3002,NULL,NULL, 
         SDO_ELEM_INFO_ARRAY(1,4,2, 1,2,1,   4,2,2), 
         SDO_ORDINATE_ARRAY(        10,10,0, 10,14,0,  6,10,0,  14,10,0)) geom 
from dual 
)
select 	id
      , CASE SDO_CS.MAKE_2D( geom).st_isvalid()
        when 1 then 'valid'
        when 0 then 'invalid'
        END validness
    ,	sdo_geom.validate_geometry_with_context( theGeometry => SDO_CS.MAKE_2D( g.geom), tolerance => 0.001) reason 
from t1 g;

result:

ID VALIDNESS REASON
1  valid     TRUE

hope this helps, Stephan

This entry was posted in Oracle, Oracle Spatial. Bookmark the permalink.

One Response to SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT 3D bug workaround

  1. Wijnand says:

    Hi Stephan, Your geometry consists of two elements. The first element start at the first ordinate and should be a straight line. Your second element starts at the fourth element and consists of curved lines. Could it be that your 3D example geometry is invalid because your first element of your compound-geometry is a point (10,10,0)! This is not consistent with the gtype of your geometry 3002 nor with the sdo_etype which is for your first element 2, a line.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>