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

Querying Spatial Data



This chapter describes how the structures of a Spatial Data Option layer are used to resolve spatial queries and spatial joins. For the sake of clarity, the examples assume that all of the tiles covering all of the elements in a layer are the same size, although this is not required by the Spatial Data Option.

3.1 Query Model

The Spatial Data Option uses a "2-tier" query model to resolve spatial queries and spatial joins. The term is used to indicate that two distinct operations are performed in order to resolve queries. The output of both operations yield the exact result set.

The two operations are referred to as primary and secondary filter operations.

The following figure graphically illustrates the relationship between the primary and secondary filters:

Figure 3¯1 Query Model

Spatial Data Option uses a spatial index to implement the primary filter. This is described in detail in following sections.

A function used as a secondary filter is SDO_GEOM.RELATE() which determines the spatial relationship between two given geometries, such as whether they touch, overlap, or if one is inside the other.

3.2 Spatial Data Model

An important concept in the spatial data model is that each element is represented in the <layer>_SDOINDEX table by a set of exclusive and exhaustive tiles. This means that the tiles fully cover the object (exhaustive) and that no tiles overlap each other (exclusive).

Consider the following layer containing several objects. Each object is labeled with its SDO_GID. The relevant cover tiles are labeled with `Tn'.

Figure 3¯2 Tessellated Layer With Multiple Objects

The Spatial Data Option layer tables would have the following information stored in them for these geometries:

Table 3¯1 <layer>_SDOLAYER
SDO_ORDCNT (NUMBER)
4

Table 3¯2 <layer>_SDOGEOM
SDO_GID (NUMBER)

SDO_ESEQ (NUMBER)

SDO_ETYPE (NUMBER)

SDO_SEQ (NUMBER)

SDO_X1 (NUMBER)

SDO_Y1 (NUMBER)

SDO_X2 (NUMBER)

SDO_Y2 (NUMBER)

1013

0

3

0

P1(X)

P1(Y)

P2(X)

P2(Y)

1013

0

3

1

P2(X)

P2(Y)

P3(X)

P3(Y)

1013

0

3

2

P3(X)

P3(X)

P4(X)

P4(Y)

1013

0

3

3

P4(X)

P4(Y)

P5(X)

P5(Y)

1013

0

3

4

P5(X)

P5(Y)

P6(X)

P6(Y)

1013

0

3

5

P6(X)

P6(Y)

P7(X)

P7(Y)

1013

0

3

6

P7(X)

P7(Y)

P8(X)

P8(Y)

1013

0

3

7

P8(X)

P8(Y)

P1(X)

P1(Y)

1013

1

3

0

G1(X)

G1(Y)

G2(X)

G2(Y)

1013

1

3

1

G2(X)

G2(Y)

G3(X)

G3(Y)

1013

1

3

2

G3(X)

G3(Y)

G4(X)

G4(Y)

1013

1

3

3

G4(X)

G4(Y)

G1(X)

G1(Y)

501

0

3

0

A1(X)

A1(Y)

A2(X)

A2(Y)

501

0

3

1

A2(X)

A2(Y)

A3(X)

A3(Y)

501

0

3

2

A3(X)

A3(Y)

A4(X)

A4(Y)

501

0

3

3

A4(X)

A4(Y)

A1(X)

A1(Y)

1243

0

3

0

B1(X)

B1(Y)

B2(X)

B2(Y)

1243

0

3

1

B2(Y)

B2(Y)

B3(X)

B3(Y)

1243

0

3

2

B3(X)

B3(Y)

B1(X)

B1(Y)

12

0

2

0

D1(X)

D1(Y)

D2(X)

D2(Y)

61

0

3

0

C1(X)

C1(Y)

C2(X)

C2(Y)

61

0

3

1

C2(X)

C2(Y)

C3(X)

C3(Y)

61

0

3

2

C3(X)

C3(Y)

C4(X)

C4(Y)

61

0

3

3

C4(X)

C4(Y)

C5(X)

C5(Y)

61

0

3

4

C5(X)

C5(Y)

C1(X)

C1(Y)

Table 3¯3 <layer>_SDOINDEX
SDO_GID (NUMBER) SDO_CODE <RAW> SDO_MAXCODE <RAW>
1013

T1

T1FFF...F

1013

T2

T2FFF...F

1013

T3

T3FFF...F

501

T2

T2FFF...F

501

T5

T5FFF...F

1243

T2

T2FFF...F

1243

T3

T3FFF...F

1243

T4

T4FFF...F

12

T3

T3FFF...F

12

T4

T4FFF...F

61

T6

T6FFF...F

61

T7

T7FFF...F

3.3 Spatial Query

A typical spatial query is to request all objects that lie within a defined fence or window. A query window is defined in Figure 3-3 by the dotted line box.

Figure 3¯3 Tessellated Layer With a Query Fence

3.3.1 Primary Filter

To resolve this window query, build a layer for the query fence if it is not already defined:

SQL> EXECUTE SDO_WINDOW.CREATE_WINDOW_LAYER (fencelayer, DIMNUM1, LB1, UB1, 
TOLERANCE1, DIMNAME1, DIMNUM2, LB2, UB2, TOLERANCE2, DIMNAME2)


Next, insert the ordinates for the query fence into the layer tables:

SQL> EXECUTE DBMS_OUTPUT.PUTLINE(TO_CHAR(SDO_WINDOW.BUILD_WINDOW (comp_user, 
fencelayer, SDO_ETYPE, NUM_TILES, X1, Y1, X2, Y2, X3, Y3, X4, Y4, X1, Y1)));


Now you can construct a query that joins the index of the query window to the appropriate layer index and determines all elements that have these tiles in common. The following SQL query form is used: 

SELECT DISTINCT A.SDO_GID, B.SDO_GID
FROM <layer1>_SDOINDEX A, <fencelayer>_SDOINDEX B
WHERE A.SDO_CODE = B.SDO_CODE
and B.SDO_GID = {GID returned from SDO_WINDOW.BUILD_WINDOW};
The result set of this query is the PRIMARY filter set. In this case, the result set is:

 { 1013,501,1243,12 }

3.3.2 Secondary Filter

The SECONDARY filter uses performs exact geometry calculations of the tiles selected by the PRIMARY filter. The following example shows the first and second pass filters:

SELECT SDO_GID
   FROM (
          SELECT DISTINCT A.SDO_GID
             FROM <layer1>_SDO_INDEX A
                  <fence'>_SDO_INDEX B
             WHERE A.SDO_CODE = B.SDO_CODE         
         )
   WHERE SDO_GEOM.INTERACT('<layer1>', GID1, '<fence>', 1) = 'TRUE';
                  


This query would return all the geometry id's that lie within or overlap the window. In this example the results of the second pass filter would be:

{1243,1013}

3.4 Spatial Join

A spatial join is the same as a regular join except that the predicate involves a spatial operator. In the Spatial Data Option, a spatial join takes place between two layers; specifically, two <layer>_SDOINDEX tables are joined.

Example 3¯1

The PRIMARY filter would identify pairs of PARK GID's and HIGHWAY GID's that cross in the index. The query that performs the PRIMARY filter join is:

SELECT DISTINCT A.SDO_GID, B.SDO_GID 
FROM PARKS_SDOINDEX A, HIGHWAYS_SDOINDEX B
WHERE A.SDO_CODE BETWEEN B.SDO_CODE AND B.SDO_MAXCODE
OR B.SDO_CODE BETWEEN A.SDO_CODE AND A.SDO_MAXCODE;
The result set of the PRIMARY filter must be passed through the SECONDARY filter to get the exact set of PARKS/HIGHWAYS GID pairs that cross. The query that performs the SECONDARY filtering is:

Suppose the original query had asked, "which 4-lane highways cross national parks." You could modify the above SQL statement to join back to the HIGHWAYS table where HIGHWAYS.WIDTH=4. This combination of spatial and relational attributes in a single query is one of the primary reasons for using the Spatial Data Option.



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