深入浅出Oracle Spatial

空间数据库(Spatial Database)用于存储、查询点、线、面的空间对象。

 

为什么需要空间数据库(组件)

做一个区域的人口普查,不仅仅记录人口信息,还需要记录区域地理信息,通过空间数据库字段可以非常快速实现记录和查询。

普通的数据库存储也能做,但因为不能存储复杂的空间几何信息,但方案就非常复杂了,对于上图的人口普查,至少需要三张表来实现。

 

主流空间数据的存储解决方案

不同数据库空间支持和应用情况的对比可见:

Compare SQL Server 2008 R2, Oracle 11G R2, PostgreSQL/PostGIS 1.5 Spatial Features

GIS: PostGIS/PostgreSQL vs. MySql vs. SQL Server?

毫无疑问,PostgreSQL+PostGIS是当前最主流的地理存储解决方案了,PostgreSQL性能表现优异,而且最重要还免费,怎么可能不流行。

(但因为所在公司历史情况,基本都用的是Oracle数据库,所以我们还必须采用Oracle Spatial作为我们的地理信息存储方式)。

 

Oracle Spatial

Oracle Spatial 是Oracle企业版提供的一个扩展产品,它具有专门的空间数据管理功能,用于存储、查询点、线、面的空间对象。

ps: MapViewer is a J2EE service for rendering maps using spatial data managed by Oracle’s Spatial option. MapViewer hides the complexity of spatial data queries and cartographic rendering.

 

Oracle Spatial的版本进化

Oracle Spatial was previously known as SDO and before that as MultiDimension. A brief history:

  • Spatial data capabilities as modification shipped by scientists working with the Canadian Hydrographic Service (CHS) to Oracle 4.

  • Spatial Data Option (SDO) shipped in Oracle 7.3.3.

  • Spatial introduced it’s object type in Oracle 8.1.5.

  • Spatial added Java Classes, Projections, Linear Referencing and R-Tree Indexing in Oracle 8.1.7.

  • Spatial added Whole Earth Geometry Model, Function-based indexes, Object replication, Partitioning in Oracle 9i.

  • Spatial added Geocoder, GeoRaster, Network Data Model, Topology, Spatial Analytic Functions and Routing engine in Oracle 10g.

  • Spatial added 3D Support and Web Services in Oracle 11g.

  • Oracle Application Server MapViewer first shipped in AS 9.0.2

  • MapViewer current release is FMW Version 10.1.3.3 Patch 5

 

 

Oracle Spatial License

Oracle Spatial is only available with Oracle Enterprise Edition as a separately licensed option.

见:Licensing Information

 

Oracle Spatial支持的空间几何类型

