Querying Spatial Data: Oracle Query Model
This page
is a summary of chapter four in the Oracle8i Spatial User's Guide and Reference
versions 8.1.5 and 8.1.6. For a more detailed explanation and more
examples see these reference guides.
The Oracle Query Model:
To query spatial data, each
geometry must be represented in tiles. Tiles are fully tesselated
regions defined in a total specified area. Each geometry is contained
in one or more tiles, so the tiles can represent the approximate location
of each geometry. Tiles are important for quick and accurate selection
of geometries which are queried spatially or spatial joined because
tiles contain a subset of all the geometries within the total area defined.
Therefore, only a subset of the geometries have to be manipulated.
Oracle uses a primary filter to find the tiles for all geometries
used in a specific spatial query or join. These tiles are then used
in a secondary filter to find the exact result for the spatial query
or spatial join. By using this two-tier query model Oracle
can quickly extract relavant tiles (which contain the geometries) and
then compute the complex spatial query or join only on the geometries contained
in these tiles.
-
Primary Filter: The primary
filter permits fast selection of candidate records to pass along to the
secondary filter. The primary filter uses geometry approximations
(or index tiles) to reduce computaional complexity and is considered a
lower cost filter.
-
Secondary Filter: The secondary
filter applies exact computaional geometry to the result set of the primary
filter. These exact computaions yield the exact answer to a
query. The secondary filter operations are computationally more expensive,
but they are applied only to the relatively small result set returned from
the primary filter.
In order to define a spatial query in Oracle three parameters
must be defined: two geometries used in the spatial query or join and parameters
defining the type of spatial query or join.
-
Geometry1 is a column of type SDO_GEOMETRY in a table.
This geometry must be spatially indexed (index tiles)
-
Geometry2 is an object of type SDO_GEOMETY. It
can be in a table (spatially indexed) or it can be user defined (query
window)
-
Params is a quoted string of keyword value pairs that
determine the behavior of the spatial query or join.
Examples:
Tessellated Layer with Multiple Objects
Figure 4-1 Oracle8i Spatial User's Guide and Reference: 4-2
This example shows a tessellated layer with
equal sized tile. The tile are signified by T# and the geometry object
are represented by a number. The spatial indexing would be represented
as followed: Geometry 1013 is in tiles T1, T2, T3, and T4; Geometry
501 is in tiles T2 and T7; Geometry 12 is in T3 and T4; Geomety 1243
is in tiles T3, T4, T5, and T6; and Geometry 61 is in tiles T8 and T9.
This next example shows a typical spatial query,
Requesting all objects that lie within a defined fence or query window.
Tessellated Layer with a Query Window
Figure 4-2 Oracle8i Spatial User's Guide and Reference: 4-2
To find the objects that lie within the defined query
window the primary and secondary filters will be used
Primary Filter
-
Oracle will first find the tiles which overlap the window.
In this example the window is located in tiles T1, T2, T3, and T4.
-
Oracle will then select the objects which are located
in these tiles. Objects 1013, 501, 12, and 1243 are located in these
four tiles.
Secondary Filter
-
The secondary filter will then take the Objects
selected in the Primary Filter and find the exact result: all objects within
the query window (1013 and 1243).