Oracle-specific Geography Tasks

Description

Oracle examples for creating and dropping tables with geometry columns, inserting location data values, inserting line data values, and inserting polygon data values.

In the samples below, :SRID indicates the optional spatial reference identifier argument. For Oracle, the default is 4326.
Alpha Anywhere's implementation is complete for Oracle Spatial. We support Oracle Locator except for Well-Known-Text and Well-Known-Binary formats. This is a limitation of Oracle Express, as it does not include the Java Virtual Machine that processes these formats.

Creating and Dropping Tables with Geometry Columns 

Creating a table with geometry columns:

CREATE TABLE GeogTest
(
KeyValue	varchar2(25)	NOT NULL,
Location	SDO_GEOMETRY	NOT NULL,
PRIMARY KEY (KeyValue))

INSERT INTO USER_SDO_GEOM_METADATA VALUES('GeogTest','Location', 
MDSYS.SDO_DIM_ARRAY(
MDSYS.SDO_DIM_ELEMENT('X', -180, 180, 0.000000005), 
MDSYS.SDO_DIM_ELEMENT('Y', -90, 90, 0.000000005)), 4326))

CREATE INDEX GEOGTEST_A5Spatial1 on GEOGTEST(Location) 
indextype is mdsys.spatial_index

Dropping a table:

DELETE FROM USER_SDO_GEOM_METADATA 
    WHERE TABLE_NAME = 'GEOGTEST' 
    AND COLUMN_NAME = 'LOCATION'

DROP TABLE GeogTest

Inserting Location Data Values 

Inserting location data using Portable SQL Syntax:

INSERT INTO GeogTest (KeyValue, Location) 
    values('Item1', GeogCreateLocation(-70, 42, :SRID))

Inserting location data using Native syntax:

INSERT INTO GeogTest  (KeyValue, Location) 
    VALUES ('Item1', SDO_Geometry('POINT(' || 
    CAST( - 70 as VARCHAR(1024)) || ' ' || 
    CAST(42 as VARCHAR(1024)) || ')', :SRID))

Inserting Line Data Values 

Inserting line data values using Portable SQL Syntax:

INSERT INTO GeogTest (KeyValue, Location) 
    values('Item2', GeogCreateLine(-70, 42, -70, 38, :SRID))

Inserting line data values using Native SQL Syntax:

INSERT INTO GeogTest  (KeyValue, Location) 
    VALUES ('Item2', SDO_Geometry('LINESTRING(' || 
    CAST( - 70 as VARCHAR(1024)) || ' ' || 
    CAST(42 as VARCHAR(1024)) || ', ' || 
    CAST( - 70 as VARCHAR(1024)) || ' ' || 
    CAST(38 as VARCHAR(1024)) || ')', :SRID))

Inserting Polygon Data Values 

Inserting polygon values using Portable SQL Syntax:

INSERT INTO GeogTest (KeyValue, Location) 
    values('Item3', GeogCreatePolygon(-70, 42, -70, 32, -60, 
              32, -60, 42, -70, 42, :SRID))

Inserting polygon values using Native SQL Syntax:

INSERT INTO GeogTest  (KeyValue, Location) 
    VALUES ('Item3', SDO_Geometry('POLYGON((' || 
    CAST( - 70 as VARCHAR(1024)) || ' ' || 
    CAST(42 as VARCHAR(1024)) || ', ' || 
    CAST( - 70 as VARCHAR(1024)) || ' ' || 
    CAST(32 as VARCHAR(1024)) || ', ' || 
    CAST( - 60 as VARCHAR(1024)) || ' ' || 
    CAST(32 as VARCHAR(1024)) || ', ' || 
    CAST( - 60 as VARCHAR(1024)) || ' ' || 
    CAST(42 as VARCHAR(1024)) || ', ' || 
    CAST( - 70 as VARCHAR(1024)) || ' ' || 
    CAST(42 as VARCHAR(1024)) || '))', :SRID))

See Also