Oracle Create Sdo_geometry Table

Source: Internet
Author: User

Oracle Spatial is composed of a lump of object data types, type methods, operators, functions and processes. A geographic object is stored as a Sdo_geometry object in a field in the table. Spatial indexes are established and maintained by Common DDL and DML statements.
This chapter focuses on some examples of how to create, query, and index spatial data.

Simple Insert, index and query spatial data examples
This section demonstrates a very simple process of creating spatial tables, inserting, indexing, and querying data.
The scene is a soft-drink company that uses geographic information to represent the situation of their products (COLA) in various regions. These can be: market share, competitive pressure, growth potential and so on. The region can be a neighboring city, state, province, or country.
What we are going to do is:
1. Create a table (Cola_markets) to save spatial data
2. Insert data from four (cola_a, Cola_b, Cola_c, Cola_d) regions
3. Upgrade the User_sdo_geom_metadata view to the dimension information for these areas anyway
4. Building a spatial index (COLA_SPATIAL_IDX)
5. Make some spatial queries

[SQL]View PlainCopy
    1. CREATE TABLE cola_markets (
    2. mkt_id number PRIMARY KEY,
    3. name VARCHAR2 (+),
    4. Shape sdo_geometry);

[SQL]View PlainCopy
  1. INSERT into cola_markets VALUES (
  2. 1,
  3. ' cola_a ',
  4. Sdo_geometry (
  5. 2003, --two-dimensional polygon
  6. NULL,
  7. NULL,
  8. Sdo_elem_info_array (1,1003,3), --one rectangle (1003 = exterior)
  9. Sdo_ordinate_array (5,7) --only 2 points needed to
  10. --Define rectangle (lower left and upper right) with
  11. --Cartesian-coordinate data
  12. )
  13. );
  14. --The next and the INSERT statements create areas of interest for
  15. --Cola B and Cola C. These areas is simple polygons (and not
  16. --rectangles).
  17. INSERT into cola_markets VALUES (
  18. 2,
  19. ' Cola_b ',
  20. Sdo_geometry (
  21. 2003, --two-dimensional polygon
  22. NULL,
  23. NULL,
  24. Sdo_elem_info_array (1,1003,1), --one polygon (exterior polygon ring)
  25. Sdo_ordinate_array (5,1, 8, 1, 8, 6, 5, 7, 5,1)
  26. )
  27. );
  28. INSERT into cola_markets VALUES (
  29. 3,
  30. ' Cola_c ',
  31. Sdo_geometry (
  32. 2003, --two-dimensional polygon
  33. NULL,
  34. NULL,
  35. Sdo_elem_info_array (1,1003,1), --one polygon (exterior polygon ring)
  36. Sdo_ordinate_array (3,3, 6, 3, 6, 5, 4, 5, 3,3)
  37. )
  38. );
  39. --now insert a area of interest for Cola D. This is a
  40. --circle with a radius of 2. It is completely outside the
  41. --first three areas of interest.
  42. INSERT into cola_markets VALUES (
  43. 4,
  44. ' Cola_d ',
  45. Sdo_geometry (
  46. 2003, --two-dimensional polygon
  47. NULL,
  48. NULL,
  49. Sdo_elem_info_array (1,1003,4), - -One circle
  50. Sdo_ordinate_array (8,7, 10, 9, 8,11)
  51. )
  52. );


You need to write information about the spatial layer of the established table into a user_sdo_geom_metadata

[SQL]View PlainCopy
  1. INSERT into user_sdo_geom_metadata
  2. (TABLE_NAME,
  3. COLUMN_NAME,
  4. Diminfo,
  5. SRID)
  6. VALUES (
  7. ' Cola_markets ',
  8. ' shape ',
  9. Sdo_dim_array ( --20X20 grid
  10. Sdo_dim_element (' X ', 0, 0.005),
  11. Sdo_dim_element (' Y ', 0, 0.005)
  12. ),
  13. NULL --SRID
  14. );
[SQL]View PlainCopy
    1. --SRID

User_sdo_geom_metadata after landing PL/SQL, users→mdsys→objects→views→user_sdo_geom_metadata

Open to view (I have inserted 2 records of the spatial table)

You can see this inserted record, click on any one of the red squares, and it will appear:

[SQL]View PlainCopy
    1. Sdo_dim_array ( --20X20 grid
    2. Sdo_dim_element (' X ', 0, 0.005),
    3. Sdo_dim_element (' Y ', 0, 0.005)
    4. ),


This is the meaning of SQL, where Sdo_dimname is a two-dimensional maximum and minimum value of the description, SDO_LB is the minimum value above x, Sdo_ub is the maximum value above X, sdo_tolerance refers to the size of the error, This means that data in 0.005 will default to one data.

The fourth step is to create a spatial index (COLA_SPATIAL_IDX)

[SQL]View PlainCopy
    1. CREATE INDEX Cola_spatial_idx
    2. On cola_markets (shape)
    3. Indextype is Mdsys.  Spatial_index;


The purpose of indexing is to increase the query speed (in theory, you can not set up the index to query, but the actual basic cannot query out)

When the index is established, the following table is generated in tables:

This is an index table:

Can be found in the system's Index table.

The above is created to complete the Sdo_geometry table, you can start the spatial analysis.

Oracle Create Sdo_geometry Table

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.