Oracle Validate and rectify geometry

From WickyWiki

Common error messages include:

  • ORA-13349 - polygon boundary crosses itself
  • ORA-13351 - two or more rings of a complex polygon overlap
  • ORA-13356 - adjacent points in a geometry
  • ORA-13367 - wrong orientation of exterior/interior rings

Validate and try to rectify a layer (table and geometry column):

drop table val_results;
create table val_results (sdo_rowid ROWID, result VARCHAR2(2000));
call SDO_GEOM.VALIDATE_LAYER_WITH_CONTEXT('GEOTABLE1','SHAPE','VAL_RESULTS');

SELECT count(*)-1 as numerrors from val_results;

-- try to rectify errors
update GEOTABLE1
  set shape=SDO_UTIL.RECTIFY_GEOMETRY(shape, 0.00005)
  where rowid in (select sdo_rowid from val_results);

truncate table val_results;
call SDO_GEOM.VALIDATE_LAYER_WITH_CONTEXT('GEOTABLE1','SHAPE','VAL_RESULTS');

SELECT count(*)-1 as numerrors from val_results;

Validate one geometry at a time:

select SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(shape, 0.00005)
  from GEOTABLE1
  ;