Download presentation
Presentation is loading. Please wait.
1
Object Relational Model Creating Spatial Tables
2
Concepts Describe the schema associated with a spatial layer Explain how spatial data is stored using the Oracle8i Spatial object-relational model Create the table associated with a spatial layer Describe the schema associated with a spatial layer Explain how spatial data is stored using the Oracle8i Spatial object-relational model Create the table associated with a spatial layer
3
SDO_GEOMETRY Object SQL> CREATE TABLE states ( 2 state VARCHAR2(30), 3 totpop NUMBER(9), 4 geom MDSYS.SDO_GEOMETRY); SQL> CREATE TABLE states ( 2 state VARCHAR2(30), 3 totpop NUMBER(9), 4 geom MDSYS.SDO_GEOMETRY); Example sdo_gtype NUMBER sdo_srid NUMBER sdo_point SDO_POINT_TYPE sdo_elem_info SDO_ELEM_INFO_ARRAY sdo_ordinates SDO_ORDINATE_ARRAY 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 Object
4
SDO_GEOMETRY Object (cont.) x NUMBER y NUMBER z NUMBER x NUMBER y NUMBER z NUMBER SDO_POINT_TYPE VARRAY (1048576) OF NUMBER SDO_ORDINATE_ARRAY SDO_ELEM_INFO_ARRAY
5
SDO_GTYPE Defines the kind of geometry stored in the object d = number of dimensions e.g. 2, 3 or 4 Defines the kind of geometry stored in the object d = number of dimensions e.g. 2, 3 or 4 GTYPEExplanation d000 UNKNOWN_GEOMETRYSpatial ignores this geometry. d001 POINT Geometry contains one point. d002 LINESTRINGGeometry contains one line string. d003 POLYGON Geometry contains one polygon. d004 HETEROGENEOUS COLLECTIONGeometry is a collection of elements of different types: points, lines, polygons d005 MULTIPOINTGeometry has multiple points. d006 MULTILINESTRINGGeometry has multiple line strings. d007 MULTIPOLYGON Geometry has multiple polygons
6
SDO_SRID Defines the coordinate system («Spatial Reference System») used for this geometry Integer value matching a Spatial Reference Id defined in the MDSYS.CS_SRS table If not specified, use the spatial reference system defined at layer level (in spatial metadata) - if any Defines the coordinate system («Spatial Reference System») used for this geometry Integer value matching a Spatial Reference Id defined in the MDSYS.CS_SRS table If not specified, use the spatial reference system defined at layer level (in spatial metadata) - if any
7
SDO_POINT This type should not be used outside of the SDO_GEOMETRY object. Optimized space for storing points (not point clusters). Ignored if SDO_ELEM_INFO and SDO_ORDINATES are not NULL This type should not be used outside of the SDO_GEOMETRY object. Optimized space for storing points (not point clusters). Ignored if SDO_ELEM_INFO and SDO_ORDINATES are not NULL
8
SDO_ELEM_INFO Entries in the array should be considered in groups of three. The triplet values stored in the this array are interpreted as: –Ordinate offset - The position of the first ordinate of an element in the sdo_ordinates array. Values start at 1. –Element type –Interpretation - Straight line, Circular arc or header Entries in the array should be considered in groups of three. The triplet values stored in the this array are interpreted as: –Ordinate offset - The position of the first ordinate of an element in the sdo_ordinates array. Values start at 1. –Element type –Interpretation - Straight line, Circular arc or header
9
SDO_ORDINATES This is a simple array of numbers Contains the ordinates that make up geometry elements Elements stored in the SDO_ORDINATES array are defined in the SDO_ELEM_INFO array This is a simple array of numbers Contains the ordinates that make up geometry elements Elements stored in the SDO_ORDINATES array are defined in the SDO_ELEM_INFO array
10
Element Example: Point Point optimized for space Spatial index is 2 dimensional, x and y. To generate a spatial index on SDO_POINT, SDO_ELEM_INFO and SDO_ORDINATES must be NULL. Point optimized for space Spatial index is 2 dimensional, x and y. To generate a spatial index on SDO_POINT, SDO_ELEM_INFO and SDO_ORDINATES must be NULL. (x, y, z) SQL> INSERT INTO telephone_poles 2> VALUES (attribute_1, …. attribute_n, 3> mdsys.sdo_geometry ( 4> 3001, null, 5> mdsys.sdo_point_type (43.7,-75.2,200), 6> null, null) 7> ); SQL> INSERT INTO telephone_poles 2> VALUES (attribute_1, …. attribute_n, 3> mdsys.sdo_geometry ( 4> 3001, null, 5> mdsys.sdo_point_type (43.7,-75.2,200), 6> null, null) 7> );
11
Element Types in SDO_ELEM_INFO Element TypesInterpretation 0 UNKNOWN_ELEMENT 1 POINT # of points in collection 2 LINESTRING 1 - Straight lines 2 - Circular arcs n003 POLYGON 1 - Straight lines 2 - Circular arcs 3 - Optimized rectangle 4 - Circle 4 COMPOUND LINESTRING# of type 2 sub-elements that make up the linestring n005 COMPOUND POLYGON # of type 2 sub-elements that make up the polygon
12
Element Example: Line String Ordinate offset 1 Element type 2 Interpretation 1 (x1,y1)(x1,y1) (x2,y2)(x2,y2) (x3,y3)(x3,y3) (x4,y4)(x4,y4) Line segments that close to form a ring have no implied interior Line segments must be contiguous Line segments that close to form a ring have no implied interior Line segments must be contiguous
13
Element Example: Arc String Ordinate offset 1 Element type 2 Interpretation 2 (x7,y7) (x1,y1) (x3,y3)(x3,y3) (x4,y4) (x2,y2) (x5,y5) (x6,y6) Each arc is defined by three points on the circumference of a circle Last point from one arc is the first point of next arc Arcs that close to form a ring have no implied interior Arcs must be contiguous Each arc is defined by three points on the circumference of a circle Last point from one arc is the first point of next arc Arcs that close to form a ring have no implied interior Arcs must be contiguous
14
Element Example: Polygon Interpretation 1 - All line segments are straight lines Area is implied Line segments cannot cross each other Interpretation 1 - All line segments are straight lines Area is implied Line segments cannot cross each other Ordinate offset 1 Element type 1003 Interpretation 1 (x4,y4)(x4,y4) (x5,y5) (x3,y3) (x2,y2) (x6,y6)(x1,y1)
15
Element Example: Arc Polygon (x8,y8) Interpretation 2 - All line segments are circular arcs Area is implied Arcs can not cross each other Interpretation 2 - All line segments are circular arcs Area is implied Arcs can not cross each other Ordinate offset 1 Element type 1003 Interpretation 2 (x7,y7)(x7,y7) (x8,y8) (x6,y6) (x5,y5) (x9,y9) (x2,y2) (x3,y3) (x4,y4) (x1,y1)
16
Element Example: Rectangle Optimal storage - Defined by lower left point, upper right point Area is implied Optimal storage - Defined by lower left point, upper right point Area is implied Ordinate offset 1 Element type 1003 Interpretation 3 (x2,y2) (x1,y1)
17
Element Example: Circle Defined by any three points on the circumference Area is implied Defined by any three points on the circumference Area is implied Ordinate Offset 1 Element Type 1003 Interpretation 4 (x1,y1)(x1,y1) (x2,y2) (x3,y3)
18
Element Example: Compound Line String First triplet (header) defines the number of sub-elements Sub-elements must be contiguous Arcs and line segments of sub-elements can cross Element types 4 can ONLY contain element types 2 First triplet (header) defines the number of sub-elements Sub-elements must be contiguous Arcs and line segments of sub-elements can cross Element types 4 can ONLY contain element types 2 (x6,y6) Element Type 4 2 Ordinate Offset 1 5 13 (x3,y3) (x1,y1) (x5,y5) (x4,y4) (x2,y2) (x7,y7) (x8,y8) (x9,y9) Interpretation 3 1 2 1
19
Element Example: Compound Polygon First triplet (header) defines the number of sub-elements Sub-elements must be contiguous Arcs and line segments of sub-elements can cross Element types 5 can ONLY contain element types 2 Area is implied First triplet (header) defines the number of sub-elements Sub-elements must be contiguous Arcs and line segments of sub-elements can cross Element types 5 can ONLY contain element types 2 Area is implied Interpretation 2 1 2 Element Type 1005 2 Ordinate Offset 1 5 (x4,y4) (x5,y5) (x6,y6) (x7,y7) (x2,y2) (x3,y3) (x1,y1)
20
Element Example: Unknown geometry Element type 0 is ignored by Oracle Spatial Element type 0 is for modeling unsupported element types (I.e. curves, splines etc…) A geometry with an element type 0 must contain at least one element of type 1,2,3,4 or 5. The non 0 element is an approximation of the unsupported geometry. The approximation is indexed by Oracle Spatial Element type 0 is ignored by Oracle Spatial Element type 0 is for modeling unsupported element types (I.e. curves, splines etc…) A geometry with an element type 0 must contain at least one element of type 1,2,3,4 or 5. The non 0 element is an approximation of the unsupported geometry. The approximation is indexed by Oracle Spatial Ordinate Offset 1 11 Element Type 0 1003 Interpretation 1324 3 (x1,y1) (x2,y2) (x3,y3) (x4,y4) (x5,y5) (x6,y6) (x7,y7)
21
Collection Example: Point cluster Ordinate Offset 1 Element type 1 Interpretation 5 (x3,y3) (x5,y5) (x2,y2) (x4,y4) (x1,y1) Interpretation is the number of points in the cluster
22
Collection Example: Multi Line String Elements can be line strings, arc strings or compound line strings (x1,y1)(x1,y1) (x2,y2)(x2,y2) (x3,y3)(x3,y3) (x4,y4)(x4,y4)(x6,y6)(x6,y6) Ordinate offset 1 7 Element type 2 Interpretation 1 2 (x5,y5)(x5,y5)
23
Collection Example: Multi Polygon Elements can be polygons, arcs polygons, or compound polygons Ordinate offset 1 13 Element type 1003 Interpretation 1 4 (x4,y4)(x4,y4) (x5,y5) (x3,y3) (x2,y2) (x6,y6)(x1,y1) (x7,y7)(x7,y7) (x8,y8) (x9,y9)
24
Element example: Polygon with void A void can be modeled with any combination of type 3 and type 5 elements Voids can contain islands and islands can contain voids Area is implied as the difference between the outer and inner polygons A void can be modeled with any combination of type 3 and type 5 elements Voids can contain islands and islands can contain voids Area is implied as the difference between the outer and inner polygons (x4,y4)(x4,y4) (x5,y5) (x3,y3) (x2,y2) (x6,y6) (x1,y1) (x7,y7) (x8,y8) Ordinate offset 1 13 Element type 1003 2003 Interpretation 1 3
25
Element example: Compound polygon with void A void can be modeled with any combination of type 3 and type 5 elements Voids can contain islands and islands can contain voids Area is implied as the difference between the outer and inner polygons A void can be modeled with any combination of type 3 and type 5 elements Voids can contain islands and islands can contain voids Area is implied as the difference between the outer and inner polygons Interpretation 2 1 2 3 Ordinate Offset 1 7 17 Element Type 1005 2 2003 (x5,y5) (x4,y4) (x3,y3) (x6,y6) (x7,y7) (x1,y1) (x2,y2) (x9,y9) (x10,y10) (x8,y8)
26
Encoding polygons with voids Note: Order required for boundaries Orientation of coordinates: Note: Order required for boundaries Orientation of coordinates: is different from AB DE CF AF DC EB Not the same as + +
27
Ring ordering External ring must appear before internal ring Outer and inner rings identified by element type External ring must appear before internal ring Outer and inner rings identified by element type must be constructed as + ++ 1003 2003 1003 2003 1003
28
Points orientation Counter-clockwise for exterior rings Clockwise for interior rings Counter-clockwise for exterior rings Clockwise for interior rings AB DE CF + AB ED CF
29
Constructing geometries (10,10)(10,10) (20,25)(20,25) (30,10)(30,10) (40,10)(40,10) SQL> INSERT INTO lines VALUES ( 2> attribute_1, …. attribute_n, 3> mdsys.sdo_geometry ( 4> 2002, null, null, 5> mdsys.sdo_elem_info_array (1,2,1), 6> mdsys.sdo_ordinate_array ( 7> 10,10, 20,25, 30,10, 40,10)) 8> ); SQL> INSERT INTO lines VALUES ( 2> attribute_1, …. attribute_n, 3> mdsys.sdo_geometry ( 4> 2002, null, null, 5> mdsys.sdo_elem_info_array (1,2,1), 6> mdsys.sdo_ordinate_array ( 7> 10,10, 20,25, 30,10, 40,10)) 8> );
30
Constructing geometries SQL> INSERT INTO PARKS VALUES( 2> attribute_1, …, attribute_n, 3> MDSYS.SDO_GEOMETRY( 4> 2003, null, null, 5> MDSYS.SDO_ELEM_INFO_ARRAY 6> (1,1005,2, 1,2,1, 7,2,2, 17,2003,3), 7> MDSYS.SDO_ORDINATE_ARRAY 8> (10,50,10,30,50,30,50,50,40,60, 9> 30,50,20,60,10,50,25,35,35,40 )); SQL> INSERT INTO PARKS VALUES( 2> attribute_1, …, attribute_n, 3> MDSYS.SDO_GEOMETRY( 4> 2003, null, null, 5> MDSYS.SDO_ELEM_INFO_ARRAY 6> (1,1005,2, 1,2,1, 7,2,2, 17,2003,3), 7> MDSYS.SDO_ORDINATE_ARRAY 8> (10,50,10,30,50,30,50,50,40,60, 9> 30,50,20,60,10,50,25,35,35,40 )); (x5,y5) (x4,y4) (x3,y3) (x6,y6) (x7,y7) (x1,y1) (x2,y2) (x9,y9) (x10,y10) (x8,y8)
31
Element Types Summarized Element TypesInterpretation 0 UNKNOWN_ELEMENT 1 POINT # of points in collection 2 LINESTRING 1 - Straight lines 2 - Circular arcs 3 POLYGON 1 - Straight lines 2 - Circular arcs 3 - Optimized rectangle 4 - Circle 4 COMPLEX LINESTRING# of type 2 elements that make up the linestring 5 COMPLEX POLYGON # of type 2 elements that make up the polygon
32
Spatial Metadata The spatial routines require you to populate a table that contains metadata about SDO_GEOMETRY columns The metadata table is created under the Oracle user MDSYS during installation The metadata table is referenced via the view USER_SDO_GEOM_METADATA For every SDO_GEOMETRY column, insert a row in the USER_SDO_GEOM_METADATA view The spatial routines require you to populate a table that contains metadata about SDO_GEOMETRY columns The metadata table is created under the Oracle user MDSYS during installation The metadata table is referenced via the view USER_SDO_GEOM_METADATA For every SDO_GEOMETRY column, insert a row in the USER_SDO_GEOM_METADATA view
33
USER_SDO_GEOM_METADATA sdo_dimname VARCHAR2(32) sdo_lb NUMBER sdo_ub NUMBER sdo_tolerance NUMBER sdo_dimname VARCHAR2(32) sdo_lb NUMBER sdo_ub NUMBER sdo_tolerance NUMBER MDSYS.SDO_DIM_ELEMENT object VARRAY(4) OF SDO_DIM_ELEMENT MDSYS.SDO_DIM_ARRAY table_name VARCHAR2(32), column_name VARCHAR2(32), diminfo MDSYS.SDO_DIM_ARRAY srid NUMBER table_name VARCHAR2(32), column_name VARCHAR2(32), diminfo MDSYS.SDO_DIM_ARRAY srid NUMBER USER_SDO_GEOM_METADATA
34
USER_SDO_GEOM_METADATA (cont.) SDO_DIMNAME –The dimension name SDO_LB –Lowest possible value for this dimension SDO_UB –Largest possible value for this dimension SDO_TOLERANCE –Round-off error value used by Oracle Spatial indexing, operators and functions. SDO_SRID –Spatial Reference System id (optional) SDO_DIMNAME –The dimension name SDO_LB –Lowest possible value for this dimension SDO_UB –Largest possible value for this dimension SDO_TOLERANCE –Round-off error value used by Oracle Spatial indexing, operators and functions. SDO_SRID –Spatial Reference System id (optional)
35
Populating USER_SDO_GEOM_METADATA SQL> INSERT INTO USER_SDO_GEOM_METADATA VALUES 2 (‘ROADS’, 3 ‘GEOMETRY’, 4 MDSYS.SDO_DIM_ARRAY ( 5 MDSYS.SDO_DIM_ELEMENT(’Long’, -180, 180,.005), 6 MDSYS.SDO_DIM_ELEMENT(‘Lat’, -90, 90,.005) 7 ), 8 NULL 9 ); SQL> INSERT INTO USER_SDO_GEOM_METADATA VALUES 2 (‘ROADS’, 3 ‘GEOMETRY’, 4 MDSYS.SDO_DIM_ARRAY ( 5 MDSYS.SDO_DIM_ELEMENT(’Long’, -180, 180,.005), 6 MDSYS.SDO_DIM_ELEMENT(‘Lat’, -90, 90,.005) 7 ), 8 NULL 9 );
36
Notes on dimensions You can place more than 2 dimensions in the SDO_DIM_ARRAY, but Oracle Spatial Operators, Functions and Indexing will only use the first 2 dimensions defined. All layers that you want to match MUST have the EXACT SAME bounds ! You can place more than 2 dimensions in the SDO_DIM_ARRAY, but Oracle Spatial Operators, Functions and Indexing will only use the first 2 dimensions defined. All layers that you want to match MUST have the EXACT SAME bounds !
37
Support for topology Topology is not explicitly maintained in the DB Several topological operators and functions have been implemented for checking the relationships between two geometries Window and spatial join queries are also supported Topology is not explicitly maintained in the DB Several topological operators and functions have been implemented for checking the relationships between two geometries Window and spatial join queries are also supported
38
A B A B A B A B A B A red B green A B B Inside A A Contains B B Covered by A A Covers B Touch Overlap Boundaries Intersect Overlap Boundaries Disjoint Equal Disjoint Topological relationships
39
1.DISJOINT: boundaries and interiors do not intersect 2. TOUCH: boundaries intersect but interiors do not intersect 3. OVERLAPBDYDISJOINT: interior of one object intersects boundary and interior of other object, but two boundaries do not intersect (example: a line originates outside a polygon and ends inside the polygon) 4. OVERLAPBDYINTERSECT: boundaries and interiors of the two objects intersect 5. EQUAL: the two objects have the same boundary and interior Topological relationships
40
6. CONTAINS: interior and boundary of one object is completely contained in the interior of other object 7. COVERS: interior of one object is completely contained in interior of other object and their boundaries intersect 8. INSIDE: opposite of CONTAINS; A INSIDE B implies B CONTAINS A 9. COVEREDBY: opposite of COVERS; A COVEREDBY B implies B COVERS A 10. ANYINTERACT: the objects are non-disjoint Topological relationships (cont.d)
41
SDO_RELATE MASK: identifies the topological relation Topological operators: SDO_RELATE boolean := SDO_RELATE (,, ‘MASK= QUERYTYPE= [other optional parameters]’ ) boolean := SDO_RELATE (,, ‘MASK= QUERYTYPE= [other optional parameters]’ )
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.