Go to content Go to navigation and search

Home

Current Oracle Spatial Blog Articles

    Convert Single Geometry to Multi-part Geometry in Oracle Spatial
    Optimized Rectangle to 5 Point Polygon
    Centroid Package now supports Y ordinate seeding
    Convert GeoJSON document to Sdo_Geometry objects
    Implementation Of Travelling Salesman Problem
    Create Polygon From Bearings And Distances
    Function That Returns a Compass Point From a Whole Circle Bearing
    Playing around with Centroids by using different seed values
    GeoRaptor 4.x Update 2
    Simple Oracle C Sprintf or Java String.format
    Some Oriented Point Functions
    Extracting Inner Rings Changed Ordinate Ordering: A Trap For Players Who Don't Read Documentation!
    PLS-00306: wrong number or types of arguments in call to 'SDO_GEOMETRY'
    Converting Google Earth Formatted Longitude/Latitude points to decimal degrees
    Oracle Business Intelligence Warehousing and Analytics - Spatial Summit
    How far inside, is inside? Measuring actual distance.
    Noding and building a polygon from single, overlapping linestrings
    Analyzing Spatial Query Performance Improvements in Oracle Spatial and Graph 12c Through Cross-Vendor Comparison
    ST_VertexN / ST_PointN - Extracting a specific point from any geometry
    Convert Single Point stored in SDO_ORDINATES to SDO_POINT_TYPE
    Aggregate APPEND Islands and XOR polygons
    Circular Arcs in Geodetic Polygons
    Some SDO_GEOMETRY/DIMINFO handling functions
    Applying And Extending Oracle Spatial - Book Released
    Changing all DIMINFO sdo_tolerance values for all metadata records in one go.
    Building Polygons from Incomplete Linestrings using ST_PolygonBuilder
    Computing Cardinal Directions to nearby geometries
    Intersecting two aggregated polygon layers with SC4O
    Spatial and Oracle 12c
    Update Triggers and SDO_GEOMETRY Equality
    Duplicate Geometry data and Data Models
    CENTROID package update
    How to calculate cumulative length of a linestring
    Useful Package of Wrapper Functions for Sdo_Util.AffineTransforms
    Compute Location from known Lat/Long point using delta easting and northing in miles
    SDO_AGGR_SET_UNION
    Sorting SDO_GEOMETRY data using the ORDER BY clause of a SELECT statement
    Creating linestrings from points
    Rounding Coordinates or Ordinates in SDO_GEOMETRY
    Effects of Sdo_Geometry Ordinate Precision on Performance
    Effects of Sdo_Geometry Ordinate Precision on Storage
    The Spatial filtering of geometries: The effect of tolerances on relationships
    Application of Delaunay Triangulation and Inverse Distance Weighting (IDW) in Oracle for Soils Interpolation
    Selecting all SDO_GTYPE values for all tables/sdo_geometry columns in a schema
    CENTROID package - Tips for Use
    Announcing the Spatial Companion For Oracle (SC4O)
    Filtering Rings (Oracle Spatial)
    Splitting a polygon using one or more linestrings
    isValid, isSimple, Dimension and CoordDim methods for SDO_Geometry
    Line Merging or Collecting lines together: ST_LineMerger
    ST_DeleteVertex for Oracle SDO_Geometry based on Jaspa/JTS
    3D/4D and SRID aware Conversion functions for SDO_Geometry: WKT and EWKT
    Topological vs Non-Topological Simplification/Generalization of Aggregated Area Geometies in Oracle
    Filtering very short linestrings via bitmap function index
    CENTROID For Oracle
    Gridding a sdo_geometry line/polygon object (Oracle)
    Finding centre and radius of a circular geometry
    Constraining geometry type for sdo_geometry column in a table.
    CASE Statements and SDO_GEOMETRY
    The Power of Constraints and Indexes for Spatial Constraints: stopping duplicate points
    Replacement for SDO_GEOM.RELATE - ST_Relate based on JTS
    Changing Oracle Spatial Index Parameters on existing index
    Writing Excel Spreadsheets files from within the Oracle database using Java and PL/SQL
    Writing xSV (eg csv) files from within the Oracle database using Java and PL/SQL
    A simple spike finder for Spatial/Locator
    JTS Java class compilation for 11g and above
    Random Spatial Search Procedure
    Geometry Snapping using JTS in Oracle
    Exposing JTS's MinimumBoundingCircle functionality
    Exposing JTS's Densifier functionality
    Using JTS's Comparison Functions - HausdorffSimilarityMeasure & AreaSimilarityMeasure with SDO_GEOMETRY
    Free JTS-based Area/Length Functions
    Handy way of systematically fixing polygon geometries with 13349 and other errors
    Standalone CENTROID package now available for download
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 4 Processing Geodetic data
    Configurable Buffer: JTS and Oracle
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 3
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 2
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 1
    Building Lines into Polygons in Oracle Locator / Spatial
    Finding Intersection Points between Line and Polygon
    SDO2GeoJSON
    Free version of sdo_length
    Alternative to my SQL based GetNumRings function
    External Tables and SDO_Geometry data.
    layer_gtype keyword issue when indexing linear data on 11g
    String Tokenizer for Oracle
    Free Aggregate Method for Concatenating 2D Lines in Oracle Locator 10g
    Reducing 5 Vertex Polygon to Optimized Rectangle
    Square Buffer
    Converting decimal seconds to string
    SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT - 13356 Issues
    Valid conversion unit values for Oracle sdo_geom.sdo_length()
    Removing Steps in Gridded Vector Data - SmoothGrid for Oracle
    Oracle Spatial DISJOINT search/filtering
    Creating SDO_Geometry from geometric data recorded in the columns of a table
    Concave Hull Geometries in Oracle 11gR2
    Projecting SDO_GEOM_METADATA DIMINFO XY ordinates
    Instantiating MDSYS.VERTEX_TYPE
    New PL/SQL Packages - Rotate oriented point
    GeoRaptor Development Team
    Fast Refreshing Materialized View Containing SDO_GEOMETRY and SDO_GEOM.SDO_AREA function
    Performance of PL/SQL Functions using SQL vs Pure Code
    Implementing the BEST VicGrid Projection in Oracle 10gR2
    Making Sdo Geometry Metadata Update Generic Code
    ORA-13011 errors when using SDO_GEOM.VALIDATE_LAYER_WITH_CONTEXT()
    Extract Polygons from Compound Polygon
    Detecting sdo_geometries with compound (3-point Arcs) segments
    GEOMETRY_COLUMNS for Oracle Spatial
    Convert GML to SDO_Geometry in Oracle 10gR2
    Spatial Sorting of Data via Morton Key
    Swapping Ordinates in an SDO_GEOMETRY object
    New To_3D Function
    Extend (Reduce/Contract/Skrink) Function for Oracle
    Loading and Processing GPX 1.1 files using Oracle XMLDB
    Loading Spatial Data from an external CSV file in Oracle
    Calling the Oracle Spatial shapefile loader from within the Oracle database itself
    Implementing SDO_VertexUpdate/ST_VertexUpdate for Oracle
    Implementing SDO_RemovePoint/ST_RemovePoint for Oracle
    Implementing SDO_AddPoint/ST_AddPoint for Oracle
    ESRI ArcSDE Exverted and Inverted Polygons and Oracle Spatial
    Funky Fix Ordinates By Formula
    Implementing a SetPoint/ST_SetPoint function in Oracle
    Implementing an ST_SnapToGrid (PostGIS) function for Oracle Spatial
    Generating random point data
    Implementing an Affine/ST_Affine function for Oracle Spatial
    Implementing a Scale/ST_Scale function for Oracle Spatial
    Implementing a Parallel/ST_Parallel function for linestring data for Oracle Spatial
    Implementing a Rotate/ST_Rotate function for Oracle Spatial
    Limiting table list returned when connecting to Oracle Database using ODBC
    ST_Azimuth for Oracle: AKA Cogo.Bearing
    Implementing a Translate/ST_Translate/Move function for Oracle Spatial
    Elem_Info_Array Processing: An alternative to SDO_UTIL.GetNumRings and querying SDO_ELEM_INFO itself
    Minumum Bounding Rectangle (MBR) Object Type for Oracle
    How to extract elements from the result of an sdo_intersection of two polygons.
    How to restart a database after failed parameter change
    Fixing failed spatial indexes after import using data pump
    generate_series: an Oracle implementation in light of SQL Design Patterns
    Multi-Centroid Shootout
    Oracle Spatial Centroid Shootout
    On the use of ROLLUP in Oracle SELECT statements
    Surrounding Parcels
    Spatial Pipelining
    Using Oracle's SDO_NN Operator - Some examples
    Converting distances and units of measure in Oracle Locator
    Split Sdo_Geometry Linestring at a known point
    Forcing an Sdo_Geometry object to contain only points, lines or areas
    Unpacking USER_SDO_GEOM_METADATA's DIMINFO structure using SQL
    Generating multi-points from single point records in Oracle Spatial
    Object Tables of Sdo_Geometry
    Oracle Locator vs Oracle Spatial: A Reflection on Oracle Licensing of the SDO_GEOM Package
    FAST REFRESHing of Oracle Materialized Views containing Sdo_Geometry columns
    Australian MGA/AMG Zone Calculation from geographic (longitude/latitude) data
    Loading Shapefiles (SHP) into Oracle Spatial
    Oracle Spatial Mapping and Map Rendering Performance Tips
    The significance of sdo_lb/sdo_ub in USER_SDO_GEOM_METDATA: Do I need it?
    Oracle Spatial Forum - Melbourne April 2007
    Layer_GTypes for spatial indexes
    Oracle's SQL/MM Compliant Types
    Tips and Tricks

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.

