Oracle Spatial table creation learning steps

Source: Internet
Author: User

Oracle Spatial table creation LearningThe steps are as follows:

Step 1. Create a table where shape is used to store space data.

 
 
  1. CREATE TABLE mylake (  
  2. feature_id NUMBER PRIMARY KEY,  
  3. name VARCHAR2(32),  
  4. shape MDSYS.SDO_GEOMETRY); 

Step2. in user_sdo_geom_metadata Insert a new record to the table to describe the space field.

 
 
  1. Insert into user_sdo_geom_metadata VALUES (
  2. 'Mylake ', // --- table name
  3. 'Shape', // --- field name
  4. MDSYS. SDO_DIM_ARRAY (
  5. MDSYS. SDO_DIM_ELEMENT ('x', 0,100, 0.05), // --- minimum, maximum, and tolerance of X dimension.
  6. MDSYS. SDO_DIM_ELEMENT ('y', 0,100, 0.05) // --- minimum Y dimension, maximum value and tolerance NULL // --- coordinate system, Cartesian coordinate system by default
  7. );

Step 3: Create a spatial index

 
 
  1. CREATE INDEX mylake_idx ON mylake(shape)   
  2. INDEXTYPE IS MDSYS.SPATIAL_INDEX 

Step 4. insert Space Data

Oracle Spatial uses MDSYS. SDO_GEOMETRY to store Spatial data, defined:

 
 
  1. CREATE TYPE sdo_geometry AS OBJECT (  
  2. SDO_GTYPE NUMBER,  
  3. SDO_SRID NUMBER,  
  4. SDO_POINT SDO_POINT_TYPE,  
  5. SDO_ELEM_INFO MDSYS.SDO_ELEM_INFO_ARRAY,  
  6. SDO_ORDINATES MDSYS.SDO_ORDINATE_ARRAY); 

SDO_SRID: Coordinate System. NULL is the Cartesian coordinate system. SDO_POINT: Oracle Spatial can also define a single point. SDO_POINT defines create type sdo_point_type as object (x number, y number, z number). If it is two-dimensional, Z is NULL. SDO_ELEM_INFO: each three values describe an element. Value 1: The first vertex starts at SDO_ORDINATES_ARR. Second value: Element type. Third value: vertex connection method: 1-through a straight line connection, 2-through an Arc Connection: defined as create type sdo_elem_info_array as varray (1048576) of NUMBER; SDO_ORDINATES: list of all vertices in the ry. It is defined as create type sdo_ordinate_array as varray (1048576) of NUMBER;

// Insert a lake containing an island

 
 
  1. INSERT INTO mylake VALUES(  
  2. 10,   
  3. 'Lake Calhoun',   
  4. MDSYS.SDO_GEOMETRY(  
  5. 2003,  
  6. NULL,  
  7. NULL,  
  8. MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1, 19,2003,1),  
  9. MDSYS.SDO_ORDINATE_ARRAY(0,0, 10,0, 10,10, 0,10, 0,0, 4,4, 6,4, 6,6, 4,6, 4,4)  
  10. )); 

// Insert two boats

 
 
  1. INSERT INTO mylake VALUES(  
  2. 11,   
  3. 'The Windswept',   
  4. MDSYS.SDO_GEOMETRY(  
  5. 2003,  
  6. NULL,  
  7. NULL,  
  8. MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1),  
  9. MDSYS.SDO_ORDINATE_ARRAY(2,2, 3,2, 3,2, 2,3, 2,2) ); INSERT INTO mylake VALUES(  
  10. 12,   
  11. 'Blue Crest',   
  12. MDSYS.SDO_GEOMETRY(  
  13. 2003,  
  14. NULL,  
  15. NULL,  
  16. MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1),  
  17. MDSYS.SDO_ORDINATE_ARRAY(7,7, 8,7, 8,7, 7,8, 7,7) ); 

Step 4. QueryOracle Spatial queries data in two processing processes: 1. query candidate items only through the index. Implemented through the SDO_FILTER function: SDO_FILTER (geometry1 MDSYS. SDO_GEOMETRY, geometry2 MDSYS. SDO_GEOMETRY, params VARCHAR2) geometry1: it must be the indexed geometric data geometry2: it is not necessarily a space field in the table, nor is it required to be indexed params: Filter Type querytype = WINDOW: geometry2 does not require querytype = JOIN: geometry2 must be from the table.

 
 
  1. SELECT name boat_name  
  2. FROM mylake t  
  3. WHERE feature_id = 12 
  4. AND SDO_FILTER(t.shape, mdsys.sdo_geometry(2003,NULL,NULL,  
  5. mdsys.sdo_elem_info_array(1,1003,1),  
  6. mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)),'querytype=WINDOW') = 'TRUE';  

// Select all boats in the defined rectangle

 
 
  1. SELECT name boat_name  
  2. FROM mylake t  
  3. WHERE feature_id = 12 
  4. AND SDO_FILTER(t.shape, mdsys.sdo_geometry(2003,NULL,NULL,  
  5. mdsys.sdo_elem_info_array(1,1003,1),  
  6. mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)),  
  7. 'querytype=WINDOW') = 'TRUE'  
  8. AND SDO_RELATE(t.shape, mdsys.sdo_geometry(2003,NULL,NULL,  
  9. mdsys.sdo_elem_info_array(1,1003,1),  
  10. mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)),  
  11. 'masktype=INSIDE querytype=WINDOW') = 'TRUE' 

// Masktype can be used together

 
 
  1. SELECT feature_id id  
  2. FROM mylake t  
  3. WHERE feature_id = 12 
  4. AND SDO_FILTER(t.shape, mdsys.sdo_geometry(2003,NULL,NULL,  
  5. mdsys.sdo_elem_info_array(1,1003,1),  
  6. mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)),  
  7. 'querytype=WINDOW') = 'TRUE'  
  8. AND SDO_RELATE(t.shape, mdsys.sdo_geometry(2003,NULL,NULL,  
  9. mdsys.sdo_elem_info_array(1,1003,1),  
  10. mdsys.sdo_ordinate_array(2,2, 5,2, 5,5, 2,5, 2,2)),  
  11. 'masktype=INSIDE+TOUCH querytype=WINDOW') = 'TRUE' 

This article introduces the knowledge of Oracle Spatial table creation and learning!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.