We are going to use oracle as gis database server. We will use AutoCAD Map 3D for creating editing and updating gis data in the database. As database client we will use sqlplusw and sqldeveloper. We will also use GeoRaptor for viewing geometry data in sqldeveloper.
Creating a table with geometry field:
create table kavel(
id varchar2(30 BYTE) PRIMARY KEY,
description varchar2(30 BYTE),
type varchar2(30 BYTE),
geom MDSYS.SDO_GEOMETRY
)
A spatial table must have a primary key
All Oracle gis database stuff (tables, views, types,functions) are stored under MDSYS user account. So to use SDO_GEOMETRY we need ot use MDSYS.SDO_GEOMETRY.
Add Meta data in to user_sdo_geom_metadata table:
Then we need to add an entry in the user_sdo_geom_metadata table. It has the following columns
TABLE_NAME : Name of the table.
COLUMN_NAME : Name of column.
DIMINFO : Dimention of the geometry objects.(???)
SRID : Special reference ID. For WGS84 we use SRID 4326. (??? Does oracle uses its own SRID ???)
DELETE FROM user_sdo_geom_metadata
WHERE table_name=’kavel”;
INSERT INTO user_sdo_geom_metadata VALUES
(‘KAVEL’,'GEOM’,
MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT(‘LONGITUDE’, -180, 180,.5),
MDSYS.SDO_DIM_ELEMENT(‘LATITUDE’, -90, 90,.5)),
4326
);
- Note: You will only need to populate the metadata for the city_geometries table if it was exported from the source system prior to the table being spatially indexed. If a spatial table is exported while the spatial index exists then the import will populate the metadata and create the spatial index.
- USER_SDO_GEOM_METADATA is used by Oracle Spatial to define the valid values for a spatial tables coordinate system. You must have at least 2 dimensions defined for each spatial table. In this case, we are defining a geodetic coordinate system containing a longitude and latitude value. We also identify the coordinate system by specifying the SRID value of 4326 (WGS84). If the metadata table identifies a SRID for the spatial table then each record with a populated geometry must also specify the same SRID in the spatial object.
- You must have a metadata entry for all tables containing a spatial geometry column. If the metadata entry does not exist, then Oracle will generate errors whenever you try to index the spatial column or utilize any of the spatial operators.
- The SDO_DIM_ELEMENT specifies the dimensions name, lower boundary, upper boundary and tolerance. Tolerance is used to determine when two points are close enough to be considered the same point. For geodetic coordinate systems, like the one we define above, the tolerance is specified in meters. In this case, we are using a tolerance of 1/2 of a meter.
Add Index to geometry column:
Now we have to create a index on the geometry column (???)
CREATE INDEX kavel_geometry_idx ON kavel(geom)
INDEXTYPE IS MDSYS.SPATIAL_INDEX;