Oracle7 Spatial Data Option User's Guide and Reference Go to Product Documentation Library
Library
Go to books for this product
Product
Go to Contents for this book
Contents
Go to Index
Index



Go to previous file in sequence Go to next file in sequence

Loading Spatial Data



This chapter describes how to load spatial data into a database, including storing the data in a table and creating a spatial index for it.

2.1 Load Model

There are two steps involved in loading raw data into a spatial database such that it can be queried efficiently:

  1. Loading the data into spatial tables.

  2. Creating or updating the index on the spatial tables.

Table 2-1 shows the format of the tables needed to store and index spatial data.

Figure 2¯1 Geometry Layer Tables

2.2 Loading Process

The process of loading data can be classified into two categories:

2.2.1 Bulk Loading

Bulk loading can be used to import large amounts of legacy or raw data into a spatial database. Bulk loading is accomplished using the SQL*Loader1.

Example 2¯1

     		          geometry rows:    GID, ESEQ, ETYPE, SEQ, LON1, LAT1, LON2, LAT2

Example 2¯2

Example 2¯3

2.2.2 Transactional Insert Using SQL

Spatial Data Option uses standard Oracle7 tables which can be accessed or loaded with standard SQL syntax. The following example loads data for a geometry (GID 17) consisting of a polygon with five sides that contains both a hole and point. Notice that the first coordinate of the polygon (5, 20) is repeated at the end to close the polygon.

INSERT INTO SAMPLE_SDOGEOM (SDO_GID, SDO_ESEQ, SDO_ETYPE, SDO_SEQ, 
                              SDO_X1, SDO_Y1, SDO_X2, SDO_Y2, SDO_X3, 
                              SDO_Y3, SDO_X4, SDO_Y4, SDO_X5, SDO_Y5)
  VALUES (17, 0, 3, 0, 5, 20, 5, 30, 10, 30, 10, 20, 5, 20);

   -- hole 
INSERT INTO SAMPLE_SDOGEOM (SDO_GID, SDO_ESEQ, SDO_ETYPE, SDO_SEQ, 
                              SDO_X1, SDO_Y1, SDO_X2, SDO_Y2, SDO_X3, 
                              SDO_Y3, SDO_X4, SDO_Y4, SDO_X5, SDO_Y5)
  VALUES (17, 1, 3, 0, 8, 21, 8, 24, 9, 24, 9, 21, 8, 21);

   -- point
INSERT INTO SAMPLE_SDOGEOM (SDO_GID, SDO_ESEQ, SDO_ETYPE, SDO_SEQ, 
                              SDO_X1, SDO_Y1)
  VALUES (17, 6, 1, 0, 9, 29);


The SQL INSERT statement inserts one row of data per call.   In the previous example, the table had enough columns to store the polygon in a single row. However, if your table had fewer columns (or your polygon had more points), you would have to break the insert into multiple lines to match the table structure. Repeat the SDO_GID, SDO_ESEQ, and SDO_ETYPE, and increment the SDO_SEQ for each line as follows: 

INSERT INTO SAMPLE2_SDOGEOM (SDO_GID, SDO_ESEQ, SDO_ETYPE, SDO_SEQ, 
                              SDO_X1, SDO_Y1, SDO_X2, SDO_Y2, SDO_X3,
                              SDO_Y3, SDO_X4, SDO_Y4, SDO_X5, SDO_Y5)
  VALUES (18, 0, 3, 0, 1, 15, 1, 16, 2, 17, 3, 17, 4, 18);

INSERT INTO SAMPLE2_SDOGEOM (SDO_GID, SDO_ESEQ, SDO_ETYPE, SDO_SEQ, 
                              SDO_X1, SDO_Y1, SDO_X2, SDO_Y2, SDO_X3,
                              SDO_Y3, SDO_X4, SDO_Y4, SDO_X5, SDO_Y5)
  VALUES (18, 0, 3, 1, 4, 18, 5, 18, 6, 19, 7, 18, 6, 17);

INSERT INTO SAMPLE2_SDOGEOM (SDO_GID, SDO_ESEQ, SDO_ETYPE, SDO_SEQ, 
                              SDO_X1, SDO_Y1, SDO_X2, SDO_Y2, SDO_X3,
                              SDO_Y3, SDO_X4, SDO_Y4, SDO_X5, SDO_Y5)
  VALUES (18, 0, 3, 2, 6, 17, 7, 16, 7, 15, 6, 14, 7, 13);

