MINI MINI MANI MO

Path : /opt/oracle/product/18c/dbhomeXE/md/admin/
File Upload :
Current File : //opt/oracle/product/18c/dbhomeXE/md/admin/sdogru.sql

Rem
Rem $Header: sdo/admin/sdogru.sql /main/39 2017/10/30 12:49:46 rjanders Exp $
Rem
Rem sdogru.sql
Rem
Rem Copyright (c) 2002, 2017, Oracle and/or its affiliates. 
Rem All rights reserved.
Rem
Rem    NAME
Rem      sdogru.sql - GeoRaster Utility Package
Rem
Rem    DESCRIPTION
Rem      GeoRaster trigger functions and maintenance tools
Rem
Rem    NOTES
Rem
Rem BEGIN SQL_FILE_METADATA
Rem SQL_SOURCE_FILE: sdo/admin/sdogru.sql
Rem SQL_SHIPPED_FILE: md/admin/sdogru.sql
Rem SQL_PHASE: SDOGRU
Rem SQL_STARTUP_MODE: NORMAL
Rem SQL_IGNORABLE_ERRORS: NONE
Rem SQL_CALLING_FILE: sdo/admin/catmdsdoh.sql
Rem END SQL_FILE_METADATA
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    rjanders    10/08/17 - Add MDSYS to spatial type
Rem    rjanders    05/10/17 - #26037683: Raise 'when other' exceptions
Rem    rjanders    03/23/17 - #25437999: Remove 'when others then NULL'
Rem                           handlers
Rem    zzhang      05/26/16 - Move memory API from sdo_geor to sdo_geor_utl
Rem    zzhang      12/09/15 - change calcDemArea to calcSurfaceArea
Rem    zzhang      11/19/15 - move generateBitmapPyramid to sdo_geor
Rem    ilucena     10/20/15 - move generate ramp to utl
Rem    czechar     08/14/15 - adding SQL file metadata
Rem    ilucena     04/24/15 - add calcWorldFileParams
Rem    zzhang      02/06/15 - add calcDemArea
Rem    zzhang      01/21/15 - generateBitmapPyramid
Rem    rjanders    03/15/13 - #16473696: Start/End _ORACLE_SCRIPT
Rem                           initialization
Rem    fechen      10/31/12 - add getProgress
Rem    zzhang      03/19/12 - Implement emptyBlocks
Rem    zzhang      04/26/11 - Add new procedure recreateDMLTriggers
Rem    fechen      11/16/10 - add isreporting
Rem    fechen      10/07/10 - add status support
Rem    wexu        07/23/08 - bug 7197832 - revoke exec priv during upgrade
Rem    bgouslin    01/07/07 - New version to fix Windoze format issue caused by
Rem                           some ADE bug
Rem    zzhang      04/18/06 - move functions to sdo_geor_admin package
Rem    zzhang      02/03/06 - add new functions
Rem    wexu        05/19/05 - renameRDT changed 
Rem    wexu        07/12/04 - bug 3703288 
Rem    wexu        06/19/03 - remove createDDLTrigger
Rem    wexu        06/18/03 - split createTriggers
Rem    wexu        06/06/03 - add createTriggers
Rem    qxie        06/06/03 - edits
Rem    qxie        11/15/02 - DML and DDL trigger funcs
Rem    qxie        11/15/02 - Created
Rem

Rem ********************************************************************
Rem This package must not be modified by the customer.  Doing so
Rem could cause internal errors.
Rem ********************************************************************

Rem ********************************************************************
Rem #16473696: Indicate Oracle-Supplied object
@@?/rdbms/admin/sqlsessstart.sql
Rem ********************************************************************

-- bug 7197832: revoke public execute privilege with grant option
-- this is necessary for upgrade cases
DECLARE
  package_not_found exception;
  pragma exception_init(package_not_found, -04042);
BEGIN
  BEGIN
    EXECUTE IMMEDIATE 'REVOKE EXECUTE ON MDSYS.SDO_GEOR_UTL FROM PUBLIC';
    EXCEPTION
      WHEN package_not_found THEN NULL;
      WHEN OTHERS THEN
        SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
                               'EXCEPTION[sdogru.sql(' || $$PLSQL_LINE || ')1]: ' || SQLERRM); RAISE;
  END;
END;
/

CREATE OR REPLACE PACKAGE MDSYS.SDO_GEOR_UTL AUTHID CURRENT_USER AS


