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.

SDO_GEOMETRY Objects in Function-Based Indexes<br />

create or replace function get_long_lat_pt(longitude in number,<br />

latitude in number)<br />

return SDO_GEOMETRY deterministic is<br />

begin<br />

return sdo_geometry(2001, 8307,<br />

sdo_point_type(longitude, latitude, NULL),NULL, NULL);<br />

end;<br />

/<br />

If the spatial data table does not already exist, create the table <strong>and</strong> add data to it, as<br />

in the following example that creates a table named LONG_LAT_TABLE:<br />

create table LONG_LAT_TABLE<br />

(longitude number, latitude number, name varchar2(32));<br />

insert into LONG_LAT_TABLE values (10,10, 'Place1');<br />

insert into LONG_LAT_TABLE values (20,20, 'Place2');<br />

insert into LONG_LAT_TABLE values (30,30, 'Place3');<br />

Update the USER_SDO_GEOM_METADATA view, using dot-notation to specify<br />

the schema name <strong>and</strong> function name. The following example specifies SCOTT.GET_<br />

LONG_LAT_PT(LONGITUDE,LATITUDE) as the COLUMN_NAME (explained in<br />

Section 2.4.2) in the metadata view.<br />

-- Set up the metadata entry for this table.<br />

-- The column name sets up the function on top<br />

-- of the two columns used in this function,<br />

-- along with the owner of the function.<br />

insert into user_sdo_geom_metadata values('LONG_LAT_TABLE',<br />

'scott.get_long_lat_pt(longitude,latitude)',<br />

sdo_dim_array(<br />

sdo_dim_element('Longitude', -180, 180, 0.005),<br />

sdo_dim_element('Latitude', -90, 90, 0.005)), 8307);<br />

Create the spatial index, specifying the function name with parameters. For<br />

example:<br />

create index LONG_LAT_TABLE_IDX on<br />

LONG_LAT_TABLE(get_long_lat_pt(longitude,latitude))<br />

indextype is mdsys.spatial_index;<br />

Perform queries on the data. In the following example, the two queries accomplish<br />

the same thing; however, the first query does not use a user-defined function<br />

(instead using a constructor to specify the point), whereas the second query uses the<br />

function to specify the point.<br />

Extending <strong>Spatial</strong> Indexing Capabilities 9-5

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

Saved successfully!

Ooh no, something went wrong!