[gdal-dev] How to compare closed curves with different start points?
George Mathijssen
george.mathijssen at gmail.com
Sat Aug 23 07:29:54 PDT 2025
Hi,
In an application that I am currently developing there is a need to compare
geometries and I hit an obstacle when comparing OGRCurvePolygons.
>From a SQL/MM perspective I (mostly) need ST_OrderingEquals, meaning that
the coordinates must be in the same order. This is implemented by
OGRCurvePolygon as is stated in the documentation.
The obstacle however is that there are 3 freedoms when comparing polygons:
* the direction of a ring may differ
* the start point of a ring may differ
* the order of inner rings may differ
For example the following 2 curve polygons should be considered equal in
the application (apologies for the formatting):
CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (85369.63 433446.48, 85368.99
433448.54, 85366.08 433449.62), (85366.08 433449.62, 85320.0 433442.34),
CIRCULARSTRING (85320.0 433442.34, 85318.48 433441.52, 85317.85 433439.94),
(85317.85 433439.94, 85323.26 433407.01), CIRCULARSTRING (85323.26
433407.01, 85324.24 433405.814, 85325.76 433405.24), (85325.76 433405.24,
85371.68 433412.51), CIRCULARSTRING (85371.68 433412.51, 85373.66
433413.74, 85374.28 433415.25), (85374.28 433415.25, 85369.63 433446.48)),
CIRCULARSTRING (85361.39 433438.49, 85365.44 433434.44, 85361.39 433430.39,
85357.34 433434.44, 85361.39 433438.49), CIRCULARSTRING (85327.69 433426.1,
85330.18 433423.61, 85327.69 433421.12, 85325.2 433423.61, 85327.69
433426.1))
CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (85320.0 433442.34, 85318.48
433441.52, 85317.85 433439.94), (85317.85 433439.94, 85323.26 433407.01),
CIRCULARSTRING (85323.26 433407.01, 85324.24 433405.814, 85325.76
433405.24), (85325.76 433405.24, 85371.68 433412.51), CIRCULARSTRING
(85371.68 433412.51, 85373.66 433413.74, 85374.28 433415.25), (85374.28
433415.25, 85369.63 433446.48), CIRCULARSTRING (85369.63 433446.48,
85368.99 433448.54, 85366.08 433449.62), (85366.08 433449.62, 85320.0
433442.34)), CIRCULARSTRING (85357.34 433434.44, 85361.39 433438.49,
85365.44 433434.44, 85361.39 433430.39, 85357.34 433434.44), CIRCULARSTRING
(85327.69 433426.1, 85330.18 433423.61, 85327.69 433421.12, 85325.2
433423.61, 85327.69 433426.1))
The differing directions of rings I can solve with
OGRCompoundCurve::isClockwise and OGRCompoundCurve::reversePoints to ensure
consistent ring directions before comparing.
The differing order of inner rings is solvable by finding matching rings.
This is O(N^2), but N is small enough in practice to be acceptable.
This leaves me with the problem of comparing rings that have different
start points. My first thought was to ask how to change the start point of
a closed curve (ring), since I cannot find anything about this in the
documentation. However that is not a solution, since you cannot change the
start point to any other point on the ring. For example changing the start
point to be the mid-point of an arc (circular string) would make the
geometry invalid.
I could iterate the points of the closed curve/ring, but I would also have
to know how each point is connected to the previous/next point (linear,
curve). I do not know if this information is available, searching the
documentation gave me no result.
So the question is: how can I compare closed curves (rings) that have
different start points?
Thank you for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20250823/c7e9213b/attachment.htm>
More information about the gdal-dev
mailing list