CENTROID For Oracle

Wednesday January 04 2012 at 05:17

Keywordscentroid multipart polygon linestring point multilinestring multipolygon multipoint guarantee inside
Summary

A set of enhanced centroid functions are presented for use with Oracle Sdo_Geometry data.

My CENTROID PL/SQL package is a hot download from this site. It seems there is a need out there for variations on the generating of centroids.

Recently I ported my centroid algorithms to SQL Server Spatial (Denali). In doing so a few improvements or changes were made. These include the ability to:

  • Provide the centroid polygon algorithm with a seed X ordinate to complement the X ordinate that is the midpoint of the MBR of the polygon or the average X ordinate of all the vertices in the polygon;
  • Select the smallest or largest part of a multipart line or polygon geometry as the target for the centroid.

This article now replaces all other articles on my Oracle SDO_GEOMETRY based centroid algorithms.

From the CENTROID package specification, the following functions are available.

  1.   /* ----------------------------------------------------------------------------------------
  2.   * @function   : centroid_p
  3.   * @precis     : Generates centroid for a point (itself) or multipoint.
  4.   * @version    : 1.3
  5.   * @description: This function creates centroid of multipoint via averaging of ordinates.
  6.   * @param      : p_geometry     : MDSYS.SDO_GEOMETRY : The geometry object.
  7.   * @param      : p_round_x      : Number : Ordinate rounding precision for X ordinates.
  8.   * @param      : p_round_y      : Number : Ordinate rounding precision for Y ordinates.
  9.   * @param      : p_round_z      : Number : Ordinate rounding precision for Z ordinates.
  10.   * @return     : centroid       : MDSYS.SDO_GEOMETRY : The centroid.
  11.   * @requires   : GetVector()
  12.   * @history    : Simon Greener - Jul 2008 - Original coding of centroid_p as internal function
  13.   * @history    : Simon Greener - Jan 2012 - Exposed internal function.
  14.   * @copyright  : Free for public use
  15.   **/
  16.   FUNCTION centroid_p(p_geometry IN mdsys.sdo_geometry,
  17.                       p_round_x  IN NUMBER := 3,
  18.                       p_round_y  IN NUMBER := 3,
  19.                       p_round_z  IN NUMBER := 2)
  20.     RETURN MDSYS.SDO_GEOMETRY DETERMINISTIC;
  21.   /* ----------------------------------------------------------------------------------------
  22.   * @function   : centroid_a
  23.   * @precis     : Generates centroid for a polygon.
  24.   * @version    : 1.3
  25.   * @description: The standard mdsys.sdo_geom.sdO_centroid function does not guarantee
  26.   *               that the centroid it generates falls inside the polygon.
  27.   *               This function ensures that the centroid of any arbitrary polygon falls within the polygon.
  28.   * @param      : p_geometry     : MDSYS.SDO_GEOMETRY : The geometry object.
  29.   * @param      : p_start        : pls_integer : 0 = Use average of all Area's vertices for starting X centroid calculation
  30.   *                                              1 = Use centre X of MBR
  31.   *                                              2 = User supplied starting seed X
  32.   * @param      : p_seed_x       : Number : Starting X ordinate for which a Y that is inside the polygon is returned.
  33.   * @param      : p_round_x      : pls_integer : Ordinate rounding precision for X ordinates.
  34.   * @param      : p_round_y      : pls_integer : Ordinate rounding precision for Y ordinates.
  35.   * @param      : p_loops        : pls_integer : Number of attempts to find centroid based on small changes to seed
  36.   * @return     : centroid       : MDSYS.SDO_GEOMETRY : The centroid.
  37.   * @requires   : GetVector()
  38.   * @history    : Simon Greener - Jul 2008 - Original coding of centroid_a as internal function
  39.   * @history    : Simon Greener - Jan 2012 - Exposed internal function. Added p_seed_x support.
  40.   * @copyright  : Free for public use
  41.   **/
  42.   FUNCTION centroid_a(p_geometry IN mdsys.sdo_geometry,
  43.                       p_start    IN pls_integer DEFAULT 1,
  44.                       p_seed_x   IN NUMBER      DEFAULT NULL,
  45.                       p_round_x  IN pls_integer DEFAULT 3,
  46.                       p_round_y  IN pls_integer DEFAULT NULL,
  47.                       p_loops    IN pls_integer DEFAULT 10)
  48.     RETURN MDSYS.SDO_GEOMETRY DETERMINISTIC;
  49.   /* ----------------------------------------------------------------------------------------
  50.   * @function   : Centroid_l
  51.   * @precis     : Generates centroid for a linestring.
  52.   * @version    : 1.3
  53.   * @description: The standard MDSYS.SDO_GEOM.SDO_CENTROID function does not guarantee
  54.   *               that the centroid it generates falls inside the polygon.
  55.   *               This function ensures that the centroid of any arbitrary polygon falls within the polygon.
  56.   * @param      : p_geometry           : MDSYS.SDO_GEOMETRY : The geometry object.
  57.   * @param      : p_position_as_ratio  : Number : Position along multi-line/line where "centroid" created.
  58.   * @param      : p_round_x            : Number : Ordinate rounding precision for X ordinates.
  59.   * @param      : p_round_y            : Number : Ordinate rounding precision for Y ordinates.
  60.   * @param      : p_round_z            : Number : Ordinate rounding precision for Z ordinates.
  61.   * @return     : centroid             : MDSYS.SDO_GEOMETRY : The centroid.
  62.   * @requires   : GetVector()
  63.   * @history    : Simon Greener - Jul 2008 - Original coding of centroid_l as internal function
  64.   * @history    : Simon Greener - Jan 2012 - Exposed internal function.
  65.   * @copyright  : Free for public use
  66.   **/
  67.   FUNCTION centroid_l(p_geometry          IN mdsys.sdo_geometry,
  68.                       p_position_as_ratio IN NUMBER := 0.5,
  69.                       p_round_x           IN NUMBER := 3,
  70.                       p_round_y           IN NUMBER := 3,
  71.                       p_round_z           IN NUMBER := 2)
  72.     RETURN MDSYS.SDO_GEOMETRY DETERMINISTIC;
  73.   /* ----------------------------------------------------------------------------------------
  74.   * @function   : SDO_Centroid
  75.   * @precis     : Generates centroid for a polygon.
  76.   * @version    : 1.5
  77.   * @description: The standard MDSYS.SDO_GEOM.SDO_CENTROID function does not guarantee
  78.   *               that the centroid it generates falls inside the polygon.   Nor does it
  79.   *               generate a centroid for a multi-part polygon shape.
  80.   *               This function ensures that the centroid of any arbitrary polygon
  81.   *               falls within the polygon. Also provides centroid functions for multipoints and linestrings.
  82.   * @param      : p_geometry     : MDSYS.SDO_GEOMETRY : The geometry object.
  83.   * @param      : p_start        : Number : 0 = Use average of all Area's vertices for starting X centroid calculation
  84.   *                                         1 = Use centre X of MBR
  85.   * @param      : p_largest      : Number : 0 = Use smallest of any multipart geometry.
  86.   *                                         1 = Use largest of any multipart geometry.
  87.   * @param      : p_round_x      : Number : Ordinate rounding precision for X ordinates.
  88.   * @param      : p_round_y      : Number : Ordinate rounding precision for Y ordinates.
  89.   * @param      : p_round_z      : Number : Ordinate rounding precision for Z ordinates.
  90.   * @return     : centroid       : MDSYS.SDO_GEOMETRY : The centroid.
  91.   * @requires   : GetVector()
  92.   * @history    : Simon Greener - Mar 2008 - Total re-write of algorithm following on from cases the original algorithm didn't handle.
  93.   *                                          The new algorithm does everything in a single SQL statement which can be run outside of this function if needed.
  94.   *                                          The algorithm is based on a known method for filling a polygon which counts the type and number of crossings of a
  95.   *                                          "ray" (in this case a vertical line) across a polygon boundary. The new algorithm also has improved handling of
  96.   *                                          multi-part geometries and also generates a starting X ordinate for the vertical "ray" using vertex averaging
  97.   *                                          rather than the mid point of a part's MBR. This is to try and "weight" the centroid more towards where detail exists.
  98.   *               Simon Greener - Jul 2008 - Standalone version with no dependencies other than the need for external object types.
  99.   * @copyright  : Free for public use
  100.   **/
  101.     FUNCTION sdo_Centroid(
  102.     p_geometry     IN MDSYS.SDO_GEOMETRY,
  103.     p_start        IN NUMBER := 1,  
  104.     p_largest      IN NUMBER := 1,  
  105.     p_round_x      IN NUMBER := 3,
  106.     p_round_y      IN NUMBER := 3,
  107.     p_round_z      IN NUMBER := 2)
  108.     RETURN MDSYS.SDO_GEOMETRY DETERMINISTIC;
  109.   /**
  110.   * Overload of main sdo_centroid function
  111.   * @param      : p_tolerance    : Number : Single tolerance for use with all ordinates.
  112.   *                                         Expressed in dataset units eg decimal degrees if 8311.
  113.   *                                         See Convert_Distance for method of converting distance in meters to dataset units.
  114.   **/
  115.   FUNCTION sdo_centroid (
  116.     p_geometry     IN MDSYS.SDO_Geometry,
  117.     p_start        IN NUMBER := 1,
  118.     p_tolerance    IN NUMBER )
  119.     RETURN MDSYS.SDO_Geometry deterministic;
  120.   /**
  121.   * Overload of main sdo_centroid function
  122.   * @param      : p_dimarray  : Number : Supplies all tolerances when processing vertices.
  123.   *                                      Note that the function requires the sdo_tolerances inside the diminfo to be expressed in dataset
  124.   *                                      units eg decimal degrees if 8311. But for Oracle this is in meters for long/lat and dataset units otherwise.
  125.   *                                      Thus use of this wrapper for geodetic data IS NOT RECOMMENDED.
  126.   *                                      See Convert_Distance for method of converting distance in meters to dataset units.
  127.   **/
  128.   FUNCTION Sdo_Centroid(
  129.     p_geometry     IN MDSYS.SDO_GEOMETRY,
  130.     p_start        IN NUMBER := 1,
  131.     p_dimarray     IN MDSYS.SDO_DIM_ARRAY)
  132.     RETURN MDSYS.SDO_Geometry deterministic;
  133.   /* ----------------------------------------------------------------------------------------
  134.   * @function   : Sdo_Multi_Centroid
  135.   * @precis     : Generates centroids for a all parts of a multi-polygon.
  136.   * @version    : 1.0
  137.   * @description: The standard MDSYS.SDO_GEOM.SDO_GEOMETRY function does not guarantee
  138.   *               that the centroid it generates falls inside the polygon.   Nor does it
  139.   *               generate a centroid for a multi-part polygon shape.
  140.   *               This function generates a point for every part of a 2007 multi-part polygon..
  141.   * @param      : p_geometry : MDSYS.SDO_GEOMETRY : The polygon shape.
  142.   * @param      : p_start    : Number : 0 = Use average of all Area's vertices for starting X centroid calculation
  143.   *                                     1 = Use centre X of MBR
  144.   * @param      : p_round_x  : Number : Ordinate rounding precision for X ordinates.
  145.   * @param      : p_round_y  : Number : Ordinate rounding precision for Y ordinates.
  146.   * @param      : p_round_z  : Number : Ordinate rounding precision for Z ordinates.
  147.   * @return     : centroid   : MDSYS.SDO_GEOMETRY : The centroids of the parts as a multi-part shape.
  148.   * @history    : Simon Greener - Jun 2006 - Original coding.
  149.   * @copyright  : Free for public use
  150.   **/  
  151.   FUNCTION SDO_Multi_Centroid(
  152.     p_geometry  IN MDSYS.SDO_Geometry,
  153.     p_start     IN NUMBER := 1,
  154.     p_round_x   IN NUMBER := 3,
  155.     p_round_y   IN NUMBER := 3,
  156.     p_round_z   IN NUMBER := 2)
  157.    RETURN MDSYS.SDO_Geometry deterministic;
  158.   /**
  159.   * Overload of main sdo_multi_centroid function
  160.   * @param      : p_geometry  : MdSys.Sdo_Geometry : The sdo_geometry object.
  161.   * @param      : p_start     : Number : 0 = Use average of all Area's vertices for starting X centroid calculation
  162.   *                                      1 = Use centre X of MBR
  163.   * @param      : p_tolerance : Number : Tolerance used when processing vertices.
  164.   * @return     : centroid    : MDSYS.SDO_GEOMETRY : The centroids of the parts as a multi-part shape.
  165.   * @history    : Simon Greener - Jun 2006 - Original coding.
  166.   * @copyright  : Free for public use
  167.   **/
  168.   FUNCTION sdo_multi_centroid(
  169.     p_geometry  IN MDSYS.SDO_Geometry,
  170.     p_start     IN NUMBER := 1,
  171.     p_tolerance IN NUMBER)
  172.     RETURN MDSYS.SDO_Geometry deterministic;
  173.   /**
  174.   * Overload of main sdo_multi_centroid function
  175.   * @param      : p_geometry  : MdSys.Sdo_Geometry : The sdo_geometry object.
  176.   * @param      : p_start     : Number : 0 = Use average of all Area's vertices for starting X centroid calculation
  177.   *                                      1 = Use centre X of MBR
  178.   * @param      : p_dimarray  : Number : Supplies all tolerances when processing vertices.
  179.   *                                      Note that the function requires the sdo_tolerances inside the diminfo to be expressed in dataset
  180.   *                                      units eg decimal degrees if 8311. But for Oracle this is in meters for long/lat and dataset units otherwise.
  181.   *                                      Thus use of this wrapper for geodetic data IS NOT RECOMMENDED.
  182.   *                                      See Convert_Distance for method of converting distance in meters to dataset units.
  183.   * @return     : centroid    : MDSYS.SDO_GEOMETRY : The centroids of the parts as a multi-part shape.
  184.   * @history    : Simon Greener - Jun 2006 - Original coding.
  185.   * @copyright  : Free for public use
  186.   **/
  187.   FUNCTION sdo_multi_centroid(
  188.     p_geometry  IN MDSYS.SDO_Geometry,
  189.     p_start     IN NUMBER := 1,
  190.     p_dimarray  IN MDSYS.SDO_Dim_Array)
  191.     RETURN MDSYS.SDO_Geometry deterministic;

