<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<p style="margin-bottom:0in"><font size="2">Hi</font></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2">The problem using planer projection on big areas was that it was causing drifting points. From what I have tested before I did not find any projection that was handling this correctly. </font><span style="font-size: small;">If
 we for instance select https://epsg.io/25832 as the planer projection in the database and work coordinates from north east in Norway, we are to far east for this projection. So we here need to use https://epsg.io/25835 . </span></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2">So the question was how to transform from UTM35 to UTM32 and back with out drifting points ?</font></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2">We start out with the point 1108142.0,7788000.0 and up with POINT(1104127.00421121 7787535.4833056) in the test case below :</font></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2">select ST_AStexT(ST_Transform(ST_Transform(ST_setSrid(ST_MakePoint(1108142.0,7788000.0),25835),25832),25835));
</font></p>
<p style="margin-bottom:0in"><font size="2">-> </font><span style="font-size: small;">POINT(1104127.00421121 7787535.4833056)</span></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2">- We also tested to by going through degrees , but the points was still drifting</font></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2">select ST_AStexT(ST_Transform(ST_Transform(ST_Transform(ST_Transform(</font><span style="font-size: small;">ST_setSrid(ST_MakePoint(1108142.0,7788000.0),25835),4258),25832),4258),25835));</span></p>
<p style="margin-bottom:0in">-> <span style="font-size: small;">POINT(1104127.00421121 7787535.4833056)</span></p>
<p style="margin-bottom:0in"><span style="font-size:small"><br>
</span></p>
<p style="margin-bottom:0in"><span style="font-size:small">The tests above I did in our prod database
</span><span style="font-size:small">postgis_full_version</span><span style="font-size:small"> :</span></p>
<p style="margin-bottom:0in"><font size="2">POSTGIS="2.2.2 r14797" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.9.2, released 2012/10/08" LIBXML="2.7.6" LIBJSON="0.11" TOPOLOGY RASTER</font></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2">So to handle the problem in some cases we had some Java code that we used, based on Cobol code we got from norwegian mapping authority but that was not usable in the database.  So we ended using degrees. </font></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2"><font face="-webkit-standard"><b><span style="font-size: 14pt;">But when I tested this on my local laptop now </span><span style="font-size: 14pt;">the behaviour is totally different, so this is actually is fixed
  and thats great.</span></b></font></font></p>