TYPE target_cell_row_type IS RECORD 
(area         NUMBER,
 whole  NUMBER,
 contain  NUMBER, 
 inter_sect  NUMBER, 
 extra  NUMBER);


TYPE target_cell_rows_type IS TABLE OF target_cell_row_type;


-- Is GeoRaster valid?
FUNCTION isGeoRasterValid(powner IN varchar2,
                          ptableName IN varchar2,
                          columnName IN varchar2,
                          rdt IN varchar2,
                          rid IN number)
RETURN varchar2 DETERMINISTIC PARALLEL_ENABLE;

-- ---------------------------------------------------------------------
--      procedure to create DML triggers on a georaster table 
-- ---------------------------------------------------------------------

PROCEDURE createDMLTrigger
(
    tableName      varchar2,
    columnName     varchar2
);

-- ---------------------------------------------------------------------
--      procedure to create DML triggers on a georaster table 
-- ---------------------------------------------------------------------

PROCEDURE recreateDMLTriggers;

-- ---------------------------------------------------------------------
-- NAME
--   renameRDT
--
-- DESCRIPTION
--   This routine renames raster data table(s) owned by the current user.
--   It will update all related GeoRaster objects and GeoRaster system
--   data coorespondingly.
--
-- ARGUMENTS
--   oldRDTs - name(s) of existing raster data table(s) to be renamed
--   newRDTs - name(s) of new raster data table(s)
--
-- NOTES
--
--   This routine renames RDTs owned by the current user.
--
--   The RDT names in the strings are seperated with ','.
--   If an oldRDT does not appear in the GeoRaster sysdata, it is ignored.
--   If a newRDT is not unique in the GeoRaster sysdata, ORA-13403 is raised. 
--   If a newRDT is NULL, a unique RDT name is automatically generated.
-- ---------------------------------------------------------------------
PROCEDURE renameRDT
(
   oldRDTs VARCHAR2,
   newRDTs VARCHAR2 DEFAULT NULL
);


-- ---------------------------------------------------------------------
-- NAME
--   calcSurfaceArea
--
-- DESCRIPTION
--   Calculate 3D surface area represented by DEM data, which is stored in 
--   a GeoRaster object, with parallelism.
--
-- ARGUMENTS
--   georaster
--      GeoRaster object in which DEM data is stored.
--   window
--      A 2D geometry object specifying the area of which the 3D surface area is
--      calculated
--   parallel
--      Specifies the degree of parallelism for the operation. It should be more
--      than 0. It is recommended to set to 2*(number of cpu)
--
-- NOTES
--   This function first finds out all cells within or touching a certain area
--   specified by the window parameter, splits each of the cells into two 3D
--   triangles, computes the 3D surface area of each triangle, and then returns the
--   sum of these area values as the result. The area of the triangles which
--   intersect with the window boundary are computed based on the intersected
--   geometries. So, this function gives out a relatively very high precision
--   surface area.
--   If the parallel parameter is less than 1, then 1 will be used for parallel
--   degree.
--
-- ---------------------------------------------------------------------
FUNCTION calcSurfaceArea(georaster       IN MDSYS.sdo_georaster,
                         window          IN MDSYS.sdo_geometry,
                         parallel        IN number) 
                         RETURN number DETERMINISTIC;

-- This function is an internal function for calcSurfaceArea 
FUNCTION get_cell_geoms (rdt            IN varchar2,
                         raster_id      IN NUMBER,
                         window         IN MDSYS.sdo_geometry,
                         parallelDegree IN number,
                         parallel_table_cursor IN sdo_geor_int.parallelRefCur) 
                      RETURN target_cell_rows_type DETERMINISTIC
                      PIPELINED PARALLEL_ENABLE
                      (PARTITION parallel_table_cursor BY hash(pid));

-- ---------------------------------------------------------------------
-- NAME
--   makeRDTnamesUnique
--
-- DESCRIPTION
--   This routine resolves conflicting raster data table names by 
--   automatically renaming some of them so that all raster data tables 
--   are uniquely named afterwards.
--
-- ARGUMENTS
--   None.
--
-- NOTES
--   This routine is part of the fix for bug 3703288. In addition to applying
--   the necessary patchset that fixes this bug, an Oracle database of
--   version 10.1.0.2 or 10.1.0.3 needs to run this routine to resolve
--   potential RDT name conflicts. User may choose to run the above 
--   renameRDT() to explicitly rename existing RDTs before run this
--   routine.
--
--   This routine should be run while connected as a user with the DBA role.
--
-- ---------------------------------------------------------------------
PROCEDURE makeRDTnamesUnique;


