Go to content Go to navigation and search

Home

Current Oracle Spatial Blog Articles


Search

Browse

RSS / Atom

Email me

textpattern

Creative Commons License
All Blog Articles, Data Models and Free Source Code by Simon Greener, The SpatialDB Advisor is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Minumum Bounding Rectangle (MBR) Object Type for Oracle

Thursday December 18 2008 at 09:33

Many years ago I wrote a “comprehensive” Minimum Bounding Rectangle (MBR) Object type for Oracle. This provides a lot fo the functionality of the BOX operators for PostGIS.

Here is the public interface of the MBR type:

create or replace TYPE MBR AS OBJECT (

   MinX  Number,
   MinY  Number,
   MaxX  Number,
   MaxY  Number,

   -- ============== Constructors
   --
   Constructor Function MBR
               Return Self as Result,
   Constructor Function MBR(            p_geometry  IN MDSYS.SDO_GEOMETRY,
                                        p_tolerance IN NUMBER )
               Return Self as Result,
   Constructor Function MBR(            p_geometry IN MDSYS.SDO_GEOMETRY,
                                        p_dimarray IN MDSYS.SDO_DIM_ARRAY )
               Return Self as Result,
   Constructor Function MBR(            p_MBR In MBR )
               Return Self as Result,
   Constructor Function MBR(            p_Point   In ST_Point,
                                        p_dExtent In Number)
              Return Self As Result,
   Constructor Function MBR(            p_Point   In MDSYS.Vertex_Type,
                                        p_dExtent In Number)
              Return Self As Result,
   Constructor Function MBR(            p_Coord2D In &&defaultSchema..Coord2DType,
                                        p_dExtent In Number)
               Return Self as Result,
   Constructor Function MBR(            p_dX In NUMBER,
                                        p_dY In Number,
                                        p_dExtent In Number)
               Return Self as Result,

   -- ============== Modifiers
   --
   Member Procedure SetEmpty,
   Member Procedure Expand(         p_Coord2D IN &&defaultSchema..Coord2DType),
   Member Procedure Expand(         p_dX          IN NUMBER,
	                            p_dY          IN NUMBER),
   Member Procedure Expand(         p_other       IN MBR),
   Member Procedure Normalise(      p_dRatio      In Number),
   Member Procedure SetLargestPart( p_geometry    IN MDSYS.SDO_GEOMETRY,
                                    p_dimarray    IN MDSYS.SDO_DIM_ARRAY ),
   Member Procedure Intersection(   p_other In MBR ),

   -- ============== Testers
   --

   Member Function isEmpty
          Return Boolean Deterministic,
   Member Function Contains( p_other In MBR )
          Return Boolean Deterministic,
   Member Function Contains( p_dX In Number,
                             p_dY In Number )
          Return Boolean Deterministic,
   Member Function Contains( p_Point   In ST_Point )
          Return Boolean Deterministic,
   Member Function Contains( p_Point   In MDSYS.Vertex_Type)
          Return Boolean Deterministic,
   Member Function Contains( p_Coord2D In Coord2DType )
          Return Boolean Deterministic,
   Member Function Equals(   p_other In MBR )
          Return Boolean Deterministic,
   Member Function Compare(  p_other In MBR )
          Return Number Deterministic,
   Member Function Overlap(  p_other in MBR )
          Return Boolean Deterministic,

   -- ============== Inspectors

   Member Function X
          Return Number Deterministic,
   Member Function Y
          Return Number Deterministic,
   Member Function Width
          Return Number Deterministic,
   Member Function Height
          Return Number Deterministic,
   Member Function Area
          Return Number Deterministic,
   Member Function Centre
          Return &&defaultSchema..Coord2DType Deterministic,
   Member Function Center
          Return &&defaultSchema..Coord2DType Deterministic,
   Member Function AsDimArray
          Return MDSYS.SDO_DIM_ARRAY Deterministic,
   Member Function AsString
          Return VarChar2 Deterministic,
   Member Function AsCSV
          Return VarChar2 Deterministic,
   Member Function AsWKT
          Return VARCHAR2 Deterministic,
   Member Function AsSVG
          Return VarChar2 Deterministic,
   Member Function getCentreAsSVG
          Return VarChar2 Deterministic,

  Order Member Function Evaluate(p_other In MBR)
               Return PLS_Integer

);

Follow the link to download the full implementation of my MBR type for Oracle.

An example of the use of the MBR object can be seen from the following:

set serveroutput on size 100000
declare
  myExtent MBR := New MBR;
  anExtent MBR;
Begin
  dbms_output.put_line( '=============================' );
  If ( myExtent.isEmpty ) Then
    dbms_output.put_line( 'isEmpty: True');
  Else
    dbms_output.put_line( 'isEmpty: False');
  End If;
  myExtent := MBR(337900, 5429000, 338900, 5430000);
  dbms_output.put_line( myExtent.AsString );
  dbms_output.put_line( myExtent.AsCSV );
  dbms_output.put_line( myExtent.AsWKT );
  dbms_output.put_line( myExtent.AsSVG );
  dbms_output.put_line( myExtent.GetCentreAsSVG );
  dbms_output.put_line( myExtent.X );
  dbms_output.put_line( myExtent.Width );
  dbms_output.put_line( myExtent.Height );
  dbms_output.put_line( myExtent.Y );
  If ( myExtent.contains(337950, 5429050) ) Then
    dbms_output.put_line( 'Contains: True');
  Else
    dbms_output.put_line( 'Contains: False');
  End If;
  If ( myExtent.contains(337950, 5439050) ) Then
    dbms_output.put_line( 'Contains: True');
  Else
    dbms_output.put_line( 'Contains: False');
  End If;
  anExtent := New MBR(337950, 5429050, 338950, 5430500);
  dbms_output.put_line( 'Compare = ' || myExtent.Compare(anExtent));
End;
/
show errors

anonymous block completed
=========================
isEmpty: True
<mbr minx='337900' miny='5429000' maxx='338900' maxy='5430000' />
337900,5429000,338900,5430000
POLYGON((337900 5429000,338900 5429000,338900 5430000,337900 5430000,337900 5429000))
<rect x='337900' y='5429000' width='1000' height='1000' />
<point x='338400' y='5429500' />
338400
1000
1000
5429500
Contains: True
Contains: False
Compare = .9025

No Errors.

I hope this is of interest to someone.

Creative Commons License

post this at del.icio.uspost this at Diggpost this at Technoratipost this at Redditpost this at Farkpost this at Yahoo! my webpost this at Windows Livepost this at Google Bookmarkspost this to Twitter

Comment