Oracle创建空间字段、空间索引

一、创建点空间

--创建表
CREATE TABLE my_shape_test (
  id NUMBER PRIMARY KEY,
  name VARCHAR2(32),
  location SDO_GEOMETRY,
  x84 number(20,10),
  y84 number(20,10)
  );
--插入两条数据
INSERT INTO my_shape_test VALUES(
  1,
  'point1',
  SDO_GEOMETRY(
    2001,
    4326,
    SDO_POINT_TYPE(
        115.60843803,
        32.1681994271,
        0),
    NULL,
    NULL),
    115.60843803,
    32.1681994271
);
INSERT INTO my_shape_test VALUES(
  2,
  'point2',
 SDO_GEOMETRY(
    2001,
    4326,
    SDO_POINT_TYPE(
        115.6094495600,
        32.1684263561,
        0),
    NULL,
    NULL),
    115.6094495600,
    32.1684263561
);
---------------------------------------------------------------------------
-- UPDATE METADATA VIEW -- 更新元数据视图
---------------------------------------------------------------------------
-- Update the USER_SDO_GEOM_METADATA view. This is required
-- before the spatial index can be created. Do this only once for each
-- layer (that is, table-column combination; here: COLA_MARKETS and SHAPE).

INSERT INTO user_sdo_geom_metadata
    (TABLE_NAME,
     COLUMN_NAME,
     DIMINFO,
     SRID)
  VALUES (
  'my_shape_test',
  'location',
  SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X',-180,180,0.005),SDO_DIM_ELEMENT('Y',-90,90,0.005)),
   4326   -- SRID
);

-------------------------------------------------------------------
-- CREATE THE SPATIAL INDEX --创建空间索引
-------------------------------------------------------------------
-- Preceding statement created an R-tree index.

CREATE INDEX my_shape_test_idx
   ON my_shape_test(location)
   INDEXTYPE IS MDSYS.SPATIAL_INDEX;

二、创建面空间

官方示例

三、其他

1.开发注意事项:

  1. geoserver lib中添加 orai18n-12.1.0.2.0.jar
  2. Oracle数据库表空间名不能小写(坑1)
  3. 代码中视图sql表名需要大写(坑3)
  4. 代码中视图设置坐标系时,字段名得大写 -> final VTGeometryEncoder vtGeom = new VTGeometryEncoder(“LOCATION”, “Point”, “4326”); (坑2)

2.参考链接

参考1

参考2

参考3

你可能感兴趣的:(Oracle,Java,oracle,数据库,sql)