<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p style="margin-bottom: 0in">Hi</p>
<p style="margin-bottom: 0in"><br>
</p>
<p style="margin-bottom: 0in">One generic problem with adjusting input coordinates is that this mayl not solve the problem with overlapping or invalid polygons, because points in the center of a cell may go to any 4 grid points.
</p>
<p style="margin-bottom: 0in"><br>
</p>
<p style="margin-bottom: 0in">For example if you have two simple feature polygons that are suppose to have no gaps or overlap between them where they touch each other. Since this is simple feature the common part is not one object. If the common line is in
the middle of grid cell then you may get overlaps or gaps. </p>
<p style="margin-bottom: 0in"><br>
</p>
<p style="margin-bottom: 0in">You can say that the probability for this is very low and you may also say that there is bug in the input data when the common borders part don't have the same coordinates, but to compute this common part is not straight forward.</p>
<p style="margin-bottom: 0in"><br>
</p>
<p style="margin-bottom: 0in">Another problem is also that a polygon that was valid on the client may not be invalid when saved on the server, because the points are moving.
</p>
<p style="margin-bottom: 0in"><br>
</p>
<p style="margin-bottom: 0in">We have used some snapTo in Java (JTS) but only when got a Topology Exceptions from the JTS in Java doing it like below. The polygonSnapRounder was code I got from Martian Davis some years a go. But one problem with this coding
is that it makes the code more complicated and you may also cover up for bugs that are real or introduce new bugs.
</p>
<p style="margin-bottom: 0in"><br>
</p>
<p align="LEFT" style="margin-bottom: 0in"><font face="Monaco, monospace"><font size="2" style="font-size: 11pt"><font color="#7f0055"><b>try</b></font><font color="#000000"> {</font></font></font></p>
<p align="LEFT" style="margin-bottom: 0in"><font face="Monaco, monospace"><font size="2" style="font-size: 11pt"><font color="#000000"></font><font color="#6a3e3e">result</font><font color="#000000"> =
</font><font color="#6a3e3e">bigPolygon</font><font color="#000000">.intersects(</font><font color="#6a3e3e">areaToRemove</font><font color="#000000">);</font></font></font></p>
<p align="LEFT" style="margin-bottom: 0in"><font face="Monaco, monospace"><font size="2" style="font-size: 11pt"><font color="#000000">}
</font><font color="#7f0055"><b>catch</b></font><font color="#000000"> (com.vividsolutions.jts.geom.TopologyException
</font><font color="#6a3e3e">e2</font><font color="#000000">) {</font></font></font></p>
<p align="LEFT" style="margin-bottom: 0in"><font face="Monaco, monospace"><font size="2" style="font-size: 11pt"><font color="#000000"></font><font color="#6a3e3e">bigPolygon</font><font color="#000000"> =
</font><font color="#000000"><i>snapRoundIntersecton</i></font><font color="#000000">(</font><font color="#6a3e3e">bigPolygon</font><font color="#000000">,</font><font color="#6a3e3e">areaToRemove</font><font color="#000000">,
</font><font color="#6a3e3e">snapPM</font><font color="#000000">);</font></font></font></p>
<p align="LEFT" style="margin-bottom: 0in"><font color="#000000"><font face="Monaco, monospace"><font size="2" style="font-size: 11pt">}</font></font></font></p>
<p style="margin-bottom: 0in"><br>
</p>
<p align="LEFT" style="margin-bottom: 0in"><font face="Monaco, monospace"><font size="2" style="font-size: 11pt"><font color="#7f0055"><b>public</b></font><font color="#000000">
</font><font color="#7f0055"><b>static</b></font><font color="#000000"> Geometry snapRoundIntersecton(Geometry
</font><font color="#6a3e3e">a</font><font color="#000000">, Geometry </font><font color="#6a3e3e">b</font><font color="#000000">, PrecisionModel
</font><font color="#6a3e3e">snapPM</font><font color="#000000">) {</font></font></font></p>
<p align="LEFT" style="margin-bottom: 0in"><br>
</p>
<p align="LEFT" style="margin-bottom: 0in"><font face="Monaco, monospace"><font size="2" style="font-size: 11pt"><font color="#000000">Geometry
</font><font color="#6a3e3e">aFix</font><font color="#000000"> = PolygonSnapRounder.</font><font color="#000000"><i>snapRound</i></font><font color="#000000">(</font><font color="#6a3e3e">a</font><font color="#000000">,
</font><font color="#6a3e3e">snapPM</font><font color="#000000">);</font></font></font></p>
<p align="LEFT" style="margin-bottom: 0in"><br>
</p>
<p align="LEFT" style="margin-bottom: 0in"><font face="Monaco, monospace"><font size="2" style="font-size: 11pt"><font color="#000000">Geometry
</font><font color="#6a3e3e">bFix</font><font color="#000000"> = PolygonSnapRounder.</font><font color="#000000"><i>snapRound</i></font><font color="#000000">(</font><font color="#6a3e3e">b</font><font color="#000000">,
</font><font color="#6a3e3e">snapPM</font><font color="#000000">);</font></font></font></p>
<p align="LEFT" style="margin-bottom: 0in"><br>
</p>
<p align="LEFT" style="margin-bottom: 0in"><font face="Monaco, monospace"><font size="2" style="font-size: 11pt"><font color="#000000"><b></b></font><font color="#7f0055"><b>return</b></font><font color="#000000">
</font><font color="#6a3e3e">aFix</font><font color="#000000">.intersection(</font><font color="#6a3e3e">bFix</font><font color="#000000">);</font></font></font></p>
<p align="LEFT" style="margin-bottom: 0in"><br>
</p>
<p align="LEFT" style="margin-bottom: 0in"><font color="#000000"><font face="Monaco, monospace"><font size="2" style="font-size: 11pt">}</font></font></font></p>
<p style="margin-bottom: 0in"><br>
</p>
<p style="margin-bottom: 0in">So my point is that changing input data or to handle Topology exceptions is not an easy task and it's no guarantee for avoiding all problems as far as I can understand. This is one of the reasons that I started to look into Postgis
the Topology work by Sandro Santilli.</p>
<p style="margin-bottom: 0in"></p>
<p style="margin-bottom: 0in"><br>
</p>
<p></p>
<p style="margin-bottom: 0in">Lars </p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>Fra:</b> postgis-users <postgis-users-bounces@lists.osgeo.org> på vegne av Willy-Bas Loos <willybas@gmail.com><br>
<b>Sendt:</b> 14. september 2016 12:52<br>
<b>Til:</b> PostGIS Users Discussion<br>
<b>Emne:</b> Re: [postgis-users] fuzzy tolerance</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div class="gmail_quote">On Wed, Sep 14, 2016 at 11:27 AM, Stefan Keller <span dir="ltr">
<<a target="_blank" href="mailto:sfkeller@gmail.com">sfkeller@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
There is at least SnapToGrid:<br>
# select ST_SnapToGrid((ST_DumpPoints(<wbr>mypoly.geom)).geom, 0.1) from mypoly;<br>
<br>
:Stefan<br clear="all">
</blockquote>
</div>
<br>
Hm, i considered that before, but now i can't say why i discarded the thought.<br>
</div>
One thing is that the unit for snaptogrid is degrees for WGS84, so for world data that would pose a problem: you're not using a uniform grid to snap to.<br>
</div>
But in other coordinate systems, and if the algorithm is fast enough, one could use this in a trigger and always store geometries snapped to a 10cm grid. That would be precise enough for our data.<br>
</div>
It is easy to understand what is happening too, so that is an advantage.<br>
</div>
<div>BTW i tested and saw that it's not necessary to dump the points, you can snap the whole polygon.<br>
</div>
<br>
Any words of warning about using a trigger and storing the data on a 10 cm grid like i suggest?<br>
<br>
</div>
Cheers,<br>
<br>
<br>
<div class="gmail_extra">-- <br>
<div class="gmail_signature">
<div dir="ltr">Willy-Bas Loos<br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>