Now for some testing!

MultiPoint

  1. WITH multiPoint AS (
  2.   SELECT 'O' AS label,  sdo_geometry('MULTIPOINT((0 0),(100 0),(100 100),(0 100),(150 110),(150 150),(110 150),(110 110))',NULL) AS geom
  3.     FROM dual
  4. )
  5. SELECT 'O' AS label, geom FROM multiPoint
  6. UNION ALL
  7. SELECT 'M' AS label, centroid.Centroid_P(geom,3,3,3) AS geom FROM multiPoint
  8. UNION ALL
  9. SELECT 'S' AS label, sdo_geom.sdo_centroid(geom,0.005) AS geom FROM multiPoint;
  10. -- Results
  11. LABEL GEOM
  12. ----- -----------------------------------------------------------------------------------------------------------------------------------------------------
  13. O     MDSYS.SDO_GEOMETRY(2005,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1,8),MDSYS.SDO_ORDINATE_ARRAY(0,0,100,0,100,100,0,100,150,110,150,150,110,150,110,110))
  14. M     MDSYS.SDO_GEOMETRY(2005,NULL,MDSYS.SDO_POINT_TYPE(90,90,NULL),NULL,NULL)
  15. S     MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(90,90,NULL),NULL,NULL)

Centroid_L

  1. WITH testLine AS (
  2.    SELECT sdo_geometry('LINESTRING(258.72254365233152 770.97400259630615, 268.79365642517564 739.08214548229967, 278.86476919801976 707.1902883682933, 332.57737065318844 693.76213800450114, 366.14774656266889 676.97695004976094, 426.57442319973364 697.11917559544918, 520.57147574627891 737.40362668682576, 631.35371624756431 744.11770186872184, 829.41893411349884 797.83030332389046, 1547.8249785763801 791.11622814199438, 1205.4071442996797 895.18439346138371, 832.77597170444687 1039.5370098721496, 490.3581374277465 1086.5355361454222, 416.50331042688953 1076.464423372578, 381.25441572193506 1059.6792354178378, 346.00552101698065 1042.8940474630976, 320.82773908487036 1019.3947843264614, 295.64995715276001 995.89552118982499, 287.25736317538986 964.00366407581862, 278.86476919801976 932.11180696181225, 282.2218067889678 891.82735587043567, 277.18625040254574 858.25697996095528, 272.15069401612368 824.68660405147489, 258.72254365233152 770.97400259630615)',NULL) AS geom
  3.      FROM dual
  4. )
  5. SELECT 'O' AS label, geom FROM testLine
  6. UNION ALL
  7. SELECT a.Column_Value*10 || '%' AS label, CENTROID.Centroid_L(geom,a.Column_Value/10.0,3,3,2) AS geom
  8.   FROM testLine,
  9.        TABLE(centroid.generate_series(0,9,1)) a;
  10. -- Results
  11. --
  12. LABEL GEOM
  13. ----- ----------------------------------------------------------------------------------
  14. NULL  MDSYS.SDO_GEOMETRY(2002,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),MDSYS.SDO_ORDINATE_ARRAY(258.722543652332,770.974002596306,268.793656425176,739.0821454823,278.86476919802,707.190288368293,332.577370653188,693.762138004501,366.147746562669,676.976950049761,426.574423199734,697.119175595449,520.571475746279,737.403626686826,631.353716247564,744.117701868722,829.418934113499,797.83030332389,1547.82497857638,791.116228141994,1205.40714429968,895.184393461384,832.775971704447,1039.53700987215,490.358137427746,1086.53553614542,416.50331042689,1076.46442337258,381.254415721935,1059.67923541784,346.005521016981,1042.8940474631,320.82773908487,1019.39478432646,295.64995715276,995.895521189825,287.25736317539,964.003664075818,278.86476919802,932.111806961812,282.221806788968,891.827355870435,277.186250402546,858.256979960955,272.150694016124,824.686604051475,258.722543652332,770.974002596306))
  15. 0%    MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(258.723,770.974,NULL),NULL,NULL)
  16. 10%   MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(489.061,723.899,NULL),NULL,NULL)
  17. 20%   MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(772.455,782.382,NULL),NULL,NULL)
  18. 30%   MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(1061.852,795.658,NULL),NULL,NULL)
  19. 40%   MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(1353.305,792.934,NULL),NULL,NULL)
  20. 50%   MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(1455.077,819.304,NULL),NULL,NULL)
  21. 60%   MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(1176.948,906.209,NULL),NULL,NULL)
  22. 70%   MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(905.164,1011.495,NULL),NULL,NULL)
  23. 80%   MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(620.926,1068.614,NULL),NULL,NULL)
  24. 90%   MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(340.85,1038.082,NULL),NULL,NULL)
  25. --
  26.  11 ROWS selected