INSERT INTO SAMPLE2_SDOGEOM (SDO_GID, SDO_ESEQ, SDO_ETYPE, SDO_SEQ, 
                              SDO_X1, SDO_Y1, SDO_X2, SDO_Y2, SDO_X3,
                              SDO_Y3, SDO_X4, SDO_Y4, SDO_X5, SDO_Y5)
  VALUES (18, 0, 3, 3, 7, 13, 6, 12, 5, 13, 4, 13, 3, 14);

INSERT INTO SAMPLE2_SDOGEOM (SDO_GID, SDO_ESEQ, SDO_ETYPE, SDO_SEQ, 
                              SDO_X1, SDO_Y1, SDO_X2, SDO_Y2, SDO_X3, SDO_Y3)
  VALUES (18, 0, 3, 4, 3, 14, 2, 14, 1, 15);

2.2.3 Transactional Insert Using Spatial Geometry Functions

Spatial Data Option provides two functions to facilitate inserting data into spatial tables. A benefit to using these functions is that the issue of row-wrapping when loading elements with multiple points is handled automatically by these functions.

There are two steps to incrementally add data to the spatial tables:

  1. Initialize the element that needs to be stored. Note that this process does not fill in any coordinate information for the element. Two parameters are passed to the SDO_GEOM.INIT_ELEMENT() function which initializes the element:

    The SDO_GEOM.INIT_ELEMENT() function returns the sequence number of the element in the geometry. This sequence number is required as a parameter to the SDO_GEOM.ADD_NODES() procedure.

  2. Fill in the coordinate information for the element using the SDO_GEOM.ADD_NODES() procedure. This procedure takes the following parameters:

Example 2¯4

Example 2¯5

Figure 2¯2 Polygon With a Hole

2.3 Index Creation

Once data has been loaded into the spatial tables through either bulk or transactional loading, a spatial index needs to be created on the tables for efficient access to the data.

Create a table called <layername>_SDOINDEX with the following structure:

(SDO_GID integer, SDO_CODE raw(254))

For a bulk load, you can call the SDO_ADMIN.POPULATE_INDEX_FIXED() procedure once to tessellate the geometry table and add the generated tiles to the spatial index table. The arguments to this procedure are the name of the layer, a factor for creating fixed-size tiles that the geometry should be tessellated into, and a flag to determine if the entire geometry table should be tessellated or just the objects that do not have corresponding entries in the spatial index table. See Chapter 5, "Administrative Procedures" for a complete description of the SDO_ADMIN.POPULATE_INDEX_FIXED() procedure.

If data is updated in or deleted from a specific geometry table, you can call SDO_ADMIN.UPDATE_INDEX_FIXED() to update the index for the designated GID. The arguments to this procedure are the name of the layer, the GID of the designated geometry, the size of tiles the geometry should be tessellated into, and a replace flag. The replace flag signals whether or not to delete any existing tiles for the geometry prior to tessellating.

2.3.1 Indexing With Fixed-Size Tiles

Spatial Data Option uses two different tessellation schemes for creating cover tiles for a geometry. Most of the examples in this manual describe indexing with fixed-size tiles because that is generally the most efficient for most cases. However, in some cases an application might call for variable-size tiles. Tessellating the geometry into fixed-size tiles might have benefits related to the type of data being stored, such as using tiles sized to represent one-acre farm plots, city blocks, or individual pixels on a display.

The domain of the HHCODE used for indexing is defined by the upper and lower boundaries of each dimension stored in the <layername>_SDODIM table. A typical domain in a GIS application would be -90 to 90 degrees for latitude, and -180 to 180 degrees for longitude.

Figure 2¯3 Fixed-Size Tiling

To generate fixed-size tiles, use the SDO_ADMIN.POPULATE_INDEX_FIXED() procedure and pass it the number of times the layer should be tessellated. For example, setting the tile_size parameter to 1 would specify one subdivision. Each tile would be 180 degrees by 90 degrees as shown in Figure 2-4:

Figure 2¯4 Fixed-Size Tiling at Level 1

The formula for the number of fixed-size tiles is 4n where n is the tile_size parameter passed to the SDO_ADMIN.POPULATE_INDEX_FIXED() procedure. Figure 2-5 shows fixed-size tiling at level 2. In this example, each tile is 90 degrees by 45 degrees.

Figure 2¯5 Fixed-Size Tiling at Level 2

Example 2¯6



Go to previous file in sequence Go to next file in sequence
Prev Next
Oracle
Copyright © 1996 Oracle Corporation.
All Rights Reserved.
Go to Product Documentation Library
Library
Go to books for this product
Product
Go to Contents for this book
Contents
Go to Index
Index