-- ---------------------------------------------------------------------
-- NAME
--   calcRasterNominalSize
--
-- DESCRIPTION
--   This routine calculates the total length of the raster blocks of
--   a GeoRaster object as if it is uncompressed and not sparse.
--
-- ARGUMENTS
--   geor       - the GeoRaster object
--   padding    - indicates whether to consider padding in the blocks
--   pyramid    - indicates whether to consider pyramids
--   bitmapMask - indicates whether to consider associated bitmap masks
--
-- NOTES
--   All the argument are case insensitive. 
--   The result is in bytes.
--    
-- ---------------------------------------------------------------------
FUNCTION calcRasterNominalSize
(
  geor       IN MDSYS.SDO_GEORASTER,
  padding    IN VARCHAR2 DEFAULT 'TRUE',
  pyramid    IN VARCHAR2 DEFAULT 'TRUE',
  bitmapMask IN VARCHAR2 DEFAULT 'TRUE'
)
RETURN NUMBER DETERMINISTIC PARALLEL_ENABLE; 

-- ---------------------------------------------------------------------
-- NAME
--   calcRasterStorageSize
-- DESCRIPTION
--   This routine calculates the actual length of the raster blocks of 
--   a GeoRaster object.
--
-- ARGUMENTS
--   geor - the GeoRaster object
--
-- NOTES
--   The result is in bytes.
--
-- ---------------------------------------------------------------------
FUNCTION calcRasterStorageSize
(
  geor       IN MDSYS.SDO_GEORASTER
)
RETURN NUMBER DETERMINISTIC PARALLEL_ENABLE;

-- ---------------------------------------------------------------------
-- NAME
--   calcOptimizedBlockSize
-- DESCRIPTION
--   This routine calculates the optimized blockSize based on dimensionSize and--   user input seed blockSize. 
--
-- ARGUMENTS
--   dimensionSize - dimension size array, whose length must be 3. 
--   blockSize - block size array, whose length must be 3.
--   pyramidLevel - pyramid level, default value is 0.
--
-- NOTES
--
-- ---------------------------------------------------------------------
PROCEDURE calcOptimizedBlockSize
(
  dimensionSize       IN MDSYS.SDO_NUMBER_ARRAY,
  blockSize           IN OUT MDSYS.SDO_NUMBER_ARRAY,
  pyramidLevel        IN number default 0
);

-- ---------------------------------------------------------------------
-- NAME
--   fillEmptyBlocks 
-- DESCRIPTION
--   This routine fills in all empty blocks with background values
--   specified in the parameter
--
-- ARGUMENTS
--   geor     - the GeoRaster object
--   bgValues - background values for filling sparse data
--
-- NOTES
--
-- ---------------------------------------------------------------------
PROCEDURE fillEmptyBlocks 
(
  geor IN OUT MDSYS.SDO_GEORASTER,
  bgValues IN MDSYS.SDO_NUMBER_ARRAY DEFAULT NULL
);

-- NAME
--   emptyBlocks 
-- DESCRIPTION
--   This routine make blocks empty, if the blocks only contains background values
--   specified in the parameter
--
-- ARGUMENTS
--   geor     - the GeoRaster object
--   bgValues - background values for filling sparse data
--
-- NOTES
--
-- ---------------------------------------------------------------------
PROCEDURE emptyBlocks 
(
  geor IN OUT MDSYS.SDO_GEORASTER,
  bgValues IN MDSYS.SDO_NUMBER_ARRAY DEFAULT NULL
);

