In Developing Some Ideas For The Compression/Decompression Of Sdo_Geometry Objects, I Had Cause To Create Two PL/SQL Functions called Geocompress and Geodecompress.
I Have Not Done This For A While And Slapped Myself When I Ran Into something I Should Have Known Would Arise, as I have seen it before, and because it is documented as happening!
The issue came about when using the Sdo_Util.Extract function for processing the inner rings (holes) of a polygon:
geometry IN SDO_GEOMETRY,
Description Returns The Two-Dimensional Geometry That Represents A Specified Element (And Optionally A Ring) Of The Input Two-Dimensional Geometry.
…. For A Polygon With One Or More Holes, The Returned Geometry Representing AnExtracted Interior Ring Is Reoriented So That Its Vertices Are Presented In Counterclockwise Order.
Let’s take a look at a multipolygon with two outer rings with the first having a single inner ring/hole:
Notice how the EXTRACT function reverses the ordinates for the first polygon’s inner ring. An inner ring (2003) in a polygon always has clockwise orientation while an outer boundary (1003) always has anti-clockwise orientation.
Thus, EXTRACT’s reversing of the inner ring (2003) is quite correct as an extracted single polygon must have an outer ring (1003) which must have clockwise orientation.
However, If You Are Using Extract To Implement Some Sort Of Geoprocessing For A Polygon That Requires You To Extract The Individual Elements/Rings, Process Them, And Then Put The Geometry Back Together, You Must Take Into Account This Reversing Of Inner Rings,
when putting the polygon geometry back together. This can be done using the SDO_UTIL.REVERSE_LINESTRING function.
Note, you cannot use the reverse_linestring function on a polygon: