<div dir="ltr"><div>Hi all,</div><div><br></div><div>I am having trouble understanding the behaviour of St_Snap when used with 3D Geometries.</div><div><br></div><div>I was aware that st_snap did not properly support 3D geometries, but I would not expect that it actually changes the Z coordinates.</div><div><br></div><div>I would expect that the Z coordinates would be kept untouched, but that's not what happens.</div><div><br></div><div style="background-color:rgb(255,255,255);padding:0px 0px 0px 2px"><div style="color:rgb(35,38,41);background-color:rgb(255,255,255);font-family:"Monospace";font-size:10pt;white-space:pre"><p style="margin:0px"><span style="color:rgb(128,0,0);font-weight:bold">WITH</span> <span style="color:rgb(142,0,198);font-style:italic">input</span>    <span style="color:rgb(128,0,0);font-weight:bold">AS</span> (<span style="color:rgb(128,0,0);font-weight:bold">SELECT</span> <span style="color:rgb(0,128,0)">'POINT Z (1.001 1.001 50)'</span>::<span style="color:rgb(0,0,0)">geometry</span> <span style="color:rgb(128,0,0);font-weight:bold">AS</span> <span style="color:rgb(0,100,100);font-style:italic">geom</span>),</p><p style="margin:0px">     <span style="color:rgb(142,0,198);font-style:italic">reference</span> <span style="color:rgb(128,0,0);font-weight:bold">AS</span> (<span style="color:rgb(128,0,0);font-weight:bold">SELECT</span> <span style="color:rgb(0,128,0)">'POINT Z (1.0   1.0   999)'</span>::<span style="color:rgb(0,0,0)">geometry</span> <span style="color:rgb(128,0,0);font-weight:bold">AS</span> <span style="color:rgb(0,100,100);font-style:italic">geom</span>)</p><p style="margin:0px"><span style="color:rgb(128,0,0);font-weight:bold">SELECT</span></p><p style="margin:0px">    <span style="color:rgb(0,0,128);font-weight:bold">ST_AsEWKT</span>(<span style="color:rgb(0,0,128);font-weight:bold">ST_Snap</span>(<span style="color:rgb(142,0,198);font-style:italic">i</span>.<span style="color:rgb(0,100,100);font-style:italic">geom</span>, <span style="color:rgb(142,0,198);font-style:italic">r</span>.<span style="color:rgb(0,100,100);font-style:italic">geom</span>, <span style="color:rgb(0,0,255)">0.01</span>)) <span style="color:rgb(128,0,0);font-weight:bold">AS</span> <span style="color:rgb(0,100,100);font-style:italic">snapped</span>,</p><p style="margin:0px">    <span style="color:rgb(0,0,128);font-weight:bold">ST_Z</span>(<span style="color:rgb(0,0,128);font-weight:bold">ST_Snap</span>(<span style="color:rgb(142,0,198);font-style:italic">i</span>.<span style="color:rgb(0,100,100);font-style:italic">geom</span>, <span style="color:rgb(142,0,198);font-style:italic">r</span>.<span style="color:rgb(0,100,100);font-style:italic">geom</span>, <span style="color:rgb(0,0,255)">0.01</span>))      <span style="color:rgb(128,0,0);font-weight:bold">AS</span> <span style="color:rgb(0,100,100);font-style:italic">z_after_snap</span>,</p><p style="margin:0px">    <span style="color:rgb(0,0,128);font-weight:bold">ST_Z</span>(<span style="color:rgb(142,0,198);font-style:italic">i</span>.<span style="color:rgb(0,100,100);font-style:italic">geom</span>)                              <span style="color:rgb(128,0,0);font-weight:bold">AS</span> <span style="color:rgb(0,100,100);font-style:italic">z_original</span></p><p style="margin:0px"><span style="color:rgb(128,0,0);font-weight:bold">FROM</span> <span style="color:rgb(142,0,198);font-style:italic">input</span> <span style="color:rgb(142,0,198);font-style:italic">i</span>, <span style="color:rgb(142,0,198);font-style:italic">reference</span> <span style="color:rgb(142,0,198);font-style:italic">r</span><span style="color:rgb(255,0,0)">;</span></p></div></div><div><span style="font-family:monospace"><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)"><br></span></span></span></div><div><span style="font-family:monospace"><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)"><br></span></span></span></div><div><span style="font-family:monospace"><b><font size="4">snapped       |z_after_snap|z_original|<br>--------------+------------+----------+<br>POINT(1 1 999)|       999.0|      50.0|</font></b></span></div><div><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)"><br></span></span></div><div><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)">In fact, not only the Z coordinate gets changed as it completely ignores the tolerance.</span></span></div><div><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)"><br></span></span></div><div><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)">I then tried to use ST_Force2D around the reference geometry, but the result is kind of expected, a 2D geometry with no Z coordinate.<br><br></span></span></div><div><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)">I wonder if these are the expected behaviour of ST_snap and there is more a convenient way to snap 3D geometries in 2D while ignoring the Z component without needing to recover all vertices Zs from the original geometry.</span></span></div><div><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)"><br></span></span></div><div><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)">Thanks,</span></span></div><div><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)"><br></span></span></div><div><span><span class="gmail-token gmail-token" style="color:rgb(43,48,59)">Alexandre Neto</span></span></div></div>