<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Aptos;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Aptos",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="FR-BE" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN" style="font-size:11.0pt;mso-fareast-language:EN-US">  One idea, perhaps too resource-intensive, would be to transform the linear rings into polygons, and then take the difference (</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">OGRGeometry::Difference</span><span lang="EN" style="font-size:11.0pt;mso-fareast-language:EN-US">).
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN" style="font-size:11.0pt;mso-fareast-language:EN-US">  If the difference gives a null area, then is no difference in input rings.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN" style="font-size:11.0pt;mso-fareast-language:EN-US">Nicolas<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="FR" style="font-size:11.0pt;font-family:"Calibri",sans-serif">De :</span></b><span lang="FR" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> gdal-dev <gdal-dev-bounces@lists.osgeo.org>
<b>De la part de</b> George Mathijssen via gdal-dev<br>
<b>Envoyé :</b> lundi 25 août 2025 10:14<br>
<b>À :</b> Rahkonen Jukka <jukka.rahkonen@maanmittauslaitos.fi><br>
<b>Cc :</b> gdal-dev@lists.osgeo.org<br>
<b>Objet :</b> Re: [gdal-dev] How to compare closed curves with different start points?<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hi,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The geometry is indeed a plate with rounded corners and 2 circular holes, it is an actual geometry in the port of Rotterdam though I have simplified it somewhat.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The differences between the 2 geometries is that the exterior ring has different start points and the right most inner ring has different start points. The leftmost inner ring is identical between the two geometries. My intention was to
 also include different ring directions, but I forgot to do that.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Visualizing the st_difference query that you ran shows differences in the right most ring. It is not the entire ring that is different, just parts of it. I think this has to do with rounding and the fact that the curve segments are actually
 different: the start point in the second geometry is one point over, which means that the circular strings are entirely different.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Compare this to the exterior ring: I choose a different start point, but I did not actually change the curve segments. So the result is that all curve segments are identical, but in a different order. This might explain why st_difference
 detects the exterior rings as being identical. I wonder if this changes when I make the direction of the exterior rings opposite of each other.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Sat, 23 Aug 2025 at 19:56, Rahkonen Jukka <<a href="mailto:jukka.rahkonen@maanmittauslaitos.fi">jukka.rahkonen@maanmittauslaitos.fi</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal">Hi,<br>
<br>
I thought that PostGIS would return an empty geometry with ST_Difference, but it does not. I do not know what that means. Maybe PostGIS is linearizing the curve before computing the difference. Your geometry seems to be like a plate with rounded corners and
 two holes, and I guess that the ring of the rightmost hole is oriented differently.<br>
<br>
 This was my query:<br>
<br>
select st_difference(<br>
'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))<br>
','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))');<br>
<br>
-Jukka Rahkonen-<br>
<br>
<br>
<br>
<br>
________________________________________<br>
Lähettäjä: gdal-dev <<a href="mailto:gdal-dev-bounces@lists.osgeo.org" target="_blank">gdal-dev-bounces@lists.osgeo.org</a>> käyttäjän George Mathijssen via gdal-dev <<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>> puolesta<br>
Lähetetty: Lauantai 23. elokuuta 2025 17.29<br>
Vastaanottaja: <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a> <<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>><br>
Aihe: [gdal-dev] How to compare closed curves with different start points?<br>
<br>
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 differFor
 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.<o:p></o:p></p>
</div>
</body>
</html>