Centroid_A

First, my test polygon.

  1. WITH testPoly AS (
  2.    SELECT sdo_geometry('POLYGON((2300 -700, 2800 -300, 2300 700, 2800 1100, 2300 1100, 1800 1100, 2300 400, 2300 200, 2100 100, 2500 100, 2300 -200, 1800 -300, 2300 -500, 2200 -400, 2400 -400, 2300 -700),
  3.                                (2300 1000, 2400  900, 2200 900, 2300 1000))',NULL) AS geom
  4.      FROM dual
  5. )
  6. SELECT 'O' AS Label, geom FROM testPoly
  7. UNION ALL
  8. SELECT 'A' AS Label,
  9.        centroid.centroid_a(geom,0,NULL,3,3,3) AS geom  FROM testPoly
  10. UNION ALL
  11. SELECT 'M' AS Label,
  12.        centroid.centroid_a(geom,1,NULL,3,3,3) AS geom  FROM testPoly
  13. UNION ALL
  14. SELECT 'U' AS Label,
  15.        centroid.centroid_a(geom,2,2050,3,3,3) AS geom  FROM testPoly
  16. UNION ALL
  17. SELECT 'S' AS Label,
  18.        sdo_geom.sdo_centroid(geom,0.005) AS geom FROM testPoly;
  19. -- Results
  20. --
  21. LABEL GEOM
  22. ----- ----------------------------------------------------------------------------------------------------
  23. O     MDSYS.SDO_GEOMETRY(2003,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1,33,2003,1),MDSYS.SDO_ORDINATE_ARRAY(2300,-700,2800,-300,2300,700,2800,1100,2300,1100,1800,1100,2300,400,2300,200,2100,100,2500,100,2300,-200,1800,-300,2300,-500,2200,-400,2400,-400,2300,-700,2300,1000,2400,900,2200,900,2300,1000))
  24. A     MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(2300,550,NULL),NULL,NULL)
  25. M     MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(2300,550,NULL),NULL,NULL)
  26. U     MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(2050,925,NULL),NULL,NULL)
  27. S     MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(2346.66666666667,292.307692307692,NULL),NULL,NULL)

