[postgis-users] questions/issues when creating a topology

Lucas Ferreira Mation lucasmation at gmail.com
Thu Jan 14 03:57:48 PST 2016


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 here
<ftp://geoftp.ibge.gov.br/malhas_digitais/censo_2010/setores_censitarios/ac/ac_setores_censitarios.zip>
(this
is for a small state for "prototyping", I'll also need to replicate to the
remaining 26 states in Brasil, full data here
<ftp://geoftp.ibge.gov.br/malhas_digitais/censo_2010/setores_censitarios>).
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

The basic code is:

SELECT topology.DropTopology('t_temp_geom2');
SELECT topology.CreateTopology('t_temp_geom2',32719);
select topology.addtopogeometrycolumn('t_temp_geom2',
'public','temp_geom','tg_geom_dump_utm','POLYGON');

DO $$DECLARE r record;
BEGIN
  FOR r IN SELECT * FROM temp_geom LOOP
    BEGIN
      UPDATE temp_geom SET tg_geom_dump_UTM =
toTopoGeom(ST_Force2D(geom_dump_utm),'t_temp_geom2', 1,1)
      WHERE gid= r.gid;
    EXCEPTION
      WHEN OTHERS THEN
        RAISE WARNING 'Loading of record % failed: %', r.gid, SQLERRM;
    END;
  END LOOP;
END$$;


The idea is to add polygon by polygon to the topology/topogem so that
errors can be skipped.

I 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 here
<https://github.com/lucasmation/corrige_setor_censitario_2010/blob/master/creates_topologies.sql>
.

This testing left me with many questions (apologies in advance for a long
list):


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.

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 error-polygons?

Let's say 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?

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?

4) Is not including a tolerance parameter  in to... equivalent to a zero
tolerance?


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

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  a
 reprojection to a UTM zone (srid 32719), which is where most of the
polygons are located. The errors are not the same.
With the tolerance parameter, the 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.
Without any tolerance parameter the differences are even larger. The UTMzone
projection with no tolerance (section 2 of the code) gives 2 loading
errors. With the original SRID and no tolerance (section 4 of the code) I
get upload errors for all polygons.

7) Has there been any progress on some sort of index for topogeometries, so
spatial queries can run faster? (I found this 2013 tread
<http://osgeo-org.1560.x6.nabble.com/spatial-index-for-topology-td5085935.html>on
the topic, but nothing more recent). Of course one can always cast to
geometry (topogeom::geometry) and index that, but that is duplicating the
information somewhat.


tks in advance for any guidence on any of the questions above
regards
Lucas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20160114/56467d52/attachment.html>


More information about the postgis-users mailing list