Creating a spatial index on oracle

二次信任 提交于 2021-01-28 02:27:39

问题


I have a table 'floating_options', and I want to create a spatial index on a column 'area_geo' (which is a sdo_geometry column, with two rows of data that appear as expected when I select * from floating_options).

I have used the following code but I am receiving the error below. I would be very grateful for any help! Thanks!

CREATE INDEX area_idx ON floating_options(area_geo)
   INDEXTYPE IS MDSYS.SPATIAL_INDEX;


Error report -
SQL Error: ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13203: failed to read USER_SDO_GEOM_METADATA view
ORA-13203: failed to read USER_SDO_GEOM_METADATA view
ORA-06512: at "MDSYS.SDO_INDEX_METHOD_10I", line 10
29855. 00000 -  "error occurred in the execution of ODCIINDEXCREATE routine"
*Cause:    Failed to successfully execute the ODCIIndexCreate routine.
*Action:   Check to see if the routine has been coded correctly.

回答1:


Before indexing the table you should have it 'spatially enabled'.
Try to check if it is shown in spatial metadata:

SELECT * FROM USER_SDO_GEOM_METADATA
    WHERE TABLE_NAME = UPPER('floating_options')
      AND COLUMN_NAME = UPPER('area_geo');

If there are no results - then a couple of options are available.
One dirty way - insert data directly

INSERT INTO USER_SDO_GEOM_METADATA
VALUES (UPPER('floating_options'),UPPER('area_geo'),
        mdsys.SDO_DIM_ARRAY(
             mdsys.SDO_DIM_ELEMENT('Easting', <lowest_x>, <highest_x>, <x_tolerance>),
             mdsys.SDO_DIM_ELEMENT('Northing', <lowest_y>, <highest_y>, <y_tolerance>)
        ), <SRID>);

Please change the < placeholders > accordingly

Please take a look also at https://community.oracle.com/thread/836452?tstart=0 or http://gerardnico.com/wiki/oracle_spatial/metadata




回答2:


The following should also be considered: Oracle has case-sensitive names see this post.

The next problem with the "intelligent" guys of Oracle is, that their USER_SDO_GEOM_METADATA table does not support lower-case names (at least in 11g).

So with for a table definition like this

CREATE TABLE "cola_markets" (
  "mkt_id" NUMBER PRIMARY KEY,
  "name" VARCHAR2(32),
  "shape" SDO_GEOMETRY);

you cannot create a spatial index.

When inserting the metadata

INSERT INTO USER_SDO_GEOM_METADATA 
  VALUES (
  'cola_markets',
  'shape',
  SDO_DIM_ARRAY(   -- 20X20 grid
    SDO_DIM_ELEMENT('X', 0, 20, 0.005),
    SDO_DIM_ELEMENT('Y', 0, 20, 0.005)
     ),
  NULL   -- SRID
);

the names are converted to upper-case.

If you then create the index

CREATE INDEX cola_spatial_idx
   ON "cola_markets"("shape")
   INDEXTYPE IS MDSYS.SPATIAL_INDEX;

You will get the error mentioned above

ORA-13203: failed to read USER_SDO_GEOM_METADATA view

because it cannot find the lower-case names in the metadata table.

Conclusion:

  • use only upper-case names (or no double quotes)
  • Orcale guys are blockheads



回答3:


This is a solution:

INSERT INTO user_sdo_geom_metadata 
VALUES ('target_table', 'SHAPE', sdo_dim_array(sdo_dim_element('x',-180,180,.005),sdo_dim_element('y',-90,90,.005)), 4326);

create index new_index_table on target_table(SHAPE) indextype is mdsys.spatial_index;

It should work.



来源:https://stackoverflow.com/questions/36624479/creating-a-spatial-index-on-oracle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!