<div dir="ltr">Hi,<div>Indeed, Postgis Topology works well to build topo from clean geometries, but can fail if input geometries have topological errors.</div><div><br></div><div>It could be tricky to clean data with just postGIS and sql queries.</div><div>Topological GIS, like GRASS, can load PostGIS data and clean them at a given precision</div><div><br></div><div>HTH</div><div>Nicolas</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 4 July 2018 at 14:01, Cameron Green <span dir="ltr"><<a href="mailto:u15055452@tuks.co.za" target="_blank">u15055452@tuks.co.za</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-ZA"><div class="m_-4944194929012682579WordSection1"><p class="MsoNormal">Good day,<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="color:#222222">My name is Cameron Green and I am an honours (4<sup>th</sup> year) student at the University of Pretoria in South Africa. I am currently working on a project that requires me to assess the quality of data that was downloaded from OpenStreetMap (OSM), specifically, various topological errors. I have decided to use PostGIS as it does error checks and tells me what the error is and where (or at least that is how I understand it). <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#222222">Firstly, here is my installation information (Ubuntu 16.04) with PostgreSQL 10:<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222">POSTGIS="2.4.4 r16526" PGSQL="100" GEOS="3.5.0-CAPI-1.9.0 r4084" SFCGAL="1.2.2" PROJ="Rel. 4.9.2, 08 September 2015" GDAL="GDAL 1.11.3, released 2015/09/16" LIBXML="2.9.3" LIBJSON="0.11.99" LIBPROTOBUF="1.2.1" TOPOLOGY RASTER<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"> <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222">Using the textbook, Mastering PostGIS chapter 8, where it deals with PostGIS Topology. Below is the SQL commands I used. When I used SRID as 4026 and 0,00028 as the snap threshold, the commands execute without any issues. However, when I change the SRID to 2049 and decrease the snap tolerance in the topology.toTopoGeom, I get the following error: <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Arial",sans-serif;color:#222222"> <u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Times New Roman",serif;color:#333333;background:white">ERROR: SQL/MM Spatial exception - geometry crosses edge 4469 CONTEXT: PL/pgSQL function totopogeom(geometry,<wbr>topogeometry,double precision) line 114 at FOR over SELECT rows PL/pgSQL function totopogeom(geometry,character varying,integer,double precision) line 89 at assignment SQL state: XX000</span><span style="font-family:"Arial",sans-serif;color:#222222"><u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Arial",sans-serif;color:#222222"> <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222">The line and type of error changes as I increase the snap tolerance to any value between 5m and 100m.<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#222222">From my understanding, once the topology is created and the geometries are loaded into the topology, I should be able to run the topology.ValidateTopology function to get a list of errors. Is this correct? <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#222222">At the moment it seems like the topology errors is what preventing me from creating the topology. <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"> <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222">If anyone could please help me or direct me to where I have made an error in my SQL commands or there are some settings I must change. Any help regarding this would be greatly appreciated.  I have added the commands at the end of this email. <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"> <u></u><u></u></span></p><p class="MsoNormal">Kind regards,<u></u><u></u></p><p class="MsoNormal">Cameron Green<br>President - CGIS YouthMappers<br>BSc(Hons) Geoinformatics, University of Pretoria<br>+2783 301 3201<u></u><u></u></p><p class="MsoNormal">+2712 420 2016<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><span style="color:#222222">SQL Commands:  <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222">topology.CreateTopology ('my_topology', 2049, 5, false) <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Arial",sans-serif;color:#222222">// Checked the validity of the input geometries <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222">select ST_IsValidReason(way) <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222">from osm_lines<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222">where ST_IsValid(way) = false<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Arial",sans-serif;color:#222222">// Create the TopoGeometry column <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222">select topology.<wbr>AddTopoGeometryColumn('my_<wbr>topology', 'public', osm_lines, 'topogeom', 'Linestring')<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Arial",sans-serif;color:#222222">//  Populate the Topogeometry column from an existing geometry. <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:9.5pt;font-family:"Arial",sans-serif;color:#222222">// This is where my problem starts<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222">update osm_lines SET topogeom = topology.toTopoGeom(way,'my_<wbr>topology',1,5) <u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#222222">select topology.TopologySummary('my_<wbr>topology')<u></u><u></u></span></p><p class="MsoNormal"><span style="color:#222222"><u></u> <u></u></span></p><p class="MsoNormal"><span style="color:#222222">select * from  topology.ValidateTopology('my_<wbr>topology')<u></u><u></u></span></p><p class="MsoNormal"><u></u> <u></u></p></div></div>
<br>
<font face="Arial" size="3">This message and attachments are subject to a disclaimer. Please refer to 
</font><font size="3"><a href="http://www.it.up.ac.za/documentation/governance/disclaimer/" target="_blank"><font face="Arial">http://www.it.up.ac.za/documen<wbr>tation/governance/disclaimer/</font></a></font><font face="Arial" size="3"> for full details.</font><br>______________________________<wbr>_________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/postgis-users</a><br></blockquote></div><br></div>