<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
Yes, it appears the bug is that that assumption is not being fulfilled. A bug ticket is already submitted.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
Thanks for your response,<br>
</div>
<div class="elementToProof" style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Alexandre<br>
</div>
<div class="elementToProof">
<div id="Signature">
<div>
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Calibri, Arial, Helvetica, sans-serif;">
<table style="color: rgb(33, 33, 33); font-size: 15px; width: 430px;" width="430">
<tbody>
<tr>
<td><br>
</td>
<td><br>
</td>
<td><br>
</td>
<td><br>
</td>
</tr>
</tbody>
</table>
<br>
<p></p>
</div>
</div>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>De:</b> postgis-users <postgis-users-bounces@lists.osgeo.org> em nome de Regina Obe <lr@pcorp.us><br>
<b>Enviado:</b> 29 de agosto de 2022 22:29<br>
<b>Para:</b> 'PostGIS Users Discussion' <postgis-users@lists.osgeo.org><br>
<b>Assunto:</b> Re: [postgis-users] Corrupted topology when using totopogeom in 3D topology</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif}
a:link, span.x_MsoHyperlink
        {color:blue;
        text-decoration:underline}
a:visited, span.x_MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline}
p
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif}
span.x_EmailStyle18
        {font-family:"Calibri",sans-serif;
        color:#1F497D}
.x_MsoChpDefault
        {font-size:10.0pt}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
        {}
-->
</style>
<div lang="EN-US" link="blue" vlink="purple">
<div class="x_WordSection1">
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">I think the issue is that postgis topology only works with 2D and simply just carries the Z.  So all its assumptions about closedness and intersection are
 based on the 2D plane.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">Thanks,</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D">Regina</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri",sans-serif; color:#1F497D"> </span></p>
<div style="border:none; border-left:solid blue 1.5pt; padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal"><b><span style="font-size:11.0pt; font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt; font-family:"Calibri",sans-serif"> postgis-users [mailto:postgis-users-bounces@lists.osgeo.org]
<b>On Behalf Of </b>Alexandre Silva<br>
<b>Sent:</b> Friday, August 26, 2022 7:14 AM<br>
<b>To:</b> postgis-users@lists.osgeo.org<br>
<b>Subject:</b> [postgis-users] Corrupted topology when using totopogeom in 3D topology</span></p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">Hello,</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">I'm having some trouble creating a 3D topology using totopogeom method, I don't know if I'm not using the functions correctly or if there's indeed a
 bug, so any help would be appreciated.</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">I reduced the problem to an example with two lines.</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">The first line is added with no errors to the topology but the second one throws this error "Corrupted topology: ring of edge -3 is geometrically not-closed".</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">The second line intersects with the first one, but there's no vertex on the intersection.</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">I found two workarounds but both of them have some disadvantages in my point of view.</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">The first one was to add manually a vertex on the intersection (this involves someone doing that work manually).</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">The other one was to add the start and end point of every line using topogeo_addpoint before calling totopogeom (this involves remembering to do this
 every time that I create a topology and I think it's redundant and overhead for most cases).</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black"><a href="https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fimgur.com%2Fa%2FFgIVyMO&data=05%7C01%7Camsilva%40infoportugal.impresa.pt%7C1526482a021843c6b13c08da8a058db7%7Cd227b2e71c404f63b5132f3665c334e6%7C0%7C0%7C637974053710375944%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=D09MApc56bQEbE2wWq0NW2q9BppcOMmfVdrdo%2B1%2FrtU%3D&reserved=0" originalsrc="https://imgur.com/a/FgIVyMO" shash="spZLgtpEpNaT65aaAHFxsI+IhRyAs5pM6zRjwZXuapnFtEWDMdPrmY0WFQZo8sztrK9YAHme8rDHc10FlNcWnCgXG6H/JadcpPb/r4J7iNfFR+J2ScHEZe9uxyTKIsRBo0/BUNr0wdb3kywhpiMlKHdQALLS+/Cef2uUnsXXKuU=" id="LPNoLPOWALinkPreview">https://imgur.com/a/FgIVyMO</a>
 - here is the visual of the data for the error and non-error approach </span></p>
</div>
<div>
<p class="x_MsoNormal"><a href="https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpastebin.com%2FCR5dNYSZ&data=05%7C01%7Camsilva%40infoportugal.impresa.pt%7C1526482a021843c6b13c08da8a058db7%7Cd227b2e71c404f63b5132f3665c334e6%7C0%7C0%7C637974053710375944%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=zknaJJU%2FbS88WmkQE1g3X6EhbEb7d10tDxhkjnJR%2Fjs%3D&reserved=0" originalsrc="https://pastebin.com/CR5dNYSZ" shash="gDp6LsZZzdRP9vOxCSTHR366Fe0P3IOfGmBDdpgthYMq9eJZ0STKjgMMeRya+1ZovU0Qh3VBnfu73zRDkB/WNYiDdpkDV3HxEnOk19TIFm9TNvqOjQ6ix1CcqzhQPG8wHk9zJnzPCGiBtKZFGIxKlQTtlq+d0JkKqDUb85SH77A=" id="LPNoLPOWALinkPreview_2">https://pastebin.com/CR5dNYSZ</a>
 - here is a script to emulate the error, with the two workarounds commented</p>
</div>
<p class="x_MsoNormal"> </p>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">Not having much knowledge of the c code base, just looking at the code surrounding the error (<a href="https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.postgis.net%2Fdocs%2Fdoxygen%2F3.0%2Fd6%2Fd03%2Flwgeom__topo_8c_source.html&data=05%7C01%7Camsilva%40infoportugal.impresa.pt%7C1526482a021843c6b13c08da8a058db7%7Cd227b2e71c404f63b5132f3665c334e6%7C0%7C0%7C637974053710375944%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=eJbKR60%2FI2cu%2FL3yR8zlsBp4UvGSYXe%2F2%2B6MzxFLfaE%3D&reserved=0" originalsrc="https://www.postgis.net/docs/doxygen/3.0/d6/d03/lwgeom__topo_8c_source.html" shash="XfEFBw/09wvDBJ/kCxRGdCnwQybo0tsuRXocE4vWbEqNaR8INeMMExrgoZmDGsnhBemZp3u4uZXTSv5tBfiGYKvxdc72fa1zEycDLqM1WpsmHgpU9BEqNqOJqxiN5sN4R9/IR9P1foklvUtTBvpRey0b0RyfJ26yqLDtej7Jk7U=" id="LPlnk119426">https://www.postgis.net/docs/doxygen/3.0/d6/d03/lwgeom__topo_8c_source.html</a>),
 my wild guess is that when it creates the ring of the newly closed area, and as there is no vertex on the intersection so no snap made, the ring is closed on 2D dimension but there is a 3D gap that makes the ring not geometrically closed. My reasoning for
 this is that the same data with a 2D topology has no errors and if I reverse the insertion order (there would be a node on the intersection), it also works. I can also be completely wrong.</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">This error was tested on docker image postgis/postgis:14-3.2-alpine with postgis version:</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">POSTGIS="3.2.1 0" [EXTENSION] PGSQL="140" GEOS="3.10.2-CAPI-1.16.0" PROJ="8.2.0" LIBXML="2.9.13" LIBJSON="0.15" LIBPROTOBUF="1.4.0" WAGYU="0.5.0 (Internal)"
 TOPOLOGY</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">There's no error in this version (also running in docker):</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">POSTGIS="3.0.1 ec2a9aa" [EXTENSION] PGSQL="120" GEOS="3.7.1-CAPI-1.11.1 27a5e771" SFCGAL="1.3.6" PROJ="Rel. 5.2.0, September 15th, 2018" GDAL="GDAL 2.4.0,
 released 2018/12/14" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.3.1" WAGYU="0.4.3 (Internal)" TOPOLOGY RASTER</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">Thanks,</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="font-family:"Calibri",sans-serif; color:black">Alexandre Silva</span></p>
</div>
<div>
<p class="x_MsoNormal" style="background:white"><span style="color:black">​​</span><span style="font-family:"Calibri",sans-serif; color:black; background:white">​</span><span style="color:black"></span></p>
</div>
<p class="x_MsoNormal"><img border="0" id="x__x0000_i1025" src="http://newsletter.impresapublishing.pt/i/barra_ip.jpg"></p>
</div>
</div>
</div>
</body>
</html>