Now some examples relating to weighting and using a X ordinate seed.

  1. WITH testPoly AS (
  2. SELECT sdo_geometry('POLYGON((258.72254365233152 770.97400259630615, 268.79365642517564 739.08214548229967, 278.86476919801976 707.1902883682933, 332.57737065318844 693.76213800450114, 366.14774656266889 676.97695004976094, 426.57442319973364 697.11917559544918, 520.57147574627891 737.40362668682576, 631.35371624756431 744.11770186872184, 829.41893411349884 797.83030332389046, 1547.8249785763801 791.11622814199438, 1205.4071442996797 895.18439346138371, 832.77597170444687 1039.5370098721496, 490.3581374277465 1086.5355361454222, 416.50331042688953 1076.464423372578, 381.25441572193506 1059.6792354178378, 346.00552101698065 1042.8940474630976, 320.82773908487036 1019.3947843264614, 295.64995715276001 995.89552118982499, 287.25736317538986 964.00366407581862, 278.86476919801976 932.11180696181225, 282.2218067889678 891.82735587043567, 277.18625040254574 858.25697996095528, 272.15069401612368 824.68660405147489, 258.72254365233152 770.97400259630615))',NULL) AS geom FROM dual
  3. )
  4. SELECT 'O' AS Label, geom AS geom FROM testPoly
  5. UNION ALL
  6. SELECT 'A' AS Label, centroid.centroid_a(geom,0,NULL,2,2,2) AS geom FROM testPoly
  7. UNION ALL
  8. SELECT 'M' AS Label, centroid.centroid_a(geom,1,NULL,2,2,2) AS geom FROM testPoly
  9. UNION ALL
  10. SELECT 'U' AS Label, centroid.centroid_a(geom,2,259,2,2,2) AS geom FROM testPoly
  11. UNION ALL
  12. SELECT 'S' AS Label, sdo_geom.sdo_centroid(geom,0.005) AS geom FROM testPoly;
  13. -- Results
  14. --
  15. LABEL GEOM
  16. ----- ----------------------------------------------------------------------------------------------------
  17. O     MDSYS.SDO_GEOMETRY(2003,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1),MDSYS.SDO_ORDINATE_ARRAY(258.722543652332,770.974002596306,268.793656425176,739.0821454823,278.86476919802,707.190288368293,332.577370653188,693.762138004501,366.147746562669,676.976950049761,426.574423199734,697.119175595449,520.571475746279,737.403626686826,631.353716247564,744.117701868722,829.418934113499,797.83030332389,1547.82497857638,791.116228141994,1205.40714429968,895.184393461384,832.775971704447,1039.53700987215,490.358137427746,1086.53553614542,416.50331042689,1076.46442337258,381.254415721935,1059.67923541784,346.005521016981,1042.8940474631,320.82773908487,1019.39478432646,295.64995715276,995.895521189825,287.25736317539,964.003664075818,278.86476919802,932.111806961812,282.221806788968,891.827355870435,277.186250402546,858.256979960955,272.150694016124,824.686604051475,258.722543652332,770.974002596306))
  18. A     MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(475.25,901.23,NULL),NULL,NULL)
  19. M     MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(903.27,904.685,NULL),NULL,NULL)
  20. U     MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(259,771.085,NULL),NULL,NULL)
  21. S     MDSYS.SDO_GEOMETRY(2001,NULL,MDSYS.SDO_POINT_TYPE(701.967711917354,888.255501812355,NULL),NULL,NULL)

