10.12.2012 Views

Oracle Spatial User's Guide and Reference - InfoLab

Oracle Spatial User's Guide and Reference - InfoLab

Oracle Spatial User's Guide and Reference - InfoLab

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Querying <strong>Spatial</strong> Data<br />

evaluated against the PARKS table. Thus, the SDO_WITHIN_DISTANCE operation<br />

is performed n times if there are n rows in the COASTLINES table.<br />

For non-geodetic data, there is an efficient way to accomplish a spatial join that<br />

involves buffering all geometries of a layer. This method does not use the SDO_<br />

WITHIN_DISTANCE operator. First, create a new table COSINE_BUFS as follows:<br />

CREATE TABLE cosine_bufs UNRECOVERABLE AS<br />

SELECT SDO_BUFFER (A.SHAPE, B.DIMINFO, 1.35)<br />

FROM COSINE A, USER_SDO_GEOM_METADATA B<br />

WHERE TABLE_NAME='COSINES' AND COLUMN_NAME='SHAPE';<br />

Next, create a spatial index on the SHAPE column of COSINE_BUFS. Then you can<br />

perform the following query:<br />

SELECT a.gid, b.gid FROM parks a, cosine_bufs b,<br />

TABLE(SDO_JOIN('PARKS', 'SHAPE', 'COSINE_BUFS', 'SHAPE',<br />

'mask=ANYINTERACT')) c<br />

WHERE c.rowid1 = a.rowid AND c.rowid2 = b.rowid;<br />

4.2.1.4 Nearest Neighbor Operator<br />

The SDO_NN operator, described in Chapter 12, is used to identify the nearest<br />

neighbors for a geometry. This operator can be used only if a spatial index has been<br />

created on two dimensions of data. The syntax of the operator is as follows:<br />

SDO_NN(geometry1 SDO_GEOMETRY,<br />

geometry2 SDO_GEOMETRY,<br />

param VARCHAR2<br />

[, number NUMBER]);<br />

In the preceding syntax:<br />

■ geometry1 is a column of type SDO_GEOMETRY in a table. This column must<br />

be spatially indexed.<br />

■ geometry2 is an instance of type SDO_GEOMETRY.<br />

■ param is a quoted string of a keyword value pair that determines how many<br />

nearest neighbor geometries are returned by the operator. See the SDO_NN<br />

operator in Chapter 12 for information about this parameter.<br />

■ number is the same number used in the call to SDO_NN_DISTANCE. Use this<br />

only if the SDO_NN_DISTANCE ancillary operator is included in the call to<br />

SDO_NN. See the SDO_NN operator in Chapter 12 for information about this<br />

parameter.<br />

Indexing <strong>and</strong> Querying <strong>Spatial</strong> Data 4-15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!