OCI driver: loading into Oracle fails with ORA-29855 and ORA-13375
|Reported by:||agodfrin||Owned by:||warmerdam|
When loading a polygon layer into Oracle, and that layer contains multi-polygons, the creation of the spatial index fails with:
ERROR 1: ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine ORA-13249: internal error in Spatial index: [mdidxrbd] ORA-13249: Error in Spatial index: index build failed ORA-13249: Error in spatial index: [mdrcrtxfergm] ORA-13249: Error in spatial index: [mdpridxtxfergm] ORA-13200: internal error [ROWID:AAAaU8AAGAAANcwAAF] in spatial indexing. ORA-13206: internal error [Invalid geometry; check ROWID] while creating the spatial index ORA-13375: the layer is of type  while geometry inserted has type  ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 10
in CREATE INDEX "FRA_ADM5_IDX" ON FRA_ADM5("GEOMETRY") INDEXTYPE IS MDSYS.SPATIAL_INDEX PARAMETERS( 'LAYER_GTYPE=POLYGON' )
The reason is that the OCI driver wants to create the index with the LAYER_GTYPE=POLYGON parameter. This parameter restricts the index to only support single-element polygons. The presence of any multi-polygon in the input prevents the index to be created. That parameter is essentially used as a way to restrict a table in Oracle to geometries of a certain kind (points, lines, polygons, surfaces, solids ...). The parameter can be set to further restrict to single-instance geometries. For example POLYGON only allows single-element polygons (but they can contain any number of holes). MULTIPOLYGON allows any kind of polygon (single or multi-element).
Since GDAL 2.0 a new CO parameter ADD_LAYER_GTYPE controls whether LAYER_GTYPE should be added to the index creation. The trouble is that the default is "-co ADD_LAYER_GTYPE=YES".
This bug is critical. It impacts the loading of spatial data from any format into Oracle, especially for data such as natural features (coat lines with islands) or administrative boundaries that contain multi-polygons: existing loading scripts now fail when a user switches to ogr 2.0.
1) Disable the use of the LAYER_GTYPE index parameter by adding this to the ogr2ogr command:
then redo the load, or
2) Drop and recreate the spatial index
There are several ways to correct this issue:
1) Change the default of -co ADD_LAYER_GTYPE to NO instead of YES.
2) Always provide it in the plural: LAYER_GTYPE=MULTIPOLYGON (or MULTILINE, or MULTIPOINT etc). This still restricts a table to contains only polygons (or lines or points), but allows the objects to be single or multi-polygons.
3) Let the user explicitly specify the parameter setting (via a -CO LAYER_GTYPE= parameter)