--
-- NAME:
--      calcWorldFileParams
--
-- DESCRIPTION
--      Calculate the six-parameters of a World File from a rectified GeoRaster.
--
-- ARGUMENTS
--      geoRaster      - A SDO_GEORASTER object with a affine transformation 
--                       model SRS
--      pyramidLevel   - The pyramid level to whish the world file six-parameters 
--                       will refers to. The default value is zero.
--
-- RETURN
--      SDO_ NUMBER_ARRAY with the following content:
--      
--      (1) - A : pixel size in the x-direction in map units/pixel
--      (2) - D : rotation about y-axis
--      (3) - B : rotation about x-axis
--      (4) - E : pixel size in the y-direction in map units, almost always negative
--      (5) - C : x-coordinate of the center of the upper left pixel
--      (6) - F : y-coordinate of the center of the upper left pixel
--
--      These values are used in a six-parameter affine transformation which can be
--      written as this set of equations:
--
--      x = A * column + B * row + C
--      y = D * column + E * row + F
--
--      The affine transformation assumes the raster origin is the center point of the
--      upperleft cell and the coordinate of upperleft cell is (0, 0) in the cell space.

FUNCTION calcWorldFileParams
( 
  georaster IN MDSYS.SDO_GEORASTER,
  pyramidLevel IN NUMBER DEFAULT 0
) 
  RETURN MDSYS.SDO_NUMBER_ARRAY;

--
-- NAME:
--      generateColorRamp
--
-- DESCRIPTION
--      Produce a sdo_geor_colormap object with a new color ramp based on
--      the values entered as parameters.
--
-- PARAMETERS:
--      colorSeeds    - A colormap object with the seed values for the 
--                      beginning and end of each section of the color ramp.
--      rampSteps     - An array with how many steps each section of the 
--                      color ramp should have.
--      cellValueType - indicate if the cell values are integer or float point
--      interpoParam  - interpolation parameters, example:
--                            'method=linear'
--                            'method=cosine'
--
FUNCTION generateColorRamp(
               colorSeeds     IN MDSYS.SDO_GEOR_COLORMAP,
               rampSteps      IN MDSYS.SDO_NUMBER_ARRAY,
               cellValueType  IN VARCHAR2,
               interpoParam   IN VARCHAR2 DEFAULT NULL)
         RETURN MDSYS.SDO_GEOR_COLORMAP;

--
-- NAME:
--      generateGrayRamp
--
-- DESCRIPTION
--      Produce a sdo_geor_grayscale object with a new shaded ramp based on
--      the values entered as parameters.
--
-- PARAMETERS:
--      shadeSeeds    - A grayscale object with the seed values for the 
--                      beginning and end of each section of the gray ramp.
--      rampSteps     - An array with how many steps each section of the 
--                      color ramp should have.
--      cellValueType - indicate if the cell values are integer or float point
--      interpoParam  - interpolation parameters, example:
--                            'method=linear'
--                            'method=cosine'
--
FUNCTION generateGrayRamp(
               graySeeds      IN MDSYS.SDO_GEOR_GRAYSCALE,
               rampSteps      IN MDSYS.SDO_NUMBER_ARRAY,
               cellValueType  IN VARCHAR2,
               interpoParam   IN VARCHAR2 DEFAULT NULL)
         RETURN MDSYS.SDO_GEOR_GRAYSCALE;

------------------------------------------------------------------------
--           Status Report Related Procedures
------------------------------------------------------------------------

-- ---------------------------------------------------------------------
-- NAME
--   createReportTable 
-- DESCRIPTION
--   Create the table for the operation status.
--
-- NOTES
--
-- ---------------------------------------------------------------------
PROCEDURE createReportTable;

-- ---------------------------------------------------------------------
-- NAME
--   dropReportTable 
-- DESCRIPTION
--   Drop the table for the operation status.
--
-- NOTES
--
-- ---------------------------------------------------------------------
PROCEDURE dropReportTable;

-- ---------------------------------------------------------------------
-- NAME
--   clearReportTable 
-- DESCRIPTION
--   Delete the records in the table for the operation status.
--   If the client_id is not null, only the records with the client_id
--   are deleted, otherwise, all the records are deleted. 
-- ARGUMENTS
--   client_id: a unique id to identify the session. 
--
-- NOTES
--   This procedure will only commit on the report table so that 
--   other sessions can see the committed results. 
-- ---------------------------------------------------------------------
PROCEDURE clearReportTable(client_id in number default null);

-- ---------------------------------------------------------------------
-- NAME
--   isReporting 
-- DESCRIPTION
--   Check if any session has status report enabled. 
-- RETURN
--   1: There are session(s) with status report enabled.
--   0: There is no session with status report enabled. 
--
-- NOTES
-- ---------------------------------------------------------------------
FUNCTION isReporting RETURN NUMBER;

