Oracle8 Spatial Cartridge: User's Guide and Reference
Oracle8 Spatial Cartridge: User's Guide and Reference
Release 8.0.5
May 1998
Part No. A53264-03
Oracle8 Spatial Cartridge User’s Guide and Reference
Release 8.0.5
The programs are not intended for use in any nuclear, aviation, mass transit, medical, or other inher-
ently dangerous applications. It shall be licensee's responsibility to take all appropriate fail-safe, back
up, redundancy and other measures to ensure the safe use of such applications if the Programs are
used for such purposes, and Oracle disclaims liability for any damages caused by such use of the Pro-
grams.
This Program contains proprietary information of Oracle Corporation; it is provided under a license
agreement containing restrictions on use and disclosure and is also protected by copyright patent and
other intellectual property law. Reverse engineering of the software is prohibited.
The information contained in this document is subject to change without notice. If you find any problems
in the documentation, please report them to us in writing. Oracle Corporation does not warrant that this
document is error free.
If this Program is delivered to a U.S. Government Agency of the Department of Defense, then it is deliv-
ered with Restricted Rights and the following legend is applicable:
Restricted Rights Legend Programs delivered subject to the DOD FAR Supplement are 'commercial
computer software' and use, duplication and disclosure of the Programs shall be subject to the licensing
restrictions set forth in the applicable Oracle license agreement. Otherwise, Programs delivered subject to
the Federal Acquisition Regulations are 'restricted computer software' and use, duplication and disclo-
sure of the Programs shall be subject to the restrictions in FAR 52..227-14, Rights in Data -- General,
including Alternate III (June 1987). Oracle Corporation, 500 Oracle Parkway, Redwood City, CA 94065.
Oracle, SQL*Forms, SQL*Loader, SQL*Menu, SQL*Net, SQL*Plus, and SQL*Report are registered trade-
marks of Oracle Corporation. Oracle7 and Oracle8 are trademarks of Oracle Corporation.
All other products or company names are used for identification purposes only, and may be trademarks
of their respective owners.
Contents
Preface............................................................................................................................................................ ix
iii
2.3.1 Choosing a Tessellation Algorithm ............................................................................. 2-8
2.3.2 Spatial Indexing with Fixed-Size Tiles........................................................................ 2-9
2.3.3 Spatial Indexing with Variable-Sized Tiles .............................................................. 2-12
5 Administrative Procedures
SDO_ADMIN.POPULATE_INDEX ................................................................................... 5-2
SDO_ADMIN.POPULATE_INDEX_FIXED...................................................................... 5-4
SDO_ADMIN.SDO_CODE_SIZE ....................................................................................... 5-7
SDO_ADMIN.UPDATE_INDEX ........................................................................................ 5-8
SDO_ADMIN.UPDATE_INDEX_FIXED......................................................................... 5-10
SDO_ADMIN.VERIFY_LAYER ........................................................................................ 5-12
Partitioned Point Data Procedures ................................................................................... 5-13
SDO_ADMIN.ALTER_HIGH_WATER_MARK............................................................. 5-14
SDO_ADMIN.DROP_PARTITION_INFO ...................................................................... 5-15
SDO_ADMIN.PARTITION................................................................................................ 5-16
SDO_ADMIN.PROPAGATE_GRANTS .......................................................................... 5-18
SDO_ADMIN.REGISTER_PARTITION_INFO .............................................................. 5-19
SDO_ADMIN.REPARTITION........................................................................................... 5-20
iv
SDO_ADMIN.VERIFY_PARTITIONS ............................................................................. 5-22
6 Tuning Functions
SDO_TUNE.ESTIMATE_TILING_LEVEL ........................................................................ 6-2
SDO_TUNE.EXTENT_OF .................................................................................................... 6-5
7 Geometry Functions
SDO_GEOM.ADD_NODES................................................................................................. 7-2
SDO_GEOM.INIT_ELEMENT ............................................................................................ 7-4
SDO_GEOM.INTERACT ..................................................................................................... 7-5
SDO_GEOM.RELATE........................................................................................................... 7-7
SDO_GEOM.VALIDATE_GEOMETRY........................................................................... 7-10
8 Window Functions
SDO_WINDOW.BUILD_WINDOW .................................................................................. 8-2
SDO_WINDOW.BUILD_WINDOW_FIXED..................................................................... 8-4
SDO_WINDOW.CLEAN_WINDOW................................................................................. 8-6
SDO_WINDOW.CLEANUP_GID ...................................................................................... 8-7
SDO_WINDOW.CREATE_WINDOW_LAYER ............................................................... 8-8
v
A.1.1 Scripts for Spatial Indexing........................................................................................... A-1
A.1.1.1 cr_spatial_index.sql Script ..................................................................................... A-1
A.1.1.2 crlayer.sql Script ...................................................................................................... A-2
A.1.2 Scripts for Partitioned Point Data ................................................................................ A-2
A.1.2.1 altpart.sql Script....................................................................................................... A-3
A.1.2.2 drppart.sql Script..................................................................................................... A-3
A.1.2.3 sdogrant.sql Script................................................................................................... A-3
A.2 Tuning Tips ............................................................................................................................ A-4
A.2.1 Data Modeling ................................................................................................................ A-4
A.2.2 Understanding the Tiling Level ................................................................................... A-4
A.2.3 Database Sizing............................................................................................................... A-5
A.2.4 Tuning Point Data .......................................................................................................... A-6
A.2.4.1 Efficient Queries for Point Data ............................................................................ A-6
A.2.4.2 Efficient Schema for Point Layers ......................................................................... A-7
A.2.5 Tuning Spatial Join Queries .......................................................................................... A-8
A.2.5.1 Using the NO_MERGE, INDEX, and USE_NL Hints........................................ A-8
A.2.5.2 Spatial Join Queries with Point Layers ................................................................ A-9
A.2.6 Using Customized Geometry Types ........................................................................ A-11
A.2.7 Performing Secondary Filter Queries and the Redo Log....................................... A-11
A.2.8 Visualizing the Spatial Index (Drawing Tiles) ........................................................ A-11
B Data Dictionary
Glossary
vi
Send Us Your Comments
If you find any errors or have any other suggestions for improvement, please indicate the chapter,
section, and page number (if available).
You can send comments to us in the following ways
■ e-mail: [email protected]
■ FAX: 603.897.3269. Attn: Spatial Cartridge
■ postal service:
Oracle Corporation
Oracle Spatial Cartridge Documentation
One Oracle Drive
Nashua, NH 03062
USA
If you would like a reply, please include your name, address, and telephone number.
vii
viii
Preface
The Oracle8 Spatial Cartridge User’s Guide and Reference provides user and reference
information for Spatial Cartridge, and extensions to Oracle8 Enterprise Edition.
Spatial Cartridge requires Oracle8 Enterprise Edition. Oracle8 and Oracle8 Enter-
prise Edition have the same basic features. However, several advanced features,
such as data cartridges, are available only with the Enterprise Edition, and some of
these features are optional. For example, to use Oracle8 table partitioning, you
must have the Enterprise Edition and the Partitioning Option.
For information about the differences between Oracle8 and the Oracle8 Enterprise
Edition and the features and options that are available to you, see Getting to Know
Oracle8.
Intended Audience
This guide is intended for anyone who needs to store spatial data in a relational
database.
ix
Structure
This guide contains nine chapters, several appendixes, and a glossary:
Chapter 1 Introduces spatial data concepts.
Chapter 2 Explains spatial data loading.
Chapter 3 Explains methods for querying a spatial database.
Chapter 4 Explains how to use partitioned point data.
Chapter 5 Provides the syntax and semantics for the administrative functions
and procedures.
Chapter 6 Provides the syntax and semantics for the tuning functions and
procedures.
Chapter 7 Provides the syntax and semantics for the geometric functions and
procedures.
Chapter 8 Provides the syntax and semantics for the window functions and
procedures.
Chapter 9 Provides the syntax and semantics for functions and procedures
relevant only to using partitioned point data.
Appendix A Describes sample SQL scripts and tuning tips.
Appendix B Describes the Spatial Cartridge data dictionary.
Appendix C Provides a list of error messages and conditions.
Glossary Provides definitions of terms used in this guide.
Related Documents
For more information, see the following manuals:
■ Getting to Know Oracle8
■ Oracle8 Administrator’s Guide
■ Oracle8 Error Messages
■ Oracle8 Utilities
For additional information about Spatial Cartridge, including a demonstration, sev-
eral white papers, and other assorted collateral, visit the official Spatial Cartridge
web site: http://www.oracle.com/st/cartridges/spatial/
x
Conventions
In examples, an implied carriage return occurs at the end of each line, unless other-
wise noted. You must press the Return key at the end of a line of input.
The following conventions are used in this manual:
Convention Meaning
. Vertical ellipsis points in an example mean that information
. not directly related to the example has been omitted.
.
... Horizontal ellipsis points in statements or commands mean
that parts of the statement or command not directly related to
the example have been omitted
boldface text Boldface type in text indicates a term defined in the text, the
glossary, or in both locations.
<> Angle brackets enclose user-supplied names.
[] Brackets enclose optional clauses from which you can choose
one or none.
% The percent sign represents the system prompt on a UNIX
system.
xi
xii
1
Spatial Cartridge Concepts
1.3.1 Element
An element is the basic building block of a geometric feature for Spatial Cartridge.
The supported spatial element types are points, line strings, and polygons. For
example, elements might model star constellations (point clusters), roads (line
strings), and county boundaries (polygons). Each coordinate in an element is stored
as an X,Y pair.
Point data1 consists of one coordinate. Line data consists of two coordinates repre-
senting a line segment of the element. Polygon data consists of coordinate pair val-
ues, one vertex pair for each line segment of the polygon. Coordinates are defined
in either a clockwise or counter-clockwise order around the polygon.
If an element spans more than one row, an incremental sequence number (starting
at zero) orders the rows.
1.3.2 Geometry
A geometry is the representation of a user’s spatial feature, modeled as an ordered
set of primitive elements. Each geometric object is required to be uniquely identi-
fied by a numeric geometry identifier (GID), associating the object with its corre-
sponding attribute set.
A complex geometric feature such as a polygon with holes would be stored as a
sequence of polygon elements. In a multi-element polygonal geometry, all subele-
ments are wholly contained within the outermost element, thus building a more
complex geometry from simpler pieces.
For example, a geometry might describe the buildable land in a town. This could be
represented as a polygon with holes where water or zoning prevents construction.
1
Point data can also be stored in a partitioned table. See Chapter 4, “Partitioning Point Data”
for details.
1.3.3 Layer
A layer is a heterogeneous collection of geometries having the same attribute set.
For example, one layer in a GIS might include topographical features, while
another describes population density, and a third describes the network of roads
and bridges in the area (lines and points). Each layer’s geometric objects and their
associated spatial index are stored in the database in standard tables.
The SDO_MAXCODE and SDO_GROUPCODE columns are not required for the
recommended indexing algorithm using fixed-size tiles.
<layername>_SDOLAYER:
■ SDO_ORDCNT - The SDO_ORDCNT column is the total number of ordi-
nates per row in the <layername>_SDOGEOM table. That is, the total num-
ber of data value columns, and not the number of points or coordinates.
SDO_ORDCNT should not be multiplied by the total number of dimen-
sions per coordinate as it is already a total.
■ SDO_LEVEL - The SDO_LEVEL column stores the number of times the
layer should be tessellated during the indexing stage. Use the
SDO_TUNE.ESTIMATE_TILING_LEVEL() procedure to determine an
appropriate tiling level for your data.
■ SDO_NUMTILES - The SDO_NUMTILES column is the number of vari-
able-sized tiles used to tessellate each object in the <layer-
name>_SDOGEOM table. This column must be set to NULL when using
fixed-size tiles.
■ SDO_COORDSYS - The SDO_COORDSYS column is optional; where you
can indicate the name of the coordinate system, using a standard such as
POSC or OGIS.
<layername>_SDODIM:
■ SDO_DIMNUM - The SDO_DIMNUM column is the dimension to which this
row refers, starting with 1 and increasing.
■ SDO_LB - The SDO_LB column is the lower bound of the ordinate in this
dimension. For example, if the dimension is latitude, the lower bound
would be -90.
■ SDO_UB - The SDO_UB column is the upper bound of the ordinate in this
dimension. For example, if the dimension is longitude, the upper bound
would be 180.
■ SDO_TOLERANCE - The SDO_TOLERANCE column is the distance two
points can be apart and still be considered the same due to round-off
errors. Tolerance must be greater than zero. If you want zero tolerance,
enter a number such as 0.00005, where the number of zeroes to the right of
the decimal point matches the precision of your data. The extra 5 will
round up to your last decimal digit.
■ SDO_DIMNAME - The SDO_DIMNAME column is used for the usual name
applied to this dimension, such as longitude, latitude, X or Y.
<layername>_SDOGEOM:
■ SDO_GID - The SDO_GID column is a unique numeric identifier for each
geometry in a layer.
■ SDO_ESEQ - The SDO_ESEQ column enumerates each element in a geome-
try, that is, the Element SEQuence number.
■ SDO_ETYPE - The SDO_ETYPE column is the geometric primitive type of
the element. For this release of Spatial Cartridge, the valid values are
SDO_GEOM.POINT_TYPE, SDO_GEOM.LINESTRING_TYPE, or
SDO_GEOM.POLYGON_TYPE (ETYPE values 1, 2, and 3, respectively).
Setting the ETYPE to zero indicates that this element should be ignored.
See Section A.2.6 for information on ETYPE 0.
■ SDO_SEQ - The SDO_SEQ column records the order (the SEQuence num-
ber) of each row of data making up the element.
■ SDO_X1 - X value of the first coordinate.
■ SDO_Y1 - Y value of the first coordinate.
■ SDO_Xn - X value of the Nth coordinate.
■ SDO_Yn - Y value of the Nth coordinate.
<layername>_SDOINDEX:
■ SDO_GID - The SDO_GID column is a unique numeric identifier for each
geometry in a layer. This can be thought of as a foreign key back to the
<layername>_SDOGEOM table.
■ SDO_CODE - The SDO_CODE column is the bit-interleaved ID of a tile that
covers SDO_GID. The number of bytes needed for the SDO_CODE and
SDO_MAXCODE columns depends on the level used for tiling. Use the
SDO_ADMIN.SDO_CODE_SIZE() function to determine the size required
for a given layer. The maximum number of bytes possible is 255.
■ SDO_MAXCODE - The SDO_MAXCODE column describes a variable-sized
logical tile, which is the smallest tile (with the longest tile ID) in the current
quadrant. The SDO_MAXCODE column is SDO_CODE padded out one
place farther than the longest allowable code name for this index. This col-
umn is not used for fixed-size tiles.
■ SDO_GROUPCODE - The SDO_GROUPCODE column is a prefix of
SDO_CODE. It represents a variable-sized tile at level <layer-
name>_SDOLAYER.SDO_LEVEL that contains or is equal to the tile repre-
sented by SDO_CODE. This column is not used for fixed-size tiles.
Geometry 1013:
P3 P4 Element 0
P2 P5
G2 G3
Element 1 (Hole)
P1 G1 G4 P6
P8 P7
<layername>_SDOLAYER
SDO_ORDCNT
(number)
<layername>_SDODIM
<layername>_SDOGEOM
T2 T3
Geometry 1013:
Element 0
P3 P4
P2 P5
G2 G3
Element 1 (Hole)
P1 G1 G4 P6
T0 T1
P8 P7
Only three of the four tiles generated by the first tessellation interact with the geom-
etry. Only those tiles that interact with the geometry are stored in the
<layername>_SDOINDEX table, as shown in Table 1–5. In this example, three fixed-
size tiles are used.
Using a small fixed-size tile as shown in Figure 1–4, selectivity is good, but a large
number of tiles is needed to cover large geometries. A window query would easily
identify geometries A and B, but would reject C.
query window
Using a large fixed-size tile as shown in Figure 1–5, fewer tiles are needed to cover
the geometries, but the selectivity is poor. A window query would likely pick up all
three geometries. Any object that shares tile T1 or T2 would identify object C as a
candidate, even though the objects may be far apart, such as objects B and C are in
this figure.
Use the SDO_TUNE.ESTIMATE_TILING_LEVEL() function to determine an appro-
priate tiling level for your data set.
T1
query window
T2
In Figure 1–6, the variable-sized cover tiles conform closely to each geometry, result-
ing in good selectivity. The number of tiles needed to cover a geometry is con-
trolled using the SDO_NUMTILES column in the <layername>_SDOLAYER table.
See Section 2.3.3 for information on selecting appropriate values for variable-sized
tiling.
Two geometries may interact if a tile of one object is equal to, inside of, or contains
a tile of the other. Thus, the query predicate to compare tiles involves a test for
either equality or containment. This is unlike fixed-size tiling, which only requires
an equality check. Example 1–1 demonstrates this feature (“5” is an arbitrary win-
dow identifier).
Example 1–1
SELECT r.sdo_gid
FROM roads_sdoindex r,
window_sdoindex w
WHERE w.sdo_gid = 5
AND (r.sdo_code BETWEEN w.sdo_code AND w.sdo_maxcode OR
w.sdo_code BETWEEN r.sdo_code AND r.sdo_maxcode);
Example 1–2
SELECT r.sdo_gid
FROM layer_sdoindex r,
window_sdoindex w
WHERE w.sdo_gid = 5
AND r.sdo_group_code = w.sdo_groupcode
AND (r.sdo_code BETWEEN w.sdo_code AND w.sdo_maxcode OR
w.sdo_code BETWEEN r.sdo_code AND r.sdo_maxcode);
In Figure 1–7, consider the domain partitioned into 16 subregions. If a join com-
pares tiles from the two objects, under normal circumstances the join operation
would process tiles from the entire domain, searching for tiles that interact. How-
ever, if you constrain the processing to common partitions, then only partitions 5
and 6 would need to be processed. This may result in substantial performance
improvements.
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Large Point Datasets,” describing the use of partitioning and spatial indexing for
point data sets may be obtained from the Oracle corporate web site at:
http://www.oracle.com/st/cartridges/spatial/collateral
A previous release of Spatial Data Option (from which Spatial Cartridge has
evolved) utilized its own version of table partitioning instead of spatial indexing.
Chapter 4 briefly describes the old partitioning scheme for those customers with
legacy point data sets. Any references to point data partitioning in this guide (such
as the ”Partitioned Point Data Procedures” section in Chapter 5) refer to this legacy
feature. While this feature is still available in Spatial Cartridge, the preferred
approach is to use Oracle8 Partitioning Option and spatial indexing.
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.
Example 2–1
geometry rows: GID, ESEQ, ETYPE, SEQ, LON1, LAT1, LON2, LAT2
1
See the Oracle Server Utilities User’s Guide for information on the SQL*Loader.
The coordinates in the geometry rows represent the end points of line segments,
which taken together, represent a polygon. Example 2–2 shows the control file for
loading the data into the geometry table.
Example 2–2
LOAD DATA INFILE *
INTO TABLE ROADS_SDOGEOM
FIELDS TERMINATED BY WHITESPACE TRAILING NULLCOLS
(SDO_GID INTEGER EXTERNAL,
SDO_ESEQ INTEGER EXTERNAL,
SDO_ETYPE INTEGER EXTERNAL,
SDO_SEQ INTEGER EXTERNAL,
SDO_X1 FLOAT EXTERNAL,
SDO_Y1 FLOAT EXTERNAL,
SDO_X2 FLOAT EXTERNAL,
SDO_Y2 FLOAT EXTERNAL)
BEGINDATA
1 0 3 0 -122.401200 37.805200 -122.401900 37.805200
1 0 3 1 -122.401900 37.805200 -122.402400 37.805500
1 0 3 2 -122.402400 37.805500 -122.403100 37.806000
1 0 3 3 -122.403100 37.806000 -122.404400 37.806800
1 0 3 4 -122.404400 37.806800 -122.401200 37.805200
1 1 3 0 -122.405900 37.806600 -122.407549 37.806394
1 1 3 1 -122.407549 37.806394 -122.408300 37.806300
1 1 3 2 -122.408300 37.806300 -122.409100 37.806200
1 1 3 3 -122.409100 37.806200 -122.405900 37.806600
2 0 2 0 -122.410800 37.806000 -122.412300 37.805800
2 0 2 1 -122.412300 37.805800 -122.414100 37.805600
2 0 2 2 -122.414100 37.805600 -122.412300 37.805800
2 0 2 3 -122.412300 37.805800 -122.410800 37.806000
3 0 1 0 -122.567474 38.643564
3 0 1 1 -126.345345 39.345345
Note that table ROADS_SDOGEOM exists in the schema before attempting the
load.
In Example 2–3, the data resides in a single flat file and the data set consists of
point, line string, and polygon data. The data uses fixed-position columns and over-
loaded table rows.
Example 2–3
SDO_GID SDO_ESEQ SDO_ETYPE SDO_SEQ SDO_X1 SDO_Y1 SDO_X2 SDO_Y2
The corresponding control file for this format of input data would be:
LOAD DATA INFILE *
INTO TABLE NEW_SDOGEOM
(SDO_GID POSITION (1:5) INTEGER EXTERNAL,
SDO_ESEQ POSITION (7:10) INTEGER EXTERNAL,
SDO_ETYPE POSITION (12:15) INTEGER EXTERNAL,
SDO_SEQ POSITION (17:21) INTEGER EXTERNAL,
SDO_X1 POSITION (23:35) FLOAT EXTERNAL,
SDO_Y1 POSITION (37:48) FLOAT EXTERNAL,
SDO_X2 POSITION (50:62) FLOAT EXTERNAL,
SDO_Y2 POSITION (64:75) FLOAT EXTERNAL)
BEGINDATA
1 0 3 0 -122.401200 37.805200 -122.401900 37.805200
1 0 3 1 -122.401900 37.805200 -122.402400 37.805500
1 0 3 2 -122.402400 37.805500 -122.403100 37.806000
1 0 3 3 -122.403100 37.806000 -122.404400 37.806800
1 0 3 4 -122.404400 37.806800 -122.401200 37.805200
1 1 3 0 -122.405900 37.806600 -122.407549 37.806394
1 1 3 1 -122.407549 37.806394 -122.408300 37.806300
1 1 3 2 -122.408300 37.806300 -122.409100 37.806200
1 1 3 3 -122.409100 37.806200 -122.405900 37.806600
2 0 2 0 -122.410800 37.806000 -122.412300 37.805800
2 0 2 1 -122.412300 37.805800 -122.414100 37.805600
2 0 2 2 -122.414100 37.805600 -122.412300 37.805800
2 0 2 3 -122.412300 37.805800 -122.410800 37.806000
3 0 1 0 -122.567474 38.643564
3 0 1 1 -126.345345 39.345345
Example 2–4
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, 2, 1, 0, 9, 29);
The SQL INSERT statement inserts one row of data per call. In Example 2–4, 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
perform mulitple inserts in order to match the table structure; the data would not
wrap automatically to the next row. To load a large geometry, repeat the SDO_GID,
SDO_ESEQ, and SDO_ETYPE, and increment the SDO_SEQ for each line as shown
in Example 2–5.
Example 2–5
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);
Example 2–6
elem_value := sdo_geom.init_element(’ROADS’, 1234);
Close the polygon by repeating the first vertex (Ax,Ay) as the last vertex.
In Example 2–7, assume that the geometry shown in Figure 2–1 needs to be stored.
The geometry consists of a polygon with a hole in it. Note that both calls to the
SDO_GEOM.ADD_NODES() procedure are made with the same GID (6789) because
this is a single object even though it is composed of two elements.
Geometry 6789:
P3 P4
G2 G3
P2 P5
G4
G1
P1
P6
Example 2–7
val1 := sdo_geom.init_element(’PARKS’, 6789);
sdo_geom.add_nodes(’PARKS’, 6789, val1, SDO_GEOM.POLYGON_TYPE, P1x, P1y,
P2x, P2y, P3x, P3y, P4x, P4y, P5x, P5y, P6x, P6y, P1x, P1y);
val2 := sdo_geom.init_element(’PARKS’, 6789);
sdo_geom.add_nodes(’PARKS’, 6789, val2, SDO_GEOM.POLYGON_TYPE, G1x, G1y,
G2x, G2y, G3x, G3y, G4x, G4y, G1x, G1y);
1
The transference of the domain onto a sphere or Mercator projection is left to GIS (or other)
application programmers. Spatial Cartridge treats the domain as a conventional X by Y rect-
angle.
-90
-180 180
If the SDO_LEVEL column is set to 1, then the tiles created by the indexing mecha-
nism are the same size as tiles at the first level of tessellation. Each tile would be
180 degrees by 90 degrees as shown in Figure 2–3.
-90
-180 0 180
The formula for the number of fixed-size tiles is 4n where n is the number of tessel-
lations, stored in the SDO_LEVEL column. Figure 2–4 shows fixed-size tiling at
level 2. In this figure, each tile is 90 degrees by 45 degrees.
-90
-180 -90 0 90 180
The size of a tile can be determined by applying the following formula to each
dimension:
length = (upper_bound - lower_bound) / 2 ^ sdo_level
The length refers to the length of the tile along the specified dimension. Applying
this formula to the tiling shown in Figure 2–4 yields the following sizes:
length for dimension X = (180 - (-180) ) / 2^2
= (360) / 4
= 90
length for dimension Y = (90 - (-90) ) / 2^2
= (180) / 4
= 45
Thus, at level 2 the tiles are 90x45 degrees in size. As the number of levels increases,
the tiles become smaller and smaller. Smaller tiles provide a more precise fit of the
tiles over the geometry being indexed. However, because the number of tiles gener-
ated is unbounded, you must take into account the performance implications of
using higher levels. The SDO_TUNE.ESTIMATE_TILING_LEVEL() function can
be used to determine an appropriate level for indexing with fixed-size tiles. See
Chapter 6 for a description of this procedure.
Besides the performance aspects related to selecting a fixed-size tile, 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 1-acre farm plots, city blocks, or indi-
vidual pixels on a display. Data modeling is an important part any database design,
and is essential in a spatial database where the data often represents actual physical
locations.
In Example 2–8, assume that data has been loaded into a layer called ROADS, and
you want to create a spatial index on that data.
Example 2–8
To create a spatial index, create a table ROADS_SDOINDEX and invoke the fol-
lowing procedure:
sdo_admin.populate_index(’ROADS’);
The SDO_ADMIN.POPULATE_INDEX()and
SDO_ADMIN.UPDATE_INDEX()procedures behave differently from the CRE-
ATE INDEX statement in SQL. An implicit commit is not executed after the pro-
cedures are called. Therefore these transactions can be rolled back.
The SDO_ADMIN.POPULATE_INDEX() procedure operates as a single transac-
tion. To reduce the amount of rollback required to execute this procedure, you
can write a routine that loops and calls SDO_ADMIN.UPDATE_INDEX() . See
Section A.1.1.1, “cr_spatial_index.sql Script” for more information.
This chapter describes how the structures of a Spatial Cartridge layer are used to
resolve spatial queries and spatial joins. For the sake of clarity, the examples all use
fixed-size tiling.
PRIMARY SECONDARY
FILTER FILTER
Large
Input Smaller Exact
Row Row Result
Source Source Set
Spatial Cartridge 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.
Spatial Cartridge does not require the use of both the primary and secondary fil-
ters. In some cases, just using the primary filter is sufficient. For example, a zoom
feature in a mapping application queries for data that overlaps a rectangle repre-
senting visible boundaries. The primary filter very quickly returns a superset of the
query. The mapping application can then apply clipping routines to display the tar-
get area.
T1 T2 T7
1013
501
T3 T4
12
T5 T6 T8 T9
1243
61
The Spatial Cartridge layer tables would have the following information stored in
them for these geometries as shown in Table 3–1, Table 3–2, and Table 3–3.
SDO_GID SDO_CODE
(number) (raw)
1013 T1
1013 T2
1013 T3
1013 T4
501 T2
501 T7
1243 T3
1243 T4
1243 T5
1243 T6
12 T3
12 T4
61 T8
61 T9
T1 T2 T7
1013
501
T3 T4
12
T5 T6 T8 T9
1243
61
After compiling, the routines are available for use. When you call a routine in this
package, and the routine performs an INSERT operation, the insert will occur
under the mdsys schema. Note that it is not a requirement to use the mdsys
account. You can select any Oracle user with insert privileges.
If you need to perform other INSERT, UPDATE, or DELETE operations, and you
cannot guarantee that the user of your application has those privileges, you can
write your own PL*SQL package similar to the SDO_WINDOW package. You will
have to compile your package under a user with the required database privileges.
Next, insert the ordinates for the query fence into the layer tables:
SQL> EXECUTE DBMS_OUTPUT.PUTLINE(TO_CHAR(MDSYS.SDO_WINDOW.BUILD_WINDOW_FIXED
(comp_user, fencelayer, SDO_ETYPE, TILE_SIZE, X1, Y1, X2, Y2, X3, Y3, X4, Y4,
X1, Y1)));
The result set of this query is the primary filter set. In this case, the result set is:
{ 1013,501,1243,12 }
)
WHERE SDO_GEOM.RELATE(’<layer1>’, GID1, ’ANYINTERACT’, ’<fence>’, 1) = ’TRUE’
)
WHERE SDO_GID = GID1;
This query would return all the geometry IDs that lie within or overlap the win-
dow. In this example, the results of the secondary filter would be:
{1243,1013}
The example in this section uses the SDO_GEOM.RELATE() secondary filter. Both
the INTERACT() and RELATE() secondary filters are overloaded functions. For bet-
ter performance, use the versions that explicitly list the coordinates of the query
window whenever possible. See Chapter 7, “Geometry Functions” for details on
using these functions.
Spatial
Data PARKS_SDODIM: HIGHWAYS_SDODIM:
Structures DIM LB UB TOL NAME DIM LB UB TOL NAME
PARKS_SDOGEOM: HIGHWAYS_SDOGEOM:
GID ESEQ ETYPE SEQ X1 Y1 GID ESEQ ETYPE SEQ X1 Y1
PARKS_SDOINDEX: HIGHWAYS_SDOINDEX:
GID CODE MAX GID CODE MAX
The PRIMARY filter would identify pairs of park GIDs and highway GIDs that
cross in the index. The query that performs the primary filter join (assuming fixed-
size tile indexing) is as follows:
SELECT DISTINCT A.SDO_GID,B.SDO_GID
FROM PARKS_SDOINDEX A, HIGHWAYS_SDOINDEX B
WHERE A.SDO_CODE = B.SDO_CODE
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 full query is shown in
the following example:
Suppose the original query had asked, “which 4-lane highways cross national
parks?” You could modify the preceding SQL statement to join back to the HIGH-
WAYS table where HIGHWAYS.WIDTH=4. This combination of spatial and rela-
tional attributes in a single query is one of the essential reasons for using Spatial
Cartridge.
Spatial Cartridge provides the essential functions, procedures, and scripts for using
and managing both spatially indexed data and partitioned point data. The informa-
tion in this chapter is relevant only to users utilizing table partitioning for very
large quantities of point data.
4.1 Overview
Partitioning is a technique where data is loaded into tables that automatically sub-
divide when a predefined maximum size is reached. During subdivision, data is
moved from the parent partition to the child partitions and the parent partition is
dropped. Storage parameters for child partitions are inherited from the root parti-
tion and can be changed at any time.
A partitioned table has a partition key that is an HHCODE column created by
encoding multidimensional point data using the SDO_ENCODE() function. In the
partitioning process, at each subdivision, data is subdivided into 2n partitions
where n is the number of dimensions encoded in the HHCODE column. You can
encode up to 32 dimensions using Spatial Cartridge.
– SDO_ADMIN.REGISTER_PARTITION
– SDO_ADMIN.REPARTITION
– SDO_ADMIN.VERIFY_PARTITIONS
■ Chapter 9, “Partitioned Point Data Functions”
– SDO_BVALUETODIM
– SDO_COMPARE
– SDO_DATETODIM
– SDO_DECODE
– SDO_ENCODE
– SDO_TO_BVALUE
– SDO_TO_DATE
■ Appendix A, “Sample SQL Scripts and Tuning Tips”
– altpart.sql
– drppart.sql
– sdogrant.sql
The SDO_ADMIN procedures create and maintain spatial structures in the data-
base, and are used to perform the following tasks:
■ Tessellate entries in a geometry table and place them in a spatial index table
■ Register and manipulate partitioned spatial tables (partitioned tables are used
only for large volumes of point data)
■ Verify spatial index and partitioned spatial table information
This chapter contains descriptions of the administrative procedures used for work-
ing with either spatially indexed geometric data or partitioned point data. These
data structures are mutually exclusive and the procedures only work with the struc-
ture for which they are designed.
Table 5–1 lists the administrative procedures for working with spatially indexed
geometry-based data. Table 5–2 later in this chapter lists procedures for working
with partitioned point data.
SDO_ADMIN.POPULATE_INDEX
Purpose
This procedure tessellates a list of geometric objects created by selecting all the
entries in the geometry table that do not have corresponding entries in the spatial
index table.
This procedure can generate either fixed or variable-sized tiles depending on val-
ues stored in the <layername>_SDOLAYER table.
Syntax
SDO_ADMIN.POPULATE_INDEX (layername)
Usage Notes
Consider the following when using this procedure:
■ The <layername>_SDOINDEX table must be created prior to calling this proce-
dure. Use the SQL CREATE TABLE statement to create the spatial index table.
■ For performance reasons, create an index on the SDO_GID column in the
<layername>_SDOGEOM table before calling this routine.
■ This procedure generates either fixed-size or variable-sized tiles depending on
values stored in the <layername>_SDOLAYER table as follows:
Example 5–1
SQL> EXECUTE SDO_ADMIN.POPULATE_INDEX(’layer1’);
SQL> COMMIT;
Related Topics
■ SDO_ADMIN.UPDATE_INDEX() procedure
SDO_ADMIN.POPULATE_INDEX_FIXED
Purpose
This procedure is provided for compatibility with Spatial Cartridge release 8.0.3
tables. This procedure has been replaced by enhanced features in the
SDO_ADMIN.POPULATE_INDEX() procedure, and by supporting schema changes
as shown in Section 1.4.
This procedure tessellates a list of geometric objects created by selecting all the
entries in the geometry table that do not have corresponding entries in the spatial
index table. This procedure can also tessellate all the geometric objects in a geome-
try table or view and add the tiles to the spatial index table.
Use this procedure to tessellate the geometries into fixed-size tiles.
Syntax
SDO_ADMIN.POPULATE_INDEX_FIXED (layername, tile_size, [synch_flag,] [sdo_tile_flag,]
[sdo_maxcode_flag])
layername Specifies the name of the data set layer. The layer name is used to con-
struct the name of the geometry and spatial index tables.
Data type is VARCHAR2.
tile_size Specifies the number of tessellations required to achieve the desired tile
size (see the Usage Notes).
Data type is INTEGER.
synch_flag Specifies whether to tessellate every geometric object in the geometry
table, or only those that do not have corresponding entries in the spatial
index table. If TRUE, only those geometric objects in the geometry table
that do not have any corresponding tiles in the spatial index table are tes-
sellated. If FALSE, all the geometric objects in the geometry table are tes-
sellated and new tiles are simply added to the spatial index table.
Default value is TRUE.
Data type is BOOLEAN.
sdo_tile_flag For internal use only. Not supported in this release.
Default value is FALSE.
Usage Notes
Example 5–2
SQL> EXECUTE SDO_ADMIN.POPULATE_INDEX_FIXED(’layer1’,4,FALSE,FALSE,FALSE);
Related Topics
■ SDO_ADMIN.UPDATE_INDEX_FIXED() procedure
■ SDO_TUNE.ESTIMATE_TILING_LEVEL() function
SDO_ADMIN.SDO_CODE_SIZE
Purpose
This function determines the size that the SDO_CODE column should be in the
<layername>_SDOINDEX table.
Syntax
SDO_ADMIN.SDO_CODE_SIZE (layername)
Returns
This function returns the required size in bytes for the SDO_CODE column.
Data type is INTEGER.
Usage Notes
The SDO_CODE column is used to store the bit-interleaved cell ID of a tile that cov-
ers a geometry. The SDO_MAXCODE column is SDO_CODE padded out one place
farther than the longest allowable code name for the index. Both columns are
defined as RAW data types, with a maximum of 255 bytes. Use the
SDO_ADMIN.SDO_CODE_SIZE() function to fine-tune the size of the columns.
You should always set the SDO_MAXCODE column to one greater than the
SDO_CODE column.
Related Topics
None
SDO_ADMIN.UPDATE_INDEX
Purpose
This procedure tessellates a single geometric object in a geometry table or view and
adds the tiles to the spatial index table. If the object already exists and has index
entries, those entries are deleted and replaced by the newly generated tiles.
Syntax
SDO_ADMIN.UPDATE_INDEX (layername, GID)
Usage Notes
Considert the following when using this procedure:
■ The <layername>_SDOINDEX table must exist prior to calling this procedure.
Use the SQL CREATE TABLE statement to create the spatial index table.
■ For performance reasons, create an index on the SDO_GID column in the
<layername>_SDOGEOM table before calling this routine.
■ The values of the SDO_LEVEL and SDO_NUMTILES columns must be set in
the <layername>_SDOLAYER table before calling this procedure. This proce-
dure generates either fixed-size or variable-sized tiles depending on values
stored in the <layername>_SDOLAYER table as follows:
Example 5–3
SQL> EXECUTE SDO_ADMIN.UPDATE_INDEX(’layer1’, 25);
SQL> COMMIT;
Related Topics
■ SDO_ADMIN.POPULATE_INDEX() procedure
SDO_ADMIN.UPDATE_INDEX_FIXED
Purpose
This procedure is provided for compatibility with Spatial Cartridge release 8.0.3
tables. This procedure has been replaced by enhanced features in the
SDO_ADMIN.UPDATE_INDEX() procedure, and by supporting schema changes as
shown in Section 1.4.
This procedure tessellates a single geometric object in a geometry table or view and
adds the fixed-sized tiles to the spatial index table. By default, these tiles will
replace existing ones for the same geometry; or optionally, existing tiles can be left
alone.
Syntax
SDO_ADMIN.UPDATE_INDEX_FIXED (layername, GID, tile_size, [replace_flag,] [sdo_tile_flag]
[sdo_maxcode_flag])
layername Specifies the name of the data set layer. The layer name is used to con-
struct the name of the geometry table.
Data type is VARCHAR2.
GID Specifies the geometric object identifier.
Data type is NUMBER.
tile_size Specifies the number of tessellations required to achieve the desired
fixed-size tiles. Each tessellation subdivides the tiles from the previ-
ous level into four smaller tiles.
Data type is INTEGER.
replace_flag Specifies whether or not to delete tiles for the GID before adding new
ones. If TRUE, tiles are deleted prior to inserting new entries into the
spatial index table. If FALSE, new tiles are simply added to the spatial
index table.
Default value is TRUE.
Data type is BOOLEAN.
sdo_tile_flag For internal use only. Not supported in this release.
Default value is FALSE.
Data type is BOOLEAN.
Usage Notes
Example 5–4
SQL> EXECUTE SDO_ADMIN.UPDATE_INDEX_FIXED (’layer1’,25,4,FALSE,FALSE,FALSE);
Related Topics
■ SDO_ADMIN.POPULATE_INDEX_FIXED() procedure
■ SDO_TUNE.ESTIMATE_TILING_LEVEL() function
SDO_ADMIN.VERIFY_LAYER
Purpose
This procedure checks for the existence of the geometry and spatial index tables.
Syntax
SDO_ADMIN.VERIFY_LAYER (layername,[maxtiles])
Usage Notes
If this procedure does not find the geometry and spatial index tables, it generates
the following error: SDO 13113 (Oracle table does not exist)
Example 5–5 verifies the LAYER1 data set layer:
Example 5–5
SQL> EXECUTE SDO_ADMIN.VERIFY_LAYER(’layer1’);
Related Topics
None
Table 5–2 lists the procedures that can be used with partitioned point data. These
procedures are neither required nor compatible with the geometry-based data for-
mat.
Also see Appendix A, “Sample SQL Scripts and Tuning Tips” for additional admin-
istrative tools useful for working with partitioned point data.
SDO_ADMIN.ALTER_HIGH_WATER_MARK
Purpose
This procedure alters the high-water mark of a partitioned spatial table. The high-
water mark defines how many records can be stored in a partition before it subdi-
vides. The table must exist and be registered in the Spatial Cartridge data dictio-
nary.
This procedure is for use only with partitioned point data.
Syntax
SDO_ADMIN.ALTER_HIGH_WATER_MARK (tablename, high_water_mark)
Usage Notes
None
Example 5–6 changes the high-water mark to 5000 records for the TABLE1 parti-
tioned spatial table.
Example 5–6
SQL> EXECUTE SDO_ADMIN.ALTER_HIGH_WATER_MARK(’table1’, 5000);
Related Topics
■ SDO_ADMIN.REPARTITION() procedure
■ altpart.sql sample SQL script file
SDO_ADMIN.DROP_PARTITION_INFO
Purpose
This procedure removes a partitioned spatial table from the Spatial Cartridge data
dictionary. The table must exist and must be registered in the Spatial Cartridge data
dictionary.
This procedure is used only with partitioned point data.
Syntax
SDO_ADMIN.DROP_PARTITION_INFO (tablename)
Usage Notes
This procedure does not remove the spatial table and its associated partition tables
from the user’s schema. For a description of how to remove a partitioned spatial
table from the user’s schema, see the drppart.sql sample SQL script file described
in Section A.1.2.2.
Example 5–7 removes the table1 table from the Spatial Cartridge data dictionary.
Example 5–7
SQL> EXECUTE SDO_ADMIN.DROP_PARTITION_INFO(’table1’);
Related Topics
■ drppart.sql sample SQL script file
SDO_ADMIN.PARTITION
Purpose
This procedure places data into partition tables based on the sorted order of
encoded dimensional values.
This procedure is used only with partitioned point data.
Syntax
SDO_ADMIN.PARTITION (owner.source_table, tablename, parallel, guess , plummet_flag
[,tablespace] )
owner.source_table Specifies the Oracle8 table or view of the table containing the partition
key column.
Data type is VARCHAR2.
tablename Specifies the name of the table to partition.
Data type is VARCHAR2.
parallel Specifies the degree of parallelism for an operation on a single
instance.
Data type is INTEGER.
guess Specifies the estimated largest common level of all the potential parti-
tions to be created from data in the source_table. The common level of
a partition is the number of levels of resolution of the common
HHCODE for the partition.
Data type is INTEGER.
plummet_flag Specifies if the common HHCODE for all the potential partitions to be
created from data in the source_table contains the maximum possible
common level. If TRUE, the common HHCODE for each potential par-
tition contains the maximum possible common level. If FALSE, the
common HHCODE for each potential partition contains the minimum
possible common level.
Default value is FALSE.
Data type is BOOLEAN.
tablespace Specifies the tablespace in which the partitions should be created.
Default is the tablespace of the underlying table.
Usage Notes
Consider the following when using this procedure:
■ The maximum size of the partition tables is determined by the high-water
mark of the partitioned spatial table.
■ To perform this procedure, first load the original data into an Oracle8 table
using a utility such as SQL*Loader. After the data is loaded, encode the data
using the appropriate combination of Spatial Cartridge data conversion func-
tions (see Chapter 9.) The encoded data is used as the partition key column.
The partition key column is provided as either a column in the Oracle8 table or
as a view of that table.
■ For more information on specifying the degree of parallelism, see the Oracle8
Server Tuning manual.
Example 5–8 partitions the table1 partitioned spatial table with data contained in
the source1 table.
Example 5–8
SQL> EXECUTE SDO_ADMIN.PARTITION(’source1’,’table1’,1,10,FALSE);
Related Topics
■ SDO_ADMIN.REGISTER_PARTITION_INFO() procedure
SDO_ADMIN.PROPAGATE_GRANTS
Purpose
This procedure is used to propagate the grants on the underlying table to the parti-
tions.
This procedure is used only with partitioned point data.
Syntax
SDO_ADMIN.PROPAGATE_GRANTS (tablename)
Usage Notes
This procedure is used after calls to SDO_ADMIN.PARTITION() or
SDO_ADMIN.REPARTITION(). It must be called by the owner of the partition.
This procedure must be compiled prior to use. See Section A.1.2.3, “sdogrant.sql
Script”.
Example 5–9 propagates grants from the TABLE1 partitioned spatial table.
Example 5–9
SQL> EXECUTE SDO_ADMIN.PROPAGATE_GRANTS(’TABLE1’);
Related Topics
■ SDO_ADMIN.PARTITION() procedure
■ SDO_ADMIN.REPARTITION() procedure
SDO_ADMIN.REGISTER_PARTITION_INFO
Purpose
This procedure creates a partitioned spatial table entry in the Spatial Cartridge data
dictionary, and defines the partition key column and the high-water mark for the
table.
This procedure is used only with partitioned point data.
Syntax
SDO_ADMIN.REGISTER_PARTITION_INFO (tablename, column, high_water_mark)
Usage Notes
The SQL CREATE TABLE statement is used to create the partitioned spatial table,
with the partition key column defined as RAW(255), prior to calling this procedure.
Example 5–10 registers the TABLE1 partitioned spatial table.
Example 5–10
SQL> EXECUTE SDO_ADMIN.REGISTER_PARTITION_INFO(’table1’,
2> ’hhcolumn’, 1000);
Related Topics
■ SDO_ADMIN.PARTITION() procedure
SDO_ADMIN.REPARTITION
Purpose
This procedure reorganizes a partitioned spatial table based on the sorted order of
encoded dimensional values already contained in it. The table must exist and must
be registered in the Spatial Cartridge data dictionary.
This procedure is used only with partitioned point data.
Syntax
SDO_ADMIN.REPARTITION (tablename, parallel, [tablespace])
Usage Notes
Consider the following when using this procedure:
■ The tablespace variable is optional. If you do not supply a tablespace name, the
partitions are created in the same tablespace as the registered partition table.
■ The maximum size of the reorganized partition tables is determined by the
high-water mark of the partitioned spatial table.
■ For more information on specifying the degree of parallelism, see the section
on "Parallel Query Option," in the Oracle8 Server documentation.
Example 5–11 repartitions the table1 partitioned spatial table.
Example 5–11
SQL> EXECUTE SDO_ADMIN.REPARTITION(’table1’, 1);
Related Topics
■ SDO_ADMIN.ALTER_HIGH_WATER_MARK() procedure
SDO_ADMIN.VERIFY_PARTITIONS
Purpose
This procedure checks if the partitioned spatial table exists, if it is registered in the
Spatial Cartridge data dictionary, and if the partition key column exists as defined
in the Spatial Cartridge data dictionary.
This procedure is used only with partitioned point data.
Syntax
SDO_ADMIN.VERIFY_PARTITIONS (tablename)
Usage Notes
This procedure can generate the following errors depending on the results of the
verification:
■ SDO 13113 (Oracle table does not exist)
■ SDO 13108 (spatial table not found)
■ SDO 13111 (spatial table has no partition key defined)
■ SDO 13129 (HHCODE column not found)
Example 5–12 verifies the TABLE1 partitioned spatial table:
Example 5–12
SQL> EXECUTE SDO_ADMIN.VERIFY_PARTITIONS(’table1’);
Related Topics
■ SDO_ADMIN.REGISTER_PARTITION_INFO() procedure
This chapter contains descriptions of the tuning functions and procedures shown in
Table 6–1.
SDO_TUNE.ESTIMATE_TILING_LEVEL
Purpose
This function estimates the appropriate tiling level to use when indexing with fixed-
size tiles.
Syntax
SDO_TUNE.ESTIMATE_TILING_LEVEL (layername, maxtiles, type_of_estimate)
Returns
The function returns an integer representing the level to use when creating a spatial
index for the specified layer.
Usage Notes
The SDO_ADMIN.POPULATE_INDEX() and SDO_ADMIN.UPDATE_INDEX() proce-
dures are used to create or update the spatial index using fixed-size or variable-
Example 6–2 Recommended Tile Level Based on the GIDs of All Geometries
set serveroutput on
declare
tiling_level integer;
begin
tiling_level:= mdsys.sdo_tune.estimate_tiling_level(’SF_BLOCK_GROUPS’,
10000, ’ALL_GID_EXTENT’);
dbms_output.put_line(’VALUE is’ ,|| tiling_level);
end;
The third type of estimate helps determine the tiling level that should be used such
that on average, the maxtiles parameter defines the number of tiles to cover the
extent of a single geometry in the layer. This estimate type requires the most com-
putation of the three because the bounding rectangle of every geometry is used in
calculating the average extent. In Example 6–3, eight tiles on average are used to
cover any block group in San Francisco.
Example 6–3 Recommended Tile Level Based on Average Extent of All Geometries
set serveroutput on
declare
tiling_level integer;
begin
tiling_level := mdsys.sdo_tune.estimate_tiling_level(’SF_BLOCK_GROUPS’, 8,
’AVG_GID_EXTENT’);
dbms_output.put_line(’Tiling level value is ’ || tiling_level);
end;
Related Topics
■ SDO_ADMIN.POPULATE_INDEX
■ SDO_ADMIN.UPDATE_INDEX
■ SDO_TUNE.EXTENT_OF
■ Section A.2.2, “Understanding the Tiling Level”
■ Section A.2.8, “Visualizing the Spatial Index (Drawing Tiles)”
SDO_TUNE.EXTENT_OF
Purpose
This procedure determines the extent of all geometries in a layer.
Syntax
SDO_TUNE.EXTENT_OF (layername, min_X, max_X, min_Y, max_Y)
Returns
This procedure returns the coordinates of the minimum-bounding rectangle for all
geometric data in a layer. The data type is NUMBER for the four return values.
Usage Notes
None
Related Topics
■ SDO_TUNE.ESTIMATE_TILING_LEVEL() function
SDO_GEOM.ADD_NODES
Purpose
This procedure stores coordinate geometry points into the SDOGEOM table.
Syntax
SDO_GEOM.ADD_NODES (layername, SDO_GID, SDO_ESEQ, SDO_ETYPE, X-ord1,Y-
ord1[,...,X125, Y125])
Usage Notes
Consider the following when using this procedure:
■ Use the SQL CREATE TABLE statement to create the geometry table,
<layername>_SDOGEOM, before calling this procedure.
Example 7–1
SQL> EXECUTE SDO_GEOM.ADD_NODES (‘LAYER1’, 25,
2> SDO_GEOM.POLYGON_TYPE,
3> 3,3, 7,3,
4> 7,7, 3,7,
5> 3,3);
Related Topics
■ SDO_GEOM.INIT_ELEMENT() function
SDO_GEOM.INIT_ELEMENT
Purpose
This function initializes elements in the SDOINFO table or view for a new geome-
try element.
Syntax
SDO_GEOM.INIT_ELEMENT (layername, SDO_GID)
Returns
This function returns the next element sequence number. The data type is INTE-
GER.
Usage Notes
This function initializes the element to be stored, but does not actually insert coordi-
nates into the SDOGEOM table. The SDO_GEOM.ADD_NODES() procedure is used
to insert associated coordinate data.
For layer objects created as views, you need to explicitly insert new geometries, as
opposed to using SDO_GEOM.INIT_ELEMENT() and SDO_GEOM.ADD_NODES().
Related Topics
■ SDO_GEOM.ADD_NODES() procedure
SDO_GEOM.INTERACT
Purpose
This function determines if two geometry objects interact.
Syntax
SDO_GEOM.INTERACT (layername1, SDO_GID1, [layername2,] SDO_GID2)
SDO_GEOM.INTERACT (layername1, SDO_GID1, X_tolerance, Y_tolerance, SDO_ETYPE,
num_ordinates, X_ordinate1, Y_ordinate1 [, ..., Xn, Yn]
[,SDO_ETYPE, num_ordinates, X_ordinate1, Y_ordinate1 [,...Xn,Yn]])
layername1, Specifies the name of the data set layer. The layer name is
layername2 used to construct the name of the geometry and spatial
index tables.
Data type is VARCHAR2.
SDO_GID1, Specifies the geometric object identifier.
SDO_GID2 Data type is NUMBER.
X_tolerance, Specifies the distance two points can be apart and still be
Y_tolerance considered the same due to rounding errors. Tolerance
must be greater than zero. If you want zero tolerance,
enter a number such as 0.000005, where the number of
zeroes to the right of the decimal point matches the preci-
sion of your data.
Data type is NUMBER.
SDO_ETYPE Specifies the type of geometry object.
Data type is INTEGER, corresponding to the following
constants:
1 SDO_GEOM.POINT_TYPE
2 SDO_GEOM.LINESTRING_TYPE
3 SDO_GEOM.POLYGON_TYPE
Returns
This function returns TRUE if the first and second objects interact with each other
and are not disjoint. The data type is VARCHAR2.
Usage Notes
Use the first form of the function to test two stored geometry objects.
Use the second form of the function to compare a stored object against a user-
defined object. You can specify up to 123 vertices for a single element geometry. If
the geometry has multiple elements, the total number of arguments passed, includ-
ing SDO_ETYPE, num_ordinates, and the list of vertex coordinates cannot exceed
250 values.
Related Topics
■ SDO_GEOM.RELATE() function
SDO_GEOM.RELATE
Purpose
This function examines two geometry objects to determine their spatial relationship.
Syntax
SDO_GEOM.RELATE (layername1, SDO_GID1, mask, [layername2,] SDO_GID2)
SDO_GEOM.RELATE (layername1, SDO_GID1, mask, X_tolerance, Y_tolerance, SDO_ETYPE,
num_ordinates, X_ordinate1, Y_ordinate1 [,...,Xn, Yn] [,SDO_ETYPE, num_ordinates, X_ordinate1,
Y_ordinate1 [,...,Xn, Yn]])
layername1, Specifies the name of the data set layer. The layer
layername2 name is used to construct the name of the geome-
try and spatial index tables.
Data type is VARCHAR2.
SDO_GID1, Specifies the geometry object identifier.
SDO_GID2 Data type is NUMBER.
mask Specifies a list of relationships to check. See the
list of keywords in the Usage Notes.
X_tolerance, Specifies the distance two points can be apart and
Y_tolerance still be considered the same due to rounding
errors. Tolerance must be greater than zero. If you
want zero tolerance, enter a number such as
0.000005, where the number of zeroes to the right
of the decimal point matches the precision of your
data.
Data type is NUMBER.
SDO_ETYPE Specifies the type of geometry element.
Data type is INTEGER, corresponding to the fol-
lowing constants:
1 SDO_GEOM.POINT_TYPE
2 SDO_GEOM.LINESTRING_TYPE
3 SDO_GEOM.POLYGON_TYPE
Returns
The SDO_GEOM.RELATE() function can return three types of answers:
1. If you pass a mask listing one or more relationships, the function returns the
names of the relationships if all of them are true. If one or more relationships
are false, the procedure returns FALSE.
2. If you pass the DETERMINE keyword in the mask, the function returns the one
relationship keyword that best matches the geometries.
3. If you pass the ANYINTERACT keyword in the mask, the function returns
TRUE if the two geometries are not disjoint. This is equivalent to the
SDO_GEOM.INTERACT() function.
The data type is VARCHAR2.
Usage Notes
Use the first form of the function to examine two stored geometry objects.
Use the second form of the function to compare a stored object against a user-
defined object. You can specify up to 123 vertices for a single-element geometry. If
the geometry has multiple elements, the total number of arguments passed, includ-
ing SDO_ETYPE, num_ordinates, and the list of vertex coordinates cannot exceed
250 values.
The following relationships can be tested:
■ ANYINTERACT - Returns TRUE if the objects are not disjoint.
■ CONTAINS - Returns TRUE if the second object is entirely within the first
object and the object boundaries do not touch.
■ COVEREDBY - Returns TRUE if the first object is entirely within the sec-
ond object and the object boundaries touch at one or more points.
■ COVERS - Returns TRUE if the second object is entirely within the first
object and the boundaries touch in one or more places.
Related Topics
■ SDO_GEOM.INTERACT() function
SDO_GEOM.VALIDATE_GEOMETRY
Purpose
This function provides a consistency check for valid geometry types. The function
checks the representation of the geometry from the tables against the element defi-
nitions.
Syntax
SDO_GEOM.VALIDATE_GEOMETRY (layername,SDO_GID)
Returns
This function returns TRUE if the geometry is valid. The data type is VARCHAR2.
Usage Notes
This function checks for the following:
■ Polygons have at least three points and must be closed
■ Line strings must have at least two points
■ When an SDO_ESEQ spans multiple rows, the last point of the previous row is
the first point on the next row
Related Topics
None
If a query window does not already exist in the database, you must first insert it
and create and index for it. The SDO_WINDOW functions are used to create tempo-
rary geometry objects to be used in comparisons with stored geometries. You can
create query windows with any number of coordinates.
Because not all Oracle users may have insert privileges, the SDO_WINDOW pack-
age is not automatically installed when you install Spatial Cartridge. This allows a
DBA to control the schema under which these functions operate. Choose an Oracle
user who has insert privilege and compile the SDO_WINDOW package under that
user. For example, you could choose the mdsys Oracle user:
% sqlplus mdsys/password
SQL> @$ORACLE_HOME/md/admin/sdowin.sql
SQL> @$ORACLE_HOME/md/admin/prvtwin.plb
This chapter contains descriptions of the window functions listed in Table 8–1.
SDO_WINDOW.BUILD_WINDOW
Purpose
This function builds the window for the query and returns an SDO_GID that serves
as a handle. The window is tessellated into variable-sized tiles.
Syntax
SDO_WINDOW.BUILD_WINDOW(comp_name, layername, SDO_ETYPE, SDO_NUMTILES, X1, Y1,
[...Xn, Yn])
Returns
This function returns the SDO_GID of the new geometry. The data type is NUM-
BER.
Usage Notes
This function inserts the coordinates into the <layername>_SDOGEOM table, tessel-
lates the geometry (creates the index), and returns a unique SDO_GID correspond-
ing to the geometry.
You do not need special privileges to execute this function. However, the user who
compiles it does need appropriate privileges to read and write into the database.
When working with Spatial Cartridge release 8.0.3 tables, the SDO_NUMTILES
parameter indicates the number of tiles into which the window should be tessel-
lated. For release 8.0.4 and later, the function reads that information from the
<layername>_SDOLAYER table.
Related Topics
■ SDO_WINDOW.BUILD_WINDOW_FIXED() function
SDO_WINDOW.BUILD_WINDOW_FIXED
Purpose
This function builds the window for the query and returns an SDO_GID that serves
as a handle. The window is tessellated into fixed-size tiles.
Syntax
SDO_WINDOW.BUILD_WINDOW_FIXED (comp_name, layername, SDO_ETYPE, SDO_TILESIZE,
X1, Y1, [...Xn, Yn])
Returns
This function returns the SDO_GID of the new geometry. Data type is NUMBER.
Usage Notes
This function inserts the coordinates into the <layername>_SDOGEOM table, tessel-
lates the geometry (creates the index), and returns a unique SDO_GID correspond-
ing to the geometry.
You do not need special privileges to execute this function. However, the user who
compiles it does need appropriate privileges to read and write into the database.
Query SDO_LEVEL from the <layername>_SDOLAYER table to pass the correct
SDO_TILE_SIZE value to this function.
Related Topics
None
SDO_WINDOW.CLEAN_WINDOW
Purpose
This procedure removes (drops) the four tables created in the layer for the query
window.
Syntax
SDO_WINDOW.CLEAN_WINDOW (layername);
Usage Notes
Typically, you would build a layer once, and then build multiple windows and per-
form multiple queries using that layer. After finishing all queries, you can execute
the SDO_WINDOW.CLEAN_WINDOW() procedure to remove the tables.
Related Topics
SDO_WINDOW.CLEANUP_GID
SDO_WINDOW.CLEANUP_GID
Purpose
This procedure removes the query window from the layer tables.
Syntax
SDO_WINDOW.CLEANUP_GID (layername, SDO_GID);
Usage Notes
Typically, you would create a query layer once, and then build multiple query win-
dows and perform multiple queries using that layer. The SDO_WINDOW.
CLEANUP_GID() procedure removes a single query window from the layer. Use
this procedure to avoid the overhead of removing and re-creating the tables repeat-
edly.
After finishing all queries, you can execute the SDO_WINDOW.
CLEAN_WINDOW()procedure to remove the tables.
Related Topics
SDO_WINDOW.CLEAN_WINDOW( )
SDO_WINDOW.CREATE_WINDOW_LAYER
Purpose
This procedure creates the necessary tables that constitute a layer used for defining
a query window.
Syntax
SDO_WINDOW.CREATE_WINDOW_LAYER (layername, SDO_LEVEL, SDO_NUMTILES,
SDO_DIMNUM1, SDO_LB1, SDO_UB1, SDO_TOLERANCE1, SDO_DIMNAME1, SDO_DIMNUM2,
SDO_LB2, SDO_UB2, SDO_TOLERANCE2, SDO_DIMNAME2)
Usage Notes
Because the <layername>_SDODIM table is initialized with the dimension and the
bound information, only those queries that are in the same dimension should be
queried against this layer. If you wish to issue a query with respect to a different
dimension, you must create a new layer.
Related Topics
None
Spatial Cartridge has undergone an architectural change, beginning with the 7.3.3
release. The emphasis on partitioned tables has been replaced by the improved spa-
tial indexing features.
The functions described in this chapter are not required for creating or maintaining
a spatial database, however, they are provided for convenience in working with leg-
acy data in partitioned point data tables. They are used with SQL SELECT, INSERT,
UPDATE, and DELETE statements to perform the following:
■ Generate dimensions from bounded, hierarchical, or date data values
■ Encode and decode dimensions
■ Retrieve bounded, hierarchical, or date data values from dimensions
When using these functions in basic SQL statements, use the form:
SDO_<function>. When using the functions inside a PL/SQL block, use a period (.)
instead of the underscore.
This chapter contains descriptions of the spatial functions listed in Table 9–1.
Additional functions that support partitioned point data can be found in Chapter 5,
“Administrative Procedures” and Appendix A, “Sample SQL Scripts and Tuning
Tips”.
SDO_BVALUETODIM
Purpose
This function creates a dimension from a bounded value, which is a value con-
tained in a set of values expressed as a lower boundary and an upper boundary.
Syntax
SDO_BVALUETODIM (value, lower_boundary, upper_boundary, decimal_scale)
Returns
This function returns a dimension. The data type is RAW.
Usage Notes
Example 9–1 shows the SDO_BVALUETODIM() function.
Example 9–1
SQL> INSERT INTO sourcetable1(SAMPLENAME,DATA_PT)
2> VALUES (’SAMPLE1’,SDO_ENCODE(SDO_BVALUETODIM(10,-100,100,7),
3> SDO_BVALUETODIM(20,-100,100,7));
Related Topics
■ SDO_ENCODE() function
■ SDO_TO_BVALUE() function
SDO_COMPARE
Purpose
This function evaluates the relationship between an area or point described by an
HHCODE and another HHCODE, or a range of HHCODEs expressed as an upper
bound and lower bound.
Syntax
SDO_COMPARE (hhcode_expression, {hhcode_expression |
lower_bound_HHCODE,upper_bound_HHCODE})
Returns
This function returns one of the following keywords:
■ ENCLOSES
■ EQUAL
■ INSIDE
■ OUTSIDE
■ OVERLAP
The data type is VARCHAR2.
Usage Notes
Example 9–2 selects all points that fall within the given multidimensional range.
Example 9–2
SQL> SELECT SDO_GID FROM layer1_SDOINDEX WHERE
2> SDO_COMPARE(SDO_MAXCODE,
3> SDO_ENCODE(5,5),
4> SDO_ENCODE(25,25))=’INSIDE’;
Example 9–3 selects GIDs based on interaction between their spatial index tiles.
Example 9–3
SQL> SELECT SDO_GID FROM layer1_SDOINDEX A, layer2_SDOINDEX B
2> WHERE SDO_COMPARE(A.SDO_CODE,B.SDO_CODE) != ’OUTSIDE’;
Related Topics
■ SDO_GEOM.INTERACT() function
■ SDO_GEOM.RELATE() function
SDO_DATETODIM
Purpose
This function creates a dimension from an Oracle DATE data type. The component
number determines the level of resolution of the date in the dimension.
Syntax
SDO_DATETODIM (date [, component])
Returns
This function returns a dimension. The data type is RAW.
Usage Notes
You must use a valid Oracle date format string.
Example 9–4 shows the SDO_DATETODIM() function.
Example 9–4
SQL> INSERT INTO sourcetable1(SAMPLENAME,DATA_PT)
2> VAUES(’SAMPLE1’,SDO_ENCODE(SDO_DATETODIM(TO_DATE(’19-Jul-96’),
3> SDO_BVALUETODIM(100,-1000,1000,7)));
Related Topics
■ SDO_ENCODE() function
■ SDO_TO_DATE() function
SDO_DECODE
Purpose
This function extracts a single dimension from an HHCODE.
Syntax
SDO_DECODE (hhcode_expression, dimension_number)
Returns
This function returns a dimension. The data type is RAW.
Usage Notes
The SDO_DECODE() function is called once for each dimension to be decoded.
Example 9–5 shows the SDO_DECODE() function.
Example 9–5
SQL> SELECT
2> SDO_TO_BVALUE(SDO_DECODE(DATA_PT,1),1,6),
3> SDO_TO_BVALUE(SDO_DECODE(DATA_PT,2),-100,100),
4> SDO_TO_DATE(SDO_DECODE(DATA_PT,3))
5> FROM sourcetable1 WHERE SAMPLENAME=’SAMPLE1’;
Related Topics
■ SDO_TO_BVALUE() function
■ SDO_TO_DATE() function
SDO_ENCODE
Purpose
This function combines dimensions to create the HHCODE that describes an area
or point.
Syntax
SDO_ENCODE (dimension1[,dimension2 ...])
Returns
This function returns an HHCODE. The data type is RAW.
Usage Notes
Consider the following when using this function:
■ When encoding dimensions, the order of the dimensions in the parameter list
must be consistent for all rows within the table.
■ This function can encode up to 32 dimensions.
Example 9–6 shows the SDO_ENCODE() function.
Example 9–6
SQL> INSERT INTO sourcetable1(SAMPLENAME,DATA_PT)
2> VALUES (’SAMPLE1’,SDO_ENCODE(SDO_BVALUETODIM(50,-100, 100, 10),
3> SDO_BVALUETODIM(30,-100,100,10),
4> SDO_DATETODIM(TO_DATE(’05-Jul-96’),3)));
Related Topics
■ SDO_BVALUETODIM() function
■ SDO_DATETODIM() function
SDO_TO_BVALUE
Purpose
This function returns the original bounded data value of a dimension.
Syntax
SDO_TO_BVALUE (dimension, lower_boundary, upper_boundary)
Returns
This function returns a bounded data value. The data type is NUMBER.
Usage Notes
This function returns a number that is the value for a dimension within the speci-
fied range. This is not necessarily the range for which the dimension was originally
created.
Example 9–7 shows the SDO_TO_BVALUE() function.
Example 9–7
SQL> SELECT (SDO_TO_BVALUE(SDO_DECODE(DATA_PT,2),-100,100)
2> FROM sourcetable1 WHERE SAMPLENAME=’SAMPLE1’;
Related Topics
■ SDO_DECODE() function
■ SDO_BVALUETODIM() function
SDO_TO_DATE
Purpose
This function returns the original date value of a dimension.
Syntax
SDO_TO_DATE (dimension)
Returns
This function returns an Oracle DATE data type.
Usage Notes
Example 9–8 shows the SDO_TO_DATE() function.
Example 9–8
SQL> SELECT SDO_TO_DATE(SDO_DECODE(DATA_PT,3))
2> FROM sourcetable1 WHERE SAMPLENAME=’SAMPLE1’;
Related Topics
■ SDO_DATETODIM() function
■ SDO_DECODE() function
--
declare
cursor c1 is SELECT DISTINCT sdo_gid from POLYGON_SDOGEOM;
gid number;
i number;
begin
i := 0;
for r in c1 loop
begin
gid:= r.sdo_gid;
sdo_admin.update_index_fixed(’POLYGON’, gid, 15, FALSE, FALSE, FALSE);
exception when others then
dbms_output.put_line(’error for gid’||to_char(gid)||’: ’||SQLERRM );
end;
i:= i + 1;
if i = 50 then
commit;
i:= 0;
end if;
end loop;
commit;
end;
/
■ altpart.sql
■ drppart.sql
■ sdogrant.sql
Although the scripts described in this section are available, the recommended
approach is to use Oracle8 partitioning and spatial indexing.
The DISTINCT clause is not necessary in the primary filter of the query because a
point contains only a single tile in the spatial index.
BEGIN
UPDATE points_sdogeom SET points_sdogeom.sdo_code = NULL
WHERE points_sdogeom.sdo_gid = :n.sdo_gid;
END;
The following example shows a window query of a layer containing point data
when the window layer contains one rectangle:
SELECT sdo_gid, sdo_x1, sdo_y1
FROM points_sdogeom a,
window_sdoindex b
WHERE b.sdo_gid = [area of interest id]
AND a.sdo_code = b.sdo_code)
AND sdo_x1 BETWEEN Xmin AND Xmax
AND sdo_y1 BETWEEN Ymin AND Ymax;
use_nl (a b) */
a.sdo_gid gid_a,
b.sdo_gid gid_b
FROM STREET_ADDRESS_SDOINDEX a,
MAJOR_ROAD_SDOINDEX b
WHERE a.sdo_code = b.sdo_code)
WHERE sdo_geom.relate('STREET_ADDRESS', gid_a, 'ANYINTERACT',
'MAJOR_ROAD',gid_b) <> 'FALSE'),
COUNTY_sdogeom
WHERE COUNTY_sdogeom.sdo_gid = gid1;
The inner DISTINCT clause is not necessary for spatial joins where one of the lay-
ers contains point data. Therefore, the NO_MERGE hint is not necessary. This is
because points contain only one tile in the spatial index.
The following example shows a spatial join between polygon (county) and point
(street address) data. The query generates a report that displays how many
addresses are associated with each county.
If you can assume that each street address is associated with a single county, you
can significantly speed up this query. Because points contain only a single tile in
the spatial index, any street address tile that matches only one county tile in the pri-
mary filter does not need to go through the expensive secondary filter.
SELECT county_gid, count(street_gid)
FROM (SELECT poly.sdo_gid county_gid, street.sdo_gid street_gid
FROM STREET_ADDRESS_sdoindex street,
(SELECT sdo_code county_sdo_code,
count(sdo_gid) interacts
FROM CENSUS_COUNTY_sdoindex
GROUP by sdo_code
) counts,
CENSUS_COUNTY_sdoindex poly
WHERE street.sdo_code = counts.county_sdo_code
AND poly.sdo_code = street.sdo_code
AND (counts.interacts = 1
OR
sdo_geom.relate('STREET_ADDRESS', street.sdo_gid,
'ANYINTERACT',
'CENSUS_COUNTY',poly.sdo_gid) <> 'FALSE'
)
)
GROUP BY county_gid;
linear quadtree is stored in the SDO_CODE column, and the metadata component
is stored in the SDO_META column.
The SDO_META column is not required for spatial queries. However, by combin-
ing the SDO_META column with the SDO_CODE column, the tiles of any geome-
try or of the entire data set can be decoded. This capability allows the tiles to be
visualized.
Two Spatial Cartridge internal functions have been made visible in order to
describe the tiles. These functions were part of a previous release of Oracle Spatial
Data Option, and are currently reserved for internal use only. The functions are not
recommended for general use, except for this visualization example. Use the follow-
ing syntax for the internal functions:
hhcellbndry (sdo_code || sdo_meta, sdo_dimnum, sdo_lb, sdo_ub,
hhlength(sdo_code || sdo_meta) {’MIN’ | ’MAX’})
In the following examples, the dimension boundaries were assumed to be -180 to
180, and -90 and 90. The dimensional information is stored in the <layer-
name>_SDODIM table.
If you used SDO_ADMIN.UPDATE_INDEX_FIXED() or
SDO_ADMIN.POPULATE_INDEX_FIXED() to generate your spatial index, replace
"sdo_code || sdo_meta" with sdo_tile in the SQL statements that follow.
The following SQL query can be used to decode all the index entries in a
<layername>_SDOINDEX table. The example returns the coordinates of the
lower-left and upper-right corners of each tile.
SELECT hhcellbndry (sdo_code || sdo_meta, 1, -180.000000000, 180.000000000,
hhlength (sdo_code || sdo_meta), 'MIN') min_x,
hhcellbndry (sdo_code || sdo_meta, 1, -180.000000000, 180.000000000,
hhlength (sdo_code || sdo_meta), 'MAX') max_x,
hhcellbndry (sdo_code || sdo_meta, 2, -90.000000000, 90.000000000,
hhlength (sdo_code || sdo_meta), 'MIN') min_y,
hhcellbndry (sdo_code || sdo_meta, 2, -90.000000000, 90.000000000,
hhlength (sdo_code || sdo_meta), 'MAX') max_y
FROM (SELECT DISTINCT sdo_code, sdo_meta FROM <layername>_sdoindex);
The following SQL query can be used to decode the index entries for a specific
geometry stored in a <layername>_SDOINDEX table:
SELECT hhcellbndry (sdo_code || sdo_meta, 1, -180.000000000, 180.000000000,
hhlength (sdo_code || sdo_meta), 'MIN') min_x,
hhcellbndry (sdo_code || sdo_meta, 1, -180.000000000, 180.000000000,
hhlength (sdo_code || sdo_meta), 'MAX') max_x,
The Spatial Cartridge data dictionary is a set of tables owned by the database user
mdsys. An extension to the Oracle8 data dictionary, it automatically maintains
information about spatial tables, columns, and partitions. The Spatial Cartridge
data dictionary is created during the installation process. All nonspatial attribute
information is maintained in the Oracle8 data dictionary.
The Spatial Cartridge data dictionary has public views that provide extensive infor-
mation about spatial tables. This appendix contains descriptions of the views that
are available.
Note: Only the partitioned point routines use the Spatial Car-
tridge data dictionary.
ALL_MD_COLUMNS
Returns a list of all columns that are part of spatial tables.
Column Description
OWNER owner of the object
MD_TABLE_NAME name of the spatial table
COLUMN_NAME name of the column
DATA_TYPE data type of the column
DATA_LENGTH length of the column in bytes
DATA_PRECISION scale for NUMBER data type, binary precision for
FLOAT data type, and NULL for all other data types
DATA_SCALE digits to right of decimal point in an HHCODE or a number
ALL_MD_DIMENSIONS
Returns a list of all dimensions that are part of HHCODE columns.
Column Description
OWNER owner of the object
MD_TABLE_NAME name of the spatial table
COLUMN_NAME name of the column
DIMENSION_NAME name of the dimension
DIMENSION_NUMBER dimension number
LOWER_BOUND lower boundary of the dimension range
UPPER_BOUND upper boundary of the dimension range
SCALE scale of the dimension
RECURSION_LEVEL number of levels encoded in the HHCODE
Column Description
OWNER owner of the object
NAME object name
OPERATION operation during which the failure occurred
CCHH common code HHCODE
ALL_MD_LOADER_ERRORS
Contains the current status of a file that was loaded into a table using SD*Loader.
Column Description
OWNER owner of the object
MD_TABLE_NAME spatial table name
FILENAME SLF file name
ROWS_LOADED number of rows loaded before failure
ALL_MD_PARTITIONS
Returns a list of all the partitioned tables that are part of a user-accessible spatial
table.
Column Description
OWNER owner of the object
MD_TABLE_NAME name of the spatial table
PARTITION_TABLE_NAME name of the partitioned table
CLASS class of partition: NODE or LEAF
COMMON_LEVEL number of levels of resolution of the common HHCODE for the
partition
COMMON_HHCODE common HHCODE substring for the partition
OFFLINE_STATUS status of partition: ONLINE or OFFLINE
ALL_MD_TABLES
Returns a list of all the user-accessible spatial tables.
Column Description
OWNER owner of the table
MD_TABLE_NAME name of the spatial table
CLASS class of table: PARTITIONED or NON-PARTITIONED
PTAB_SEQ number of last partitioned table created
HIGH_WATER_MARK maximum number of rows that can be inserted into a parti-
tioned table
OFFLINE_PATH complete path name to directory where the table is archived
COUNT_MODE count mode for estimating number of rows in a partition: ESTI-
MATE or EXACT
ALL_MD_TABLESPACES
Returns a list of all tablespaces used by spatial tables.
Column Description
OWNER owner of the object
MD_TABLE_NAME name of the spatial table
TABLESPACE_NAME name of tablespace
SEQUENCE sequence number
STATUS status of tablespace: ACTIVE or INACTIVE
DBA_MD_COLUMNS
Returns a list of all columns that are part of Spatial Cartridge tables.
Column Description
OWNER owner of the object
DBA_MD_DIMENSIONS
Returns a list of all dimensions that are a part of spatial tables.
Column Description
OWNER owner of the object
MD_TABLE_NAME name of the spatial table
COLUMN_NAME name of the column
DIMENSION_NAME name of the dimension
DBA_MD_EXCEPTIONS
Contains information about spatial tables that should be removed (dropped) as a
result of some failed operation, such as a failed load.
Column Description
OWNER owner of the object
NAME object name
OPERATION operation during which the failure occurred
CCHH common code HHCODE
DBA_MD_LOADER_ERRORS
Contains the current status of a file that was loaded into a table using SD*Loader.
Column Description
OWNER owner of the table where the error occurred
MD_TABLE_NAME spatial table name
FILENAME SLF file name
ROWS_LOADED number of rows loaded before failure
DBA_MD_PARTITIONS
Returns a list of all the partitioned tables.
Column Description
OWNER owner of the object
MD_TABLE_NAME name of the spatial table
DBA_MD_TABLES
Returns a list of all the spatial tables.
Column Description
OWNER owner of the table
MD_TABLE_NAME name of the spatial table
CLASS class of table: PARTITIONED or NON-PARTITIONED
PTAB_SEQ number of last partitioned table created
HIGH_WATER_MARK maximum number of rows that can be inserted into a parti-
tioned table
OFFLINE_PATH complete path name to directory where the table is archived
COUNT_MODE count mode for estimating number of rows in a partition: ESTI-
MATE or EXACT
DBA_MD_TABLESPACES
Returns a list of all tablespaces used by spatial tables.
Column Description
OWNER owner of the object
MD_TABLE_NAME name of the spatial table
TABLESPACE_NAME name of tablespace
SEQUENCE sequence number
STATUS status of tablespace: ACTIVE or INACTIVE
Column Description
MD_TABLE_NAME name of the spatial table
COLUMN_NAME name of the spatial table
DATA_TYPE data type of the column
DATA_LENGTH length of the column in bytes
DATA_PRECISION scale for NUMBER data type, binary precision for
FLOAT data type, and NULL for all other data types
DATA_SCALE digits to right of the decimal point in an HHCODE or a number
NDIM number of dimensions in the HHCODE column (It is NULL for
all other data types.)
MAX_LEVEL maximum number of levels in the column
NULLABLE indicates if column allows NULL values
PARTITION_KEY indicates if column is the partition key column; only one
allowed per partitioned table
COLUMN_ID sequence number of the column as created
DEFAULT_LENGTH length of the default value for the column
NUM_DISTINCT number of distinct values in each column of the table
LOW_VALUE lowest value for tables with three or fewer rows (It is the sec-
ond-lowest value in the column for tables with more than three
rows.)
HIGH_VALUE highest value for tables with three or fewer rows (It is the sec-
ond-highest value in the column for tables with more than three
rows.)
USER_MD_DIMENSIONS
Returns a list of all dimensions that are part of HHCODE columns owned by the
user.
Column Description
MD_TABLE_NAME name of the spatial table
USER_MD_EXCEPTIONS
Contains information about spatial tables that should be removed (dropped) as a
result of some failed operation, such as a failed load.
Column Description
NAME object name
OPERATION operation during which the failure occurred
CCHH common code HHCODE
USER_MD_LOADER_ERRORS
Contains the current status of a file that was loaded into a table using SD*Loader.
Column Description
MD_TABLE_NAME spatial table name
FILENAME SLF file name
ROWS_LOADED number of rows loaded before failure
USER_MD_PARTITIONS
Returns a list of all the partitioned tables that are part of spatial tables owned by
the user.
Column Description
MD_TABLE_NAME name of the spatial table
USER_MD_TABLES
Returns a list of all the spatial tables owned by the user.
Column Description
MD_TABLE_NAME name of the spatial table
CLASS class of table: PARTITIONED or NON-PARTITIONED
PTAB_SEQ number of last sequence created
HIGH_WATER_MARK maximum number of rows that can be inserted into
a partitioned table
OFFLINE_PATH complete path name to directory where the table is archived
COUNT_MODE count mode for estimating number of rows in a partition:
ESTIMATE or EXACT
USER_MD_TABLESPACES
Returns a list of all tablespaces used by spatial tables.
Column Description
MD_TABLE_NAME name of the spatial table
TABLESPACE_NAME name of tablespace
SEQUENCE sequence number
STATUS status of the tablespace: ACTIVE or INACTIVE
Additional error messages are documented in the Oracle8 Error Messages manual in
the range of 13000 to 13199.
area
An extent or region of dimensional space.
attribute
Descriptive information characterizing a geographical feature such as a point, line,
or area.
attribute data
Nondimensional data that provides additional descriptive information about multi-
dimensional data, for example a class or feature such as a bridge or a road.
boundary
1. The lower or upper extent of the range of a dimension, expressed by a numeric
value.
2. The line representing the outline of a polygon.
contain
To describe a geometric relationship where one object encompasses another and the
inner object does not touch any boundaries of the outer. The outer object contains
the inner object. See also inside.
Glossary-1
coordinate
A set of values uniquely defining a point in an n-dimensional coordinate system.
coordinate system
A reference system for the unique definition for the location of a point in n-dimen-
sional space.
cover
To describe a geometric relationship in which one object encompasses another and
the inner object touches the boundary of the outer object in one or more places.
data dictionary
A repository of information about data. A data dictionary stores relational informa-
tion on all the objects in a database.
decompose
To separate or resolve into constituent parts or elements, or into simpler com-
pounds.
dimensional data
Data that has one or more dimensional components and is described by multiple
values.
disjoint
A geometric relationship where two objects do not interact in any way. Two disjoint
objects do not share any element or piece of their geometry.
equal
A geometric relationship in which two objects are considered to represent the same
geometric figure. The two objects must be composed of the same number of points,
however, the ordering of the points defining the two objects’ geometries may differ
(clockwise or counter-clockwise).
extent
A rectangle bounding a map, the size of which is determined by the minimum and
maximum map coordinates.
feature
An object in a spatial database with a distinct set of characteristics.
Glossary-2
geographically referenced data
See spatiotemporal data.
georeferenced data
See spatiotemporal data.
GIS
See geographical information system.
grid
A data structure composed of points located at the nodes of an imaginary grid. The
spacing of the nodes is constant in both the horizontal and vertical directions.
HHCODE
A data type representing the intersection point of multiple dimensions. It encodes
these multiple dimensions into a unique, linear value. The HHCODEs are used for
both spatial indexing and partitioned point data.
high-water mark
Expressed in number of records and associated with Spatial Cartridge partitioned
table structure, it defines the maximum number of records to store in a table before
decomposing another level. The high-water mark determines the maximum size of
a partition within the Spatial Cartridge table. Partitioned tables are an alternative to
spatial indexing.
hole
A polygon can include subelements that negate sections of its interior. For example,
consider a polygon representing a map of a buildable land with an inner polygon
(a hole) representing where a lake is located.
homogeneous
Spatial data of one feature type such as points, lines, or regions.
Glossary-3
hyperspatial data
In mathematics, any space comprising more than the three standard x, y, and z
dimensions, also referred to as multidimensional data.
index
Identifier that is not part of a database and used to access stored information.
inside
To describe a geometric relationship where one object is surrounded by a larger
object and the inner object does not touch the boundary of the outer. The smaller
object is inside the larger. See also contain.
key
A field in a database used to obtain access to stored information.
keyword
Synonym for reserved word.
latitude
North/South position of a point on the Earth defined as the angle between the nor-
mal to the Earth’s surface at that point and the plane of the equator.
line
A geometric object represented by a series of points, or inferred as existing between
two coordinate points.
longitude
East/West position of a point on the Earth defined as the angle between the plane
of a reference meridian and the plane of a meridian passing through an arbitrary
point.
multidimensional data
See hyperspatial data.
partition
1. The spatial table that contains data only for a unique bounded n-dimensional
space.
2. The process of grouping data into partitions that maintain the dimensional
organization of the data.
Glossary-4
partition key column
The primary HHCODE column that is used to dimensionally partition the data.
One HHCODE data type column must be identified as the partition key for the
table to be registered as partitionable in the Spatial Cartridge data dictionary. There
can only be one partition key per spatial table. Note that this is only used for parti-
tioned point data, and not spatially indexed data.
partitioned table
The spatial logical table structure that contains one or more partitions. Use parti-
tioned tables only if you are dealing with a very large amount of point data (over
50 GB).
polygon
A class of spatial objects having a nonzero area and perimeter, and representing a
closed boundary region of uniform characteristics.
proximity
A measure of inter-object distance.
query
A set of conditions or questions that form the basis for the retrieval of information
from a database.
query window
Area within which the retrieval of spatial information and related attributes is per-
formed.
RDBMS
See Relational Database Management System.
recursion
A process, function, or routine that executes continuously until a specified condi-
tion is met.
region
An extent or area of multidimensional space.
Glossary-5
Relational Database Management System (RDBMS)
A computer program designed to store and retrieve shared data. In a relational sys-
tem, data is stored in tables consisting of one or more rows, each containing the
same set of columns. Oracle8 is a relational database management system. Other
types of database systems are called hierarchical or network database systems.
resolution
The number of subdivision levels of data.
scale
1. The number of digits to the right of the decimal point in a number representing
the level of resolution of an HHCODE.
2. The ratio of the distance on a map, photograph, or image to the corresponding
image on the ground, all expressed in the same units.
SD*Converter
A utility used with previous versions of Spatial Data Option to prepare data for
loading into spatial tables. Loading is now accomplished through SQL*Loader.
SLF
See Spatial Load Format.
sort
The operation of arranging a set of items according to a key that determines the
sequence and precedence of items.
spatial
A generic term used to reference the mathematical concept of n-dimensional data.
spatial data
Data that is referenced by its location in n-dimensional space. The position of spa-
tial data is described by multiple values. See also hyperspatial data.
spatial database
A database containing information indexed by location.
Glossary-6
Spatial Cartridge data dictionary
An extension of the Oracle8 data dictionary. It keeps track of the number of parti-
tions created in a spatial table. The Spatial Cartridge data dictionary is owned by
user mdsys. The data dictionary is used only by the partitioned point routines.
spatial query
A query that includes criteria for which selected features must meet location condi-
tions.
spatiotemporal data
Data that contains time and/or location components as one of its dimensions, also
referred to as geographically referenced data or georeferenced data.
SQL*Loader
A utility to load formatted data into spatial tables.
tessellation
The process of covering a geometry with rectangular tiles without gaps or overlaps.
tiling
See tessellation.
touch
To describe a geometric relationship where two objects share a common point on
their boundaries, but their interiors do not intersect.
Glossary-7
Glossary-8
Index
A cr_spatial_index.sql A-1
CREATE_WINDOW_LAYER 8-8
ADD_NODES 7-2 creating layer tables A-2
administrative procedures 5-1 crlayer.sql A-2
ALTER_HIGH_WATER_MARK 5-14
altering partitions A-3
altpart.sql A-3 D
ANYINTERACT 7-8 data Glossary-2
arcs A-11 data dictionary B-1
area Glossary-1 data model 1-3
attribute Glossary-1 DATE data type 9-6, 9-11
decompose Glossary-2
B dimensional Glossary-2
disjoint 7-6, 7-9, Glossary-2
boundary Glossary-1 DROP_PARTITION_INFO 5-15
bounded data 9-10 dropping partitions A-3
bounded value 9-3 drppart.sql A-3
BUILD_WINDOW 8-2 dynamic query window 3-5
BUILD_WINDOW_FIXED 8-4
bulk loading 2-2
E
C element 1-3
ENCLOSES 9-4
Cartesian Glossary-1 encoding dimensions 9-9
circles A-11 EQUAL 7-9, 9-4, Glossary-2
CLEAN_WINDOW 8-6 error messages C-1
CLEANUP_GID 8-7 ESTIMATE_TILING_LEVEL 6-2
consistency check 7-10 extent 6-5, Glossary-2
CONTAINS 7-8, Glossary-1 EXTENT_OF 6-5
control file 2-2 extracting a dimension 9-8
coordinate Glossary-2
coordinate system 7-2, Glossary-2
COVEREDBY 7-8 F
COVERS 7-8, Glossary-2 feature Glossary-2
Index-1
filter 3-7 M
fixed-size tiles 2-9, 5-4, 5-10
minimum bounding rectangle 6-5
G
O
Geographical Information System Glossary-3
geometric objects 1-3 OUTSIDE 9-4
geometric primitive 1-2 OVERLAP 9-4
georeferenced Glossary-3 OVERLAPBDYDISJOINT 7-9
GIS 1-1, Glossary-3 OVERLAPBDYINTERSECT 7-9
grants 5-18, A-3
grid Glossary-3 P
partition 5-16, Glossary-4, Glossary-5
H partition key 4-1
partitioned table 4-1, 5-15, 5-16, 5-19, A-3,
HHCODE Glossary-3
Glossary-5
high water mark 5-14, Glossary-3
partitioned tables 1-17
hole in a polygon 2-7, Glossary-3
PL/SQL 9-1
homogeneous Glossary-3
plotting tiles A-11
hyperspatial Glossary-4
point data 1-3, 4-1
polygon Glossary-5
I polygon data 1-3
index 5-2, 5-4, 5-8, 5-10, Glossary-4 POPULATE_INDEX 5-2
index creation 2-8 POPULATE_INDEX_FIXED 5-4
INIT_ELEMENT 7-4 primary filter 3-7
inserting spatial data 2-4 primitive 1-2
INSIDE 7-9, 9-4 PROPAGATE_GRANTS 5-18
INTERACT 7-5 proximity Glossary-5
interaction 7-8
Q
K query Glossary-5
key Glossary-4 query window 3-5, Glossary-5
keyword Glossary-4
R
L RDBMS Glossary-5, Glossary-6
latitude Glossary-4 recursion Glossary-5
layer 1-4, A-2 region Glossary-5
line Glossary-4 REGISTER_PARTITION_INFO 5-19
line data 1-3 RELATE 7-7
loading process 2-2 REPARTITION 5-20
location 1-1 resolution Glossary-6
longitude Glossary-4
Index-2
S V
scale Glossary-6 VALIDATE_GEOMETRY 7-10
schema 1-4 VERIFY_LAYER 5-12
SD*Converter Glossary-6 VERIFY_PARTITIONS 5-22
SD*Loader Glossary-7 visualizing tiles A-11
SDO_BVALUETODIM 9-3
SDO_CODE_SIZE 5-7
SDO_COMPARE 9-4
SDO_DATETODIM 9-6
SDO_DECODE 9-8
SDO_ENCODE 9-9
SDO_TO_BVALUE 9-10
SDO_TO_DATE 9-11
sdogrant.sql A-3
secondary filter 3-8
server partitioning 4-1
SLF Glossary-6
sort Glossary-6
Spatial Glossary-7
spatial Glossary-6, Glossary-7
spatial data model Glossary-6
spatial database Glossary-6
spatial index 1-8, 2-8, 5-8, 5-10
spatial join 3-9
Spatial Load Format Glossary-7
spatial query 3-5, Glossary-7
spatiotemporal Glossary-7
SQL script A-1, A-2
SQL*Loader 2-2
T
table partitioning 1-17, 4-1
tessellation 1-9, 2-8, 5-2, 5-4, 5-8, 5-10,
Glossary-7
tile 1-9, 3-2
tiling 5-10, 6-2, A-4, Glossary-7
TOUCH 7-9, Glossary-7
transactional insert 2-4
two-tier query 3-1
U
UPDATE_INDEX 5-8
UPDATE_INDEX_FIXED 5-10
Index-3