General Centroid Method

  1. WITH multiPoly AS (
  2.    SELECT sdo_geometry('MULTIPOLYGON (((0 0, 100 0, 100 100, 0 100, 0 0)), ((110 110, 150 110, 150 150, 110 150, 110 110)))',NULL) AS geom
  3.      FROM dual
  4. )
  5. SELECT 'O' AS label, geom FROM multiPoly
  6. UNION ALL
  7. SELECT 'PNTS' AS label,
  8.        sdo_geom.sdo_buffer(
  9.               centroid.sdo_Centroid(sdo_geometry('MULTIPOLYGON (((0 0, 100 0, 100 100, 0 100, 0 0)), ((110 110, 150 110, 150 150, 110 150, 110 110)))',NULL) ,
  10.                                 1 /* Weight By MBR not Vertices */,
  11.                                 1 /* Use Largest part in any multipart */,
  12.                                 3,3,3),
  13.               5,0.005) AS geom
  14.   FROM multiPoly;
  15. -- Results
  16. --
  17. LABEL GEOM
  18. ----- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  19. O     MDSYS.SDO_GEOMETRY(2007,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1,11,1003,1),MDSYS.SDO_ORDINATE_ARRAY(0,0,100,0,100,100,0,100,0,0,110,110,150,110,150,150,110,150,110,110))
  20. PNTS  MDSYS.SDO_GEOMETRY(2003,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,2),MDSYS.SDO_ORDINATE_ARRAY(50,45,55,50,50,54.9999999999999,45,50,50,45))