-- ---------------------------------------------------------------------
-- NAME
--   enableReport 
-- DESCRIPTION
--   Enable the status report in this session. 
--
-- NOTES
-- ---------------------------------------------------------------------
PROCEDURE enableReport;

-- ---------------------------------------------------------------------
-- NAME
--   disableReport 
-- DESCRIPTION
--   Disable the status report in this session. 
--
-- NOTES
-- ---------------------------------------------------------------------
PROCEDURE disableReport;

-- ---------------------------------------------------------------------
-- NAME
--   setseqid 
-- DESCRIPTION
--   Set the sequence id for the operation in one session. This can be used 
-- to identify the different operations in the same session. If this 
-- procedure is not called, the sequence id defaults to 0 in the status
-- report. 
-- ARGUMENTS
--   seq_id: an id to identify the operation in this session. 
--
-- NOTES
-- ---------------------------------------------------------------------
PROCEDURE setseqid(seq_id number);

-- ---------------------------------------------------------------------
-- NAME
--   setClientID 
-- DESCRIPTION
--   Set the client id for a session. This can be used 
--   to identify the different sessions under the same user.
--   The client id can be the database session id or the client id in 
--   the mid-tier environment. If this procedure is not called, the client 
--   id in the status report defaults to the database session id.  
-- ARGUMENTS
--   client_id: an id to identify the session. 
--
-- NOTES
-- ---------------------------------------------------------------------
PROCEDURE setClientID(client_id number);

-- ---------------------------------------------------------------------
-- NAME
--   getProgress 
-- DESCRIPTION
--   Get the lastest progress in percentage of a specific operation. 
--   
-- ARGUMENTS
--   client_id: a unique id to identify the session. 
--   seq_id: a unique id to identify the operation in this session. 
-- RETURNS
--   The percentage of the progress in a number between 0 and 1.  
-- NOTES
-- ---------------------------------------------------------------------
FUNCTION getProgress(client_id number, seq_id number default 0) 
  RETURN NUMBER;

-- ---------------------------------------------------------------------
-- NAME
--   getStatusReport 
-- DESCRIPTION
--   Get the lastest status of a specific operation. 
--   
-- ARGUMENTS
--   client_id: a unique id to identify the session. 
--   seq_id: a unique id to identify the operation in this session. 
-- RETURNS
--   A sdo_string2_array in the format: 
--     TIMESTAMP, OP_NAME, TARGET_RDT, TARGET_RID, OP_STATUS, DESCRIPTION. 
-- NOTES
-- ---------------------------------------------------------------------
FUNCTION getStatusReport(client_id number, seq_id number default 0) 
  RETURN MDSYS.sdo_string2_array DETERMINISTIC PARALLEL_ENABLE;

-- ---------------------------------------------------------------------
-- NAME
--   getAllStatusReport 
-- DESCRIPTION
--   Get the lastest status of the operations in the status table for
--   each client_id. 
-- ARGUMENTS
--   None.
-- RETURNS
--   A sdo_string2_arrayset in the format: 
--     TIMESTAMP, OP_NAME, TARGET_RDT, TARGET_RID, OP_STATUS, DESCRIPTION. 
-- NOTES
-- ---------------------------------------------------------------------
FUNCTION getAllStatusReport 
  RETURN MDSYS.sdo_string2_arrayset DETERMINISTIC PARALLEL_ENABLE;

------------------------------------------------------------------------
--           End of Status Report Related Procedures
------------------------------------------------------------------------


-- ---------------------------------------------------------------------
--           memory management
-- ---------------------------------------------------------------------

PROCEDURE setMaxMemSize
(
   maxMemSize        IN   NUMBER DEFAULT 16777216
);

FUNCTION  getMaxMemSize RETURN number DETERMINISTIC;

PROCEDURE setReadBlockMemSize
(
   memBlockSize   IN   NUMBER DEFAULT 32768
);

FUNCTION  getReadBlockMemSize RETURN number DETERMINISTIC;

PROCEDURE setWriteBlockMemSize
(
   memBlockSize    IN  NUMBER DEFAULT 65536
);

FUNCTION  getWriteBlockMemSize RETURN number DETERMINISTIC;



END SDO_GEOR_UTL;
/
show errors;


Rem ********************************************************************
Rem #16473696: Indicate Oracle-Supplied object
@?/rdbms/admin/sqlsessend.sql
Rem ********************************************************************


OHA YOOOO