DB2-specific Geography Tasks

Description

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 DB2, the default is 1003.

 Creating and Dropping Tables with Geometry Columns

  •  Creating

    CREATE TABLE GeogTest
    (
    KeyValue	VARCHAR(25) NOT NULL,
    Location	DB2GSE.ST_GEOMETRY NOT NULL,
    PRIMARY KEY (KeyValue))
  •  Dropping

    DROP TABLE GeogTest

 Inserting Location Data Values

  •  Portable

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

    INSERT INTO GeogTest  (KeyValue, Location) 
        VALUES ('Item1', DB2GSE.ST_Point(
        CAST( - 70 AS DOUBLE), CAST(42 AS DOUBLE), CAST(:SRID AS INTEGER)))

 Inserting Line Data Values

  •  Portable

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

    INSERT INTO GeogTest  (KeyValue, Location) 
        VALUES ('Item2', DB2GSE.ST_Geometry(
        'LINESTRING(' || CAST( - 70 as VARCHAR(50)) || ' ' || 
        CAST(42 as VARCHAR(50)) || ', ' || 
        CAST( - 70 as VARCHAR(50)) || ' ' || 
        CAST(38 as VARCHAR(50)) || ')', :SRID))

 Inserting Polygon Data Values

  •  Portable

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

    INSERT INTO GeogTest  (KeyValue, Location) 
       VALUES ('Item3', DB2GSE.ST_Geometry('POLYGON((' 
       || CAST( - 70 as VARCHAR(50))
       || ' ' || CAST(42 as VARCHAR(50)) || ', ' || CAST( - 70 as VARCHAR(50))
       || ' ' || CAST(32 as VARCHAR(50)) || ', ' || CAST( - 60 as VARCHAR(50))
       || ' ' || CAST(32 as VARCHAR(50)) || ', ' || CAST( - 60 as VARCHAR(50))
       || ' ' || CAST(42 as VARCHAR(50)) || ', ' || CAST( - 70 as VARCHAR(50))
       || ' ' || CAST(42 as VARCHAR(50)) || '))', :SRID))

See Also