Oracle Spatial提供了三种最主要的几何类型(点、线、面世以及由这些几何类型对象组合而成的集合。这三种几何类型又可分为简单点(只有一个点)、点群(有多个点)、简单线(只有一条线)、线群(有多条线)、简单面(只有一个面)、面群(有多个面)。

 

Oracle Spatial Architecture

Overview of Oracle Spatial:www.oracle.com/technetwork/testcontent/spatial-ch2-129768.pdf

 

• Data model: Oracle Spatial uses a SQL data type, SDO_GEOMETRY, to store spatial data inside an Oracle database. Users may define tables containing columns of type SDO_GEOMETRY to store the locations of customers, stores, restaurants, and so on, or the locations and spatial extents of geographic entities such as roads, interstates, parks, and land parcels. This data type is described in detail in Chapter 4.

 

• Location enabling: Users can add SDO_GEOMETRY columns to application tables. This process is described in detail in Chapter 3. Users can populate the tables with SDO_GEOMETRY data using standard Oracle utilities such as SQL*Loader, Import, and Export. This process is described in Chapter 5. Alternatively, users can convert implicit spatial information,such as street addresses, into SDO_GEOMETRY columns using the geocoder component of Oracle Spatial, as described in Chapter 6.

 

• Spatial query and analysis: Users can query and manipulate the SDO_GEOMETRY data using the query and analysis component, comprising the Index and Geometry Engines. Full details of this process are given in Chapters 8 and 9.

 

• Advanced Spatial Engine: This component comprises several components that cater to sophisticated spatial applications, such as GIS and bioinformatics. This includes, for example, the GeoRaster component that allows storage of spatial objects using images (groups of pixels) rather than points, lines, and vertices. These components are covered in Appendixes A through D.

• Visualization: The Application Server components of Oracle’s spatial technology include the means to visualize spatial data via the MapViewer tool. MapViewer renders the spatial data that is stored in SDO_GEOMETRY columns of Oracle tables as displayable maps. This feature is described in detail in Chapter 11

 

一个最简单的示例-地图POI及地理坐标

建表

CREATE TABLE us_restaurants_new

(

    id NUMBER,

    poi_name VARCHAR2(32),

    location SDO_GEOMETRY — New column to store locations

);

插入样例记录

INSERT INTO us_restaurants_new VALUES

(

    1,

    ‘PIZZA HUT’,

    SDO_GEOMETRY

    (

        2001, — SDO_GTYPE attribute: “2” in 2001 specifies dimensionality is 2.

        NULL, — other fields are set to NULL.

        SDO_POINT_TYPE — Specifies the coordinates of the point

        (

        -87, — first ordinate, i.e., value in longitude dimension

        -78, — second ordinate, i.e., value in latitude dimension

        NULL — third ordinate, if any

        ),

    NULL,

    NULL

    )

);

 

数据模型 – SDO_GEOMETRY

Oracle Spatial的空间数据都存储在空间字段SDO_GEOMETRY中,理解SDO_GEOMETRY是编写Oracle Spatial程序的关键。

 

Oracle Spatial定义的SDO_GEOMETRY类型为:

      CREATE TYPE SDO_GEOMETRY AS OBJECT (

                     SDO_GTYPE   NUMBER,  //前面字符串为字段名;后面字符串为字段类型

                     SDO_SRID    NUMBER,

                     SDO_POINT    SDO_POINT_TYPE,

                     SDO_ELEM_INFO    SDO_ELEM_INFO_ARRAY,

                     SDO_ORDINATES    SDO_ORDINATE_ARRAY);

      其中SDO_GEOMETRY AS OBJECT ,标识该类型为对象类型。

 

SDO_GEOMETRY是按照Open GIS规范定义的一个对象,其原始的创建方式如下所示。

SDO_GEOMETRY中各字段类型说明建议阅读:《Oracle Spatial空间信息管理》第4章SDO_GEOMETRY数据类型

1、SDO_GTYPE :表示要存储的几何类型,如点线面。它是通过 NUMBER类型来表达的;

2、SDO_SRID :几何的空间参考坐标系,类型也为 NUMBER;

3、SDO_POINT :如果几何类型点类型的话,就是存储点坐标,否则为空。oracle自定义的SDO_POINT_TYPE类型;

4、SDO_ELEM_INFO :定义要如何理解SDO_ORDINATES中的坐标串的;

5、SDO_ORDINATES :存储实际坐标的,以X、Y以及不同点之间都是逗号隔开;

 

属性:SDO_GTYPE

描述建模对象的几何形状类型, 通过不同的值来决定所表示的几何体是点、线串、多边形、多重点、多重多边形、多重线串还是一个任意的集合,比如:2003,2001,3006。 SDO_GTYPE是一个4位的数字,结构为D00T。第一位和最后一位根据几何体的维数和形状采用不同的值,如表4-1所示。第二位和第三位通常被设成0。

D(几何体的维度)

2 =二维,3 =三维,4 =四维

T(几何体的形状/类型)

0 =无解释类型,1 =点,5 =多重点,

2 =线串,6 =多重线串,3 =多边形/面,

7 =多重多边形/多重面,4 =集合,

8 =立方体,9 =多重立方体

属性:SDO_SRID

SDO_SRID定义了空间坐标参考系统。如果SDO_SRID为null,则没有指定坐标系统,如果SDO_SRID不为null,那么它的值必须在在MDSYS.CS_SRS 表中的 SRID 列有对应的值,而且它的值必须插入USER_SDO_GEOM_METADATA视图中。

 

属性:SDO_POINTS

详见:http://book.51cto.com/art/200910/157432.htm

  1. SQL> INSERT INTO geometry_examples (name, description, geom) VALUES 

  2. (  

  3.   ‘POINT’,  

  4.   ‘2-dimensional Point at coordinates (-79,37) with srid set to 8307’,  

  5.   SDO_GEOMETRY  

  6.   (  

  7.     2001, — SDO_GTYPE format: D00T. Set to 2001 for a 2-dimensional point  

  8.     8307, — SDO_SRID (geodetic)  

  9.     SDO_POINT_TYPE  

  10.     (  

  11.       -79, — ordinate value for Longitude  

  12.       37, — ordinate value Latitude  

  13.       NULL — no third dimension (only 2 dimensions)  

  14.     ),  

  15.     NULL,  

  16.     NULL 

  17.   )  

  18. ); 

 

属性:SDO_ELEM_INFO和SDO_ORDINATES

如果你想要存储比点更复杂的元素,也许想要存储线串和多边形(这可能需要很多个顶点)。

要想存储这些类型,你就会用到SDO_ORDINATES和SDO_ELEM_INFO这两个属性。详见:http://book.51cto.com/art/200910/157433.htm

 

 

参考

Oracle Spatial

https://de.slideshare.net/camporasimone/oracle-spatial?qid=876c77a2-55d9-43c1-bd38-282cabffc5dd&v=&b=&from_search=

Oracle Spatial的GIS空间数据模型

https://malagis.com/oracle-spatial-gis-spatial-data-model.html

Oracle Spatial

http://www.orafaq.com/wiki/Spatial

Spatial FAQ

http://www.orafaq.com/wiki/Spatial_FAQ

Oracle Spatial and Graph. Jayant Sharma Director

http://docplayer.net/13656744-Oracle-spatial-and-graph-jayant-sharma-director-product-management.html

Introduction to Oracle Spatial

https://de.slideshare.net/ehamzei/introduction-to-oracle-spatial?qid=876c77a2-55d9-43c1-bd38-282cabffc5dd&v=&b=&from_search=2

Raster Algebra mit Oracle Spatial und uDig

https://de.slideshare.net/kpatenge/raster-algebra-mit-oracle-spatial-und-udig?qid=876c77a2-55d9-43c1-bd38-282cabffc5dd&v=&b=&from_search=3

 

 

转载自:https://blog.csdn.net/pan_tian/article/details/81322211