Multi-Centroid Generator

  1. WITH multiPoly AS (
  2.    SELECT sdo_geometry('MULTIPOLYGON (((0 0, 100 0, 100 100, 0 100, 0 0)), ((110 110, 150 110, 150 150, 110 150, 110 110)))',NULL) AS geom FROM dual
  3. )
  4. SELECT 'O' AS label, geom FROM multiPoly
  5. UNION ALL
  6. SELECT 'PNTS' AS label, sdo_geom.sdo_buffer(CENTROID.SDO_Multi_Centroid(geom,1 /* Weight By MBR not Vertices */,3,3,3),5,0.005) AS geom
  7.   FROM multiPoly;
  8. -- Results
  9. --
  10. LABEL GEOM
  11. ----- ----------------------------------------------------------------------------------------------------------------------------------------
  12. O     MDSYS.SDO_GEOMETRY(2007,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,1,11,1003,1),MDSYS.SDO_ORDINATE_ARRAY(0,0,100,0,100,100,0,100,0,0,110,110,150,110,150,150,110,150,110,110))
  13. PNTS  MDSYS.SDO_GEOMETRY(2007,NULL,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,2,11,1003,2),MDSYS.SDO_ORDINATE_ARRAY(130,125,135,130,130,135,125,130,130,125,50,45,55,50,50,54.9999999999999,45,50,50,45))
I hope this continues to be useful to those users of my centroid package and others reading this for the first time.sql

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