SDO_GEOMETRY polygon: Vertices are clockwise in ArcMap, but counterclockwise in SQL

06-08-2022 08:06 PM
Labels (1)
Frequent Contributor II

I've created a polygon in an Oracle 18c SDO_GEOMETRY FC via ArcMap.

In ArcMap, the vertices are displayed in the direction that I drew them: clockwise.


However, if I query the data via SQL, then the vertices are listed in counterclockwise order:

sdo_polygons p
cross join
sdo_util.getvertices(p.shape) t --

-- -- --
1 10 10
2 20 10
3 20 20
4 10 20
5 10 10


Why is there a difference in the vertex order — between ArcMap and SQL?
Are two different sets of vertices stored within a single feature?


I happen to be aware of an Oracle error message that suggests that SDO_GOMETRY polygons need to be counterclockwise:

ORA-13367: wrong orientation for interior/exterior rings

Cause: In an Oracle Spatial geometry, the exterior and/or interior rings are not oriented correctly.

Action: Be sure that the exterior rings are oriented counterclockwise and the interior rings are oriented clockwise.

Oracle Spatial Community: Why do polygon vertices need to be counterclockwise?

GIS SE: Order of polygon vertices in general GIS: clockwise or counterclockwise

0 Kudos
2 Replies
MVP Regular Contributor

From the Glossary:

[...] Each ring in a polygon contains an array of point coordinates, where the first and last point are the same. [...] To create a topologically correct polygon, exterior rings are oriented clockwise, and interior rings (holes) are oriented counter-clockwise. [...]

And from the arcpy doc on Polygons:

During the creation of a geometry object, a simplification process is performed to make the geometry topologically consistent according to its geometry type. For instance, it rectifies polygons that may be self-intersecting, or contain incorrect ring orientations.

That suggests that

  • the vertex order in ArcGIS and Oracle is different
  • ArcGIS reverses the vertex order if you draw a counter-clockwise polygon (it does)
  • the edit vertices tool hides the last vertex (it can be seen using Python or Arcade)

Have a great day!
Esri Esteemed Contributor

Shapefile uses right-hand rule*, but geodatabase uses left-hand rule*. Some storage formats have a required order (e.g., SDO, KML), but others (GML) are flexible. Since the sketch code originated in ArcView, and it was based on shapefile, it's likely that sketch would use right-hand rule, as does ArcObjects in general (and therefore ArcPy).

The SgShape library used by all Esri tools allows for extraction in either order, but at geometry assembly it will flip rings, demote interior rings, and promote exterior rings (as necessary) so that the geometry is internally consistent with left-hand rule. The only time vertices are stored twice is if a CAD entity is present.

- V


* The "right-hand rule" where, when walking the perimeter, the right hand is toward the inside (aka, clockwise on exterior rings and counter-clockwise on  interior), not the "right-hand rule" where, when the right thumb is pointed up from the face of the ring, the curl of fingers indicates the vertex order direction (that's called "left-hand rule").