Oracle spatial is used to store, manage, and query spatial data. Provides a set of SQL scenarios and functions for storing, retrieving, updating, and querying
A collection of spatial elements in a database. Mainly by the geometric data type, spatial indexing mechanism, a set of operational functions, management tools.
can refer to: http://www.cnblogs.com/lanzi/category/294299.html.
Main research content:
Sdo_geometry data type definition, including the village village all types of aggregates (dots, lines, polygons). Focus
Query and analyze using the index engine and geometry engine. Focus
Use the position coding engine to implement position enabling.
Advanced spatial indexing (including Routing and network Analysis). Focus
Use MAPVIEWR for visualization.
(1), Custom data types
Use arrays, structs, or classes with constructors, functional functions to define your own object types. Such an object type can be used for the data type of the property column, or it can be used to create the object table.
Oracle Spatial is a set of spatial data processing systems developed on the basis of this feature. Spatial has a very high number of custom data types, all under the Mdsys scenario, often using the sdo_geometry type.
Sdo_geometry represents a geometric object that can be a point, line, surface, multi point, multi-line, faceted, or mixed object. Spatial index of R-Tree and four-fork tree Spatial index are realized based on this data type, and many spatial analysis functions are realized in the form of SQL function.
The GEOLOC definition structure is as follows:
CREATE TYPE Sdo_geometry as OBJECT (
sdo_gtype number,
sdo_srid number,
sdo_point sdo_point_type,
sdo_ Elem_info Mdsys. Sdo_elem_info_array,
sdo_ordinates Mdsys. Sdo_ordinate_array);
(2), spatial index
Spatial index is a kind of logical index, and the entrance of spatial index relies on the concrete position of geometrical entity in coordinate space. The principle of creating spatial index is basically the same, all adopt the principle of partition, namely divide the query space into several
zones that contain spatial data and can be uniquely identified. There are two kinds of segmentation methods, one is the rule segmentation method, which divides the geographical space according to the rule or the half rule, and divides the indirect geographical object of the unit.
The geometrical part of a geographical element may be divided into several adjacent cells; the other is an object based segmentation method, where the partitioning of the index space is directly determined by the geographical object, and the index unit package
The minimum external rectangle that encloses the geographic object. Based on these two kinds of segmentation methods, two kinds of indexing mechanisms are produced, namely R-Tree index and four-fork tree index.
R-Tree Index can index three-dimensional and four-dimension spatial data, and approximate index of each geometry by the minimum boundary rectangle (mbr--minimum bounding Rectangle). On linear parameters
When the test data is indexed, only the R-tree index is used, and the R-tree index is the default index in Oracle spatial, and if the spatial index is not explicitly stated, then the R-Tree index is created. The R-Tree index is stored in the Spatial index table sdo_index_table, and the table is in an attempt to sdo_index_metadata. The R-Tree index ensures that the current user updates the index in real time using a sequential digital generator.
The metadata for the spatial index is stored in the view user_sdo_index_metadata, corresponding to the table sdo_index_metadata_table. Holds the name of all indexes (Sdo_index_name), the table that holds the index (sdo_index_table), the index type (sdo_index_type).
(1), Spatial index parameters: Sdo_dml_batch_size
Create INDEX Pbeijing_sidx on pbeiing (geometry) Indextype is Mdsys.spatial_index PARAMETERS (' sdo_dml_batch_size=5000 '). For the default case, the internal setting is 1000, which means that each of the 1000 data is included in the index. However, for a large number of inserts, delete update operations, the parameters should be set relatively large, improve the performance of the commit operation.
(2), query parameter size:
Select Sdo_dml_batch_size from user_sdo_index_metadata where sdo_index_name = ' pbeijing_sidx '.
(3), spatial index size requirements:
For a set of n rows of data, the R-tree spatial index roughly requires 100*3*n bytes as storage space for the spatial index table. There is also an additional need to 200*3*n to 300*3*n bytes as storage space for temporary worksheets.
(3), GML
Convert geometry to GML (Geography Markup Language) document
Select To_char (sdo_util. To_gmlgeometry (Geoloc)) from rbeijing R where r.id= ' 59552500066 '
<gml:linestring srsname= "sdo:8307" xmlns:gml= "HTTP://WWW.OPENGIS.NET/GML" ><gml:coordinates decimal= "." CS = "," ts= "" >115.71460884,39.57120198 115.71528384,39.57106104 115.71541416,39.57103098 115.71554016,39.57099597 115.71592212,39.57090498 115.71668604,39.570714 115.71734196,39.57055299 </GML:COORDINATES></GML: Linestring>
Parsing GML jar Packages:%oracle_home%\lib\xmlparserv2.jar
(4) Verification of spatial data
Oracle spatial provides two validation functions Validate_geometry_with_context (single geometry) validate_layer_with_context (geometry of the entire table)
function definition
Sdo_geom. Validate_geometry_with_context
(
Geometry in Sdo_geometry,
Diminfo in Sdo_dim_array
) return VARCHAR2;
(1), Verification standard
Basic validation
Check the effective properties and check the Sdo_gtype of the aggregates.
Verification of points
All coordinates are in the range specified by the Diminfo property.
Verification of Lines
All the dots on the line are different.
A line must have two or more points.
Polygon
A polygon is a contiguous region defined by an outer ring (shell) and multiple internal loops (hole).
The validity of the ring
Closure: The beginning is the same as the last vertex.
Flatness: All points on the ring are to be on a plane.
Non-intersection of the edges:
String: Ring is a valid string, if the adjacent vertex distance is less than the tolerance value, it is regarded as a point.
The coplanar nature of a ring: All points are on a plane.
Appropriate direction: The inner ring direction must be opposite to the outer ring direction.
Single continuous region: The inner loop cannot divide polygons into discontinuous regions.
No overlapping rings: no two rings overlap each other.
Internal and external disjoint: each inner ring must not intersect inside the outer ring.
For a two-dimensional polygon, the outer ring must be counterclockwise and the inner ring must be clockwise.
Composite polygon
Polygon Validity: Each polygon must be a valid polygon.
Non-overlapping but common-edge characteristics: Freeform polygon does not overlap, single can coincide with one side.
Continuous region: Each polygon of a composite surface is accessible from any other polygon in the face.
(5), the geometric function of the computational space entity
sdo_geom Package (Geometry)
This chapter contains descriptions of the geometry-related Pl/sql Subprograms in the Sdo_geom package, which can is grouped into the following categories:
Relationship (True/false) bet Ween 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 ()--check two geometry objects to determine the spatial relationship between them
Sdo_geom. Sdo_area ()--calculating the area of two-D geometric polygons
Sdo_geom. Sdo_distance ()-Calculates the distance between two geometric objects, distance from the nearest point or segment on the two collection object.
Sdo_geom. sdo_length--calculates the length or perimeter of a Geometry object
Sdo_geom. with_distance--determines whether two space objects are within a given Euclidean distance
Sdo_geom. Sdo_centroid ()--Determination of the center of gravity of geometric entities
Sdo_geom. Sdo_difference ()--the result geometry for calculating the difference of two geometry
Sdo_geom. sdo_intersection--returns the intersection result of two geometric entities
(6) Space operator (spatial Operators)
This chapter describes the operators, can use when working with the spatial object data type. For a overview of spatial operators, including how they differ from
Spatial procedures and functions
Sdo_filterSpecifies which geometries may interact with a given geometry.
Sdo_joinPerforms a spatial join based on one or more topological relationships.
Sdo_nnDetermines the nearest neighbor geometries to a geometry.
sdo_nn_distanceReturns the distance of a object returned by the SDO_NN operator.
sdo_relateDetermines whether or not two geometries interact in a specified way. (also Table 11–2 for convenient alternativ operators for performing specific mask value operations.)
sdo_within_distanceDetermines if two geometries are within a specified Distanc from one another.
sdo_anyinteractChecks if any geometries in a table have the Anyintera topological relationship with a specified geometry.
Sdo_containsChecks if any geometries in a table have the CONTAINS topological relationship with a specified geometry. Mdsys.sdo_contains (D.geoloc,n.geoloc) = ' TRUE ' means D contains n
Sdo_coveredbyChecks if any geometries in a table have the Coveredby topological relationship with a specified geometry.
sdo_coversChecks if any geometries in a table have the covers topological relationship with a specified geometry.
sdo_equalChecks if any geometries in a table have the EQUAL topological relationship with a specified geometry.
Sdo_insideChecks if any geometries in a table have the INSIDE topological relationship with a specified geometry.
sdo_onChecks if any geometries in a table have the "topological relationship with a specified geometry.
Sdo_overlapbdydisjointChecks if any geometries in a table have the
OverlapbdydisjointTopological relationship with a specified geometry.
Sdo_overlapbdyintersectChecks if any geometries in a table have the
OverlapbdyintersectTopological relationship with a specified geometry.
Sdo_overlapsChecks if any geometries in a table overlap (which is, have the
Overlapbdydisjointor overlapbdyintersect topological relationship with) a specified geometry.
Sdo_touchChecks if any geometries in a table have the touch topological relationship with a specified geometry.
(7), the difference between geometric functions and space operators
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 ' the ' parameter have a spatial index defined on it.) Spatialoperators must is used in the WHERE clause of a query. The parameter of any
operator specifies the geometry column to is 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, 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 don't require that a spatial index be defined, and they does not use a spatial index if it is defined. These subprograms can is used in the WHERE clause or in a subquery. If two geometries a input parameters to a Spatial procedure or function, both must the have same the 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, Use the operator. For example, unless
Need to did otherwise, use sdo_relate instead of Sdo_geom. RELATE, and use sdo_within_distance instead of Sdo_geom. Within_distance.
Space operations provide the best performance because of the use of spatial indexes. and space operations can only be used in the back of the Where. If the coordinate system of two parameters is inconsistent space performs the implicit coordinate system conversion.
Space processes and function providers are provided in Pl/sql packages, such as SDO geometry, SDO cs,sdo. These subroutines do not require that spatial indices are defined, and they do not use spatial index definitions. These children can be used in a WHERE clause or a subquery. If two graphics an input parameter space procedure or function, must have the same coordinate system.
If an operator and a procedure or function can implement the corresponding operation, if the operator can meet your requirements, use the operator. For example Sdo_relate instead of Sdo_geom. Relate,sdo_within_distance instead of Sdo_geom. Within_distance