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

Related Posts

Invoking Oracle Spatial from a Custom Command

Consider a requirement where the centroid of a set of points needs to be retrieved within a custom command. This can be achieved using the ‘GTDataProvider.DataContext.Execute‘-method:

sample_set7

Sorting and merging geometries in Oracle Spatial

Consider a requirement where an unsorted set of geometries needs to be merged into a single geometry. Take for instance the following set of geometries where: a…

Product components (lower part)

Debugging Oracle PL/SQL from Visual Studio

I use TOAD for my day-to-day Oracle development, but I find it’s debugging experience very poor compared to Visual Studio. Using ODP.Net version 11 you can use…

This Post Has One Comment

  1. 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 *