<span style="font-size: 14pt;"></span>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2">select ST_AStexT(ST_Transform(ST_Transform(ST_setSrid(ST_MakePoint(1108142.0,7788000.0),25835),25832),25835));
</font></p>
<p style="margin-bottom:0in">-> <span style="font-size:small">POINT(1108142 778800</span></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2">POSTGIS="2.5.2 r17328" [EXTENSION] PGSQL="110" GEOS="3.7.2-CAPI-1.11.2 b55d2125" SFCGAL="1.3.6" PROJ="Rel. 6.0.0, March 1st, 2019" GDAL="GDAL 2.4.1, released 2019/03/15" LIBXML="2.9.9" LIBJSON="0.13.1" LIBPROTOBUF="1.3.1"
 TOPOLOGY RASTER</font></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2">So yes, it seems like can switch to a planer projection now as suggest, we just need to upgrade our databases first,</font></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><a name="firstHeading" id="LPlnk593453" class="OWAAutoLink" previewremoved="true"></a><font size="2">By the way I am not an expert in <span lang="en">Geodesy, I just try to use tools available </span></font></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2"><span lang="en">Thanks a lot.</span></font></p>
<p style="margin-bottom:0in"><br>
</p>
<p style="margin-bottom:0in"><font size="2"><span lang="en">Lars</span></font></p>
<p style="margin-bottom:0in"><br>
</p>
<br>
<br>
<div style="color:rgb(0,0,0)">
<hr style="display:inline-block; width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> postgis-users <postgis-users-bounces@lists.osgeo.org> on behalf of Paul Ramsey <pramsey@cleverelephant.ca><br>
<b>Sent:</b> Friday, June 7, 2019 5:53 PM<br>
<b>To:</b> PostGIS Users Discussion<br>
<b>Subject:</b> Re: [postgis-users] Tolerance/SnapTo in Postgis Topology for meter and degrees.</font>
<div> </div>
</div>
<div class="" style="word-wrap:break-word; line-break:after-white-space">Surely there is an “all of Norway” planar projection you can use to handle the integrative whole-country work cases? Even if there isn’t, you can always invent one and add it to the spatial_ref_sys
 table. 
<div class=""><br class="">
</div>
<div class="">P<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Jun 7, 2019, at 3:02 AM, Lars Aksel Opsahl <<a href="mailto:Lars.Opsahl@nibio.no" class="OWAAutoLink" id="LPlnk736212" previewremoved="true">Lars.Opsahl@nibio.no</a>> wrote:</div>
<br class="x_Apple-interchange-newline">
<div class="">
<div id="x_divtagdefaultwrapper" dir="ltr" class="" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; text-decoration: none; font-size: 12pt; font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<div class="" style="margin-top:0px; margin-bottom:0in">Hi</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">We have one issue/problem and that is how to handle Tolerance/SnapTo in a good way when working in degrees.</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">We work on maps that covers all of Norway so we use degrees<span class="x_Apple-converted-space"> </span><a href="https://epsg.io/4258" class="OWAAutoLink" id="LPlnk219246" previewremoved="true">https://epsg.io/4258</a><span class="x_Apple-converted-space"> </span>.
 We also use Postgis Topology, which means that we just have add new lines both for surface and line layers and let Postgis Topology take care generating the surfaces so this samples I just focus on lines.</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">A description and some code pieces to illustrate the problem:</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><b class="">A: Layers in meter </b></div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">First we show that this works well when working in meter. I create a Postgis Topology layer with layer_precision 10 meter using<span class="x_Apple-converted-space"> </span><a href="https://epsg.io/25833" class="OWAAutoLink" id="LPlnk391136" previewremoved="true">https://epsg.io/25833</a>.
 Then we add 4 horizontal lines and 4 vertical lines using a precision with 2 meter. Postgis Topology handles this nicely and we end with total of 4 lines and not 8 lines as we added, because every second line snaps to the line added before because the distance
 between the lines are less 2 meter which use as precision we used when adding new lines.</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">The sample code :<a href="https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_meter.sql" id="LPlnk90327" class="x_OWAAutoLink" previewremoved="true">https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_meter.sql</a></div>
<br class="">
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">A image of the result :<a href="https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_meter.png" id="LPlnk302956" class="x_OWAAutoLink" previewremoved="true">https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_meter.png</a></div>
<p class="" style="margin-top:0px; margin-bottom:0px"></p>
<p class="" style="margin-top:0px; margin-bottom:0px"></p>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">The green lines are the lines we added, the red lines are the lines that are stored in the edge table.</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><b class="">Layers in degrees :</b></div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">But when we are using degrees things starts be more difficult. The reason why we are using degrees is to get a accurate transformations to local UTM zones which are different depending on where in Norway
 you are.</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">So the problem is how to use tolerances so we get a behavior equal to the test using meter.</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">We can we define the layer in Postgis Topology with quite big value because this is just max value as it seems. So we can adjust the tolerance parameter as we add lines but the problem is that we need
 to adjust this parameter depending on where we are and what orientation the line has. For vertical lines we need a bigger tolerance than for horizontal lines in Norway. This makes it quite complicated to handle adding new lines.</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">The sample code :<a href="https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_degrees.sql" id="LPlnk421152" class="x_OWAAutoLink" previewremoved="true">https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_degrees.sql</a></div>
<br class="">
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">A image of the result :<a href="https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_degrees.png" id="LPlnk419200" class="x_OWAAutoLink" previewremoved="true">https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_degrees.png</a></div>
<p class="" style="margin-top:0px; margin-bottom:0px"></p>
<p class="" style="margin-top:0px; margin-bottom:0px"></p>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">The green lines are the lines we added, the red lines are the lines that are stored in the edge table.</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">It real life it's impossible to do it this because water, farm land are not built up by horizontal and vertical lines only. Since we use Postgis Topology we could split a line in the different line parts
 and based on the angle select the best tolerance value but that is complicated and means extra computing. Another problem is that edges then will be broken up into unnecessary small pieces.</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">Any ideas on how to handle this in a better way ?</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">Can “PostGIS Geography Type” help us here ?</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
<div class="" style="margin-top:0px; margin-bottom:0in">Thanks Lars</div>
<div class="" style="margin-top:0px; margin-bottom:0in"><br class="">
</div>
</div>
<span class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; float:none; display:inline!important">_______________________________________________</span><br class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<span class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; float:none; display:inline!important">postgis-users
 mailing list</span><br class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<a href="mailto:postgis-users@lists.osgeo.org" class="OWAAutoLink" id="LPlnk790473" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px" previewremoved="true">postgis-users@lists.osgeo.org</a><br class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" class="OWAAutoLink" id="LPlnk263559" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px" previewremoved="true">https://lists.osgeo.org/mailman/listinfo/postgis-users</a></div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</div>
</body>
</html>