<div dir="ltr"><span style="font-size:12.8px">I am trying to create a topology to  fix some "small area" polygons that have gaps and overlaps in between them. The data is available </span><a href="ftp://geoftp.ibge.gov.br/malhas_digitais/censo_2010/setores_censitarios/ac/ac_setores_censitarios.zip" style="font-size:12.8px" target="_blank">here</a><span style="font-size:12.8px"> (this is for a small state for "prototyping", I'll also need to replicate to the remaining 26 states in Brasil, <a href="ftp://geoftp.ibge.gov.br/malhas_digitais/censo_2010/setores_censitarios" target="_blank">full data here</a>). With help from stkr at the IRC, after upgrading to postgis 2.2.1 I managed to create the topologies, by adding polygon by polygon so errors can be skipped</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">The basic code is:</span></div><div><span style="font-size:12.8px"><br></span></div><div><div><span style="font-size:12.8px">SELECT topology.DropTopology('t_temp_geom2');</span></div><div><span style="font-size:12.8px">SELECT topology.CreateTopology('t_temp_geom2',32719);</span></div><div><span style="font-size:12.8px">select topology.addtopogeometrycolumn('t_temp_geom2', 'public','temp_geom','tg_geom_dump_utm','POLYGON');</span></div><div style="font-size:12.8px"><br></div></div><div style="font-size:12.8px"><div style="font-size:12.8px">DO $$DECLARE r record;</div><div style="font-size:12.8px">BEGIN</div><div style="font-size:12.8px">  FOR r IN SELECT * FROM temp_geom LOOP</div><div style="font-size:12.8px">    BEGIN</div><div style="font-size:12.8px">      UPDATE temp_geom SET tg_geom_dump_UTM = toTopoGeom(ST_Force2D(geom_dump_utm),'t_temp_geom2', 1,1) </div><div style="font-size:12.8px">      WHERE gid= r.gid;</div><div style="font-size:12.8px">    EXCEPTION</div><div style="font-size:12.8px">      WHEN OTHERS THEN</div><div style="font-size:12.8px">        RAISE WARNING 'Loading of record % failed: %', r.gid, SQLERRM;</div><div style="font-size:12.8px">    END;</div><div style="font-size:12.8px">  END LOOP;</div><div style="font-size:12.8px">END$$;</div><div><br></div></div><div><br></div><div><div><span style="font-size:12.8px">The idea is to add polygon by polygon to the topology/topogem so that errors can be skipped.  </span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I</span><span style="font-size:12.8px"> tested this with different SRIDS (original in degrees and reprojected), different tolerance parameters (nothing, 1m). I posted the full code for the queries and results <a href="https://github.com/lucasmation/corrige_setor_censitario_2010/blob/master/creates_topologies.sql">here</a>. </span></div><div><span style="color:rgb(34,36,38);font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:15px;line-height:19.5px;background-color:rgba(248,248,248,0.6)"><br></span></div><div><span style="font-size:12.8px">This testing left me with many questions (apologies in advance for a long list): </span><br></div><div><br></div><div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">1) What is the role of ST_Force2D() function in  toTopoGeom(ST_Force2D(geom),...) ? The code fails if I omit this function. However my data is already 2D. </span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">2) In most test I did, I got an error when uploading one or two polygons (out of a 900 polygons in Acre state). How can I add these afterward? Assume all the edges that define those error-polygons have already been added. How do I define a new face  by those edges and attribute that to the topogeom for these </span><span style="font-size:12.8px">error-polygons?</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Let's say </span><span style="font-size:12.8px">polygon A can be defined by edges 1, 2, 3 and 4, which are already in the topology when other polygons were inserted. How do I define face A and attribute that to the topogeom?</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">3) Is there a way to manually edit topologies, in QGIS for instance? I'm thinking of a workflow for repairing a map. After doing the automatic fixes in Postgis and creating a topology, someone wants to manually correct some feature. For instance, move an edge or a point, while maintaining the topological properties. Is there a QGIS plugin  for that?</span></div><div><span style="font-size:12.8px"><br></span></div><div><div><span style="font-size:12.8px">4) Is not including a tolerance parameter  in to... equivalent to a zero tolerance?</span><span style="font-size:12.8px"><br></span></div></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">5) Does topology behaves differently depending on whether the SRID is in decimal degrees or meters? Ideally, I would prefer to have the tolerance parameter in meters, as it is a more intuitive unit and have a constant amount of "snapping" across the areas. However that means choosing a specific UTM zone for reprojecting each state. However states in Brasil are quite large, spanning more then one UTM zone. Even Acre, the small state I used for testing spans two UTM zones</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">6) I tested creating topologies with the original Sirgas 2000 decimal degree spatial reference (srid 4674, a decimal degree system, quite similar to wgs84 but slightly more optimized for Brasil) and also with </span><span style="font-size:12.8px"> a  reprojection to a UTM zone (srid 32719), which is where most of the polygons are located. The errors are not the same. </span></div><div><span style="font-size:12.8px">With the tolerance parameter, the </span><span style="font-size:12.8px">UTMzone projection  and 1m tolerance (section 1 of code mentioned above) I get errors in only 1 polygon. With the original SRID and 0.0001 degrees tolerance (section 3 of the code) I get  errors in 2 polygons. </span></div><div><span style="font-size:12.8px">Without any tolerance parameter the differences are even larger. The </span><span style="font-size:12.8px">UTMzone projection with no tolerance (section 2 of the code)</span><span style="font-size:12.8px"> gives 2 loading errors. </span><span style="font-size:12.8px">With the original SRID</span><span style="font-size:12.8px"> and no tolerance (section 4 of the code) I get upload errors for all polygons. </span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">7) Has there been any progress on some sort of index for </span>topogeometries<span style="font-size:12.8px">, so spatial queries can run faster? (I found </span><a href="http://osgeo-org.1560.x6.nabble.com/spatial-index-for-topology-td5085935.html" target="_blank" style="font-size:12.8px">this 2013 tread </a><span style="font-size:12.8px">on the topic, but nothing more recent). </span>Of course<span style="font-size:12.8px"> one can always cast to geometry </span>(topogeom::geometry)<span style="font-size:12.8px"> and index that, but that is duplicating the information somewhat. </span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"><br></span></div><div>tks in advance for any guidence on any of the questions above</div><div>regards</div><div>Lucas<br></div></div></div></div>