# [postgis-users] Tolerance/SnapTo in Postgis Topology for meter and degrees.

Lars Aksel Opsahl Lars.Opsahl at nibio.no
Fri Jun 7 03:02:23 PDT 2019

```Hi

We have one issue/problem and that is how to handle Tolerance/SnapTo in a good way when working in degrees.

We work on maps that covers all of Norway so we use degrees https://epsg.io/4258 . 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.

A description and some code pieces to illustrate the problem:

A: Layers in meter

First we show that this works well when working in meter. I create a Postgis Topology layer with layer_precision 10 meter using https://epsg.io/25833. 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.

The sample code :https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_meter.sql

A image of the result :https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_meter.png

The green lines are the lines we added, the red lines are the lines that are stored in the edge table.

Layers in degrees :

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.

So the problem is how to use tolerances so we get a behavior equal to the test using meter.

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.

The sample code :https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_degrees.sql

A image of the result :https://github.com/NibioOpenSource/pgtopo_update_sql/blob/develop/src/test/sql/snapto/snapto_code_example_degrees.png

The green lines are the lines we added, the red lines are the lines that are stored in the edge table.

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.

Any ideas on how to handle this in a better way ?

Can “PostGIS Geography Type” help us here ?

Thanks Lars

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20190607/a56b5afd/attachment.html>
```