Oracle Spatial用来存储、管理、查询空间数据。提供了一套 SQL 方案和函数,用来存储、检索、更新和查询
数据库中的空间要素集合。主要由几何数据类型,空间索引机制,一套操作函数,管理工具组成。
可以参考:http://www.cnblogs.com/lanzi/category/294299.html。
主要研究内容:
SDO_GEOMETRY数据类型定义,包括村村所有类型的集合体(点,线,多边形)。(重点)
使用索引引擎和几何引擎进行查询和分析。(重点)
使用位置编码引擎实现位置使能。
高级空间索引(包括路由和网络分析)。(重点)
使用MapViewr进行可视化。
(1),自定义的数据类型
用数组,结构体或带有构造函数,功能函数的类来定义自己的对象类型。这样的对象类型能用于属性列的数据类型,也能用来创建对象表。
而oracle spatial也正是基于此种特性所研发的一套空间数据处理系统.spatial 的自定义数据类型有非常多,都在mdsys方案下,经常使用的是sdo_geometry类型。
sdo_geometry表示一个几何对象,能是点、线、面、多点、多线、多面或混合对象。spatial 在此数据类型的基础上,实现了r树空间索引和四叉树空间索引,还以sql函数的形式实现了多种空间分析功能。
GEOLOC 定义结构如下:
(2)、空间索引
空间索引是一种逻辑索引,空间索引的入口依赖于几何实体在坐标空间中的具体位置。创建空间索引的原理基本相同,都采用分割原理,即把查询空间划分为若干
区域,这些区域包含空间数据并可唯一标识。分割的方法有两种,一种是规则分割法,它是将地理空间按照规则或半规则方式分割,分割单元间接地域地理对象
相关联,地理要素的几何部分可能被分割到几个相邻的单元中;另一种是基于对象的分割方法,这种方法的索引空间的分割直接由地理对象来确定,索引单元包
括地理对象的最小外接矩形。基于这两种分割方法,产生两种索引机制,分别为R树索引和四叉树索引。
R 树索引可以为三维和四维的空间数据进行索引,通过最小边界矩形(MBR——Minimum Bounding Rectangle)来对每个几何体近似索引。对线性参
考系数据建立索引时,只能使用R树索引,而且 R树索引是 Oracle Spatial中默认的索引,如果在创建空间索引时没有明确指出,那么创建的就是R树索引。R树索引存储在空间索引表 SDO_INDEX_TABLE 中,而该表有在试图SDO_INDEX_METADATA 中。R树索引通过一个顺序数字发生器来确保当前用户对索引的实时更新。
空间索引的元数据存储在视图 USER_SDO_INDEX_METADATA中,对应的表SDO_INDEX_METADATA_TABLE。存放所有索引的名称 (SDO_INDEX_NAME),存放索引的表 (SDO_INDEX_TABLE),索引类型(SDO_INDEX_TYPE)。
(1)、空间索引的参数: SDO_DML_BATCH_SIZE
create index pbeijing_sidx on pbeiing(geometry) indextype is mdsys.spatial_index PARAMETERS('SDO_DML_BATCH_SIZE=5000')。对于默认的情况,内部设置为 1000,意味着每此 1000个数据被纳入到索引当中。但是对于一个包含大量插入、删除更新操作来说,参数应该设的比较大,提高提交操作的性能。
(2)、查询参数大小:
select SDO_DML_BATCH_SIZE from USER_SDO_INDEX_METADATA where SDO_INDEX_NAME = 'pbeijing_sidx'。
(3)、空间索引大小的需求:
对于一个 N行数据的一个集合, R-tree空间索引大致需要 100*3*N字节作为空间索引表的存储空间。还额外需要 200*3*N到 300*3*N字节作为临时工作表的存储空间。
把 Geometry转换为 GML(Geography Markup Language)文档
select TO_CHAR(SDO_UTIL.TO_GMLGEOMETRY(geoloc)) from rbeijing r where r.id='59552500066'
(4)、验证空间数据
(5)、计算空间实体的几何体函数
SDO_GEOM Package (Geometry)
This chapter contains descriptions of the geometry-related PL/SQL subprograms in the SDO_GEOM package, which can be grouped into the following categories:
Relationship (True/False) between two objects: RELATE, WITHIN_DISTANCEValidation: VALIDATE_GEOMETRY_WITH_CONTEXT, VALIDATE_LAYER_WITH_CONTEXT
Single-object operations: SDO_ARC_DENSIFY, SDO_AREA, SDO_BUFFER, SDO_CENTROID, SDO_CONVEXHULL, SDO_LENGTH, SDO_MAX_MBR_ORDINATE, SDO_MIN_MBR_ORDINATE, SDO_MBR, SDO_POINTONSURFACETwo-object operations: SDO_DISTANCE, SDO_DIFFERENCE, SDO_INTERSECTION, SDO_UNION, SDO_XOR
SDO_GEOM.RELATE()——检查两个几何体对象,确定它们之间的空间关系
SDO_GEOM.SDO_AREA()——计算两维几何多边形的面积
SDO_GEOM.SDO_DISTANCE()——计算两个几何对象间的距离,距离为两个集合对象上距离最近的点或线段之间的距离。
SDO_GEOM.SDO_LENGTH——计算一个几何体对象的长度或周长
SDO_GEOM.WITH_DISTANCE——确定两个空间对象是否位于给定的欧氏距离以内
SDO_GEOM.SDO_CENTROID()——确定几何实体的重心
SDO_GEOM.SDO_DIFFERENCE()——计算两个几何体进行差运算的结果几何体
SDO_GEOM.SDO_INTERSECTION——返回两个几何实体的交集结果
(6)空间操作符(Spatial Operators)
This chapter describes the operators that you can use when working with the spatial object data type. For an overview of spatial operators, including how they differ from
spatial procedures and functions
SDO_FILTER Specifies which geometries may interact with a given geometry.
SDO_JOIN Performs a spatial join based on one or more topological relationships.
SDO_NN Determines the nearest neighbor geometries to a geometry.
SDO_NN_DISTANCE Returns the distance of an object returned by the SDO_NN operator.
SDO_RELATE Determines whether or not two geometries interact in a specified way. (See also Table 11–2 for convenient alternativ operators for performing specific mask value operations.)
SDO_WITHIN_DISTANCE Determines if two geometries are within a specified distanc from one another.
SDO_ANYINTERACT Checks if any geometries in a table have the ANYINTERA topological relationship with a specified geometry.
SDO_CONTAINS Checks if any geometries in a table have the CONTAINS topological relationship with a specified geometry. mdsys.sdo_contains(d.geoloc,n.geoloc)='TRUE' 表示d 包含 n
SDO_COVEREDBY Checks if any geometries in a table have the COVEREDBY topological relationship with a specified geometry.
SDO_COVERS Checks if any geometries in a table have the COVERS topological relationship with a specified geometry.
SDO_EQUAL Checks if any geometries in a table have the EQUAL topological relationship with a specified geometry.
SDO_INSIDE Checks if any geometries in a table have the INSIDE topological relationship with a specified geometry.
SDO_ON Checks if any geometries in a table have the ON topological relationship with a specified geometry.
SDO_OVERLAPBDYDISJOINT Checks if any geometries in a table have the
OVERLAPBDYDISJOINT topological relationship with a specified geometry.
SDO_OVERLAPBDYINTERSECT Checks if any geometries in a table have the
OVERLAPBDYINTERSECT topological relationship with a specified geometry.
SDO_OVERLAPS Checks if any geometries in a table overlap (that is, have the
OVERLAPBDYDISJOINT or OVERLAPBDYINTERSECT topological relationship with) a specified geometry.
SDO_TOUCH Checks if any geometries in a table have the TOUCH topological relationship with a specified geometry.
(7)、几何函数和空间操作符的区别
patial Operators, Procedures, and Functions
Spatial operators, such as SDO_FILTER and SDO_RELATE, provide optimumperformance because they use the spatial index. (Spatial operators require that the
geometry column in the first parameter have a spatial index defined on it.) Spatialoperators must be used in the WHERE clause of a query. The first parameter of any
operator specifies the geometry column to be searched, and the second parameterspecifies a query window. If the query window does not have the same coordinate
system as the geometry column, Spatial performs an implicit coordinate systemtransformation. For detailed information about the spatial operators, see Chapter 11.
Spatial procedures and functions are provided as subprograms in PL/SQL packages,such as SDO_GEOM, SDO_CS, and SDO_LRS. These subprograms do not require that a spatial index be defined, and they do not use a spatial index if it is defined. These subprograms can be used in the WHERE clause or in a subquery. If two geometries a input parameters to a Spatial procedure or function, both must have the same coordinate system.
The following performance-related guidelines apply to the use of spatial operators,procedures, and functions:
If an operator and a procedure or function perform comparable operations, and if the operator satisfies your requirements, use the operator. For example, unless you
need to do otherwise, use SDO_RELATE instead of SDO_GEOM.RELATE, and use SDO_WITHIN_DISTANCE instead of SDO_GEOM.WITHIN_DISTANCE.
空间操作提供最佳性能,因为使用了空间索引。而且空间操作只能被使用在WHERE后面。如果两个参数的坐标系统不一致空间执行隐式坐标系统转换。
空间过程和函数提供子在PL / SQL包,如sdo几何学,sdo cs,sdo中。 这些子程序不需要那空间索引被定义,并且他们不使用空间索引定义。这些子可以用在WHERE子句或子查询。如果两个图形一个输入参数空间过程或函数,都必须有相同的坐标系统。
如果一个操作符和一个过程或函数都能实现对应的操作,如果操作符能满足你的要求,使用操作符。比如SDO_RELATE instead of SDO_GEOM. RELATE,SDO_WITHIN_DISTANCE instead of SDO_GEOM.WITHIN_DISTANCE
参考:http://www.cnblogs.com/lanzi/archive/2010/12/30/1922249.html
sdo_index_metadata 百度
https://community.oracle.com/thread/876634?start=0&tstart=0