[postgis-users] ST_CreateTopoGeo

Sandro Santilli strk at kbt.io
Tue Feb 25 06:38:20 PST 2020


On Tue, Feb 25, 2020 at 01:22:39PM +0000, paul.malm at lfv.se wrote:
> Hi,
> Where do you mean I can play with the tolerance?

In TopoGeo_addLinestring
https://postgis.net/docs/manual-3.1/TopoGeo_AddLineString.html

> This is what I have done before the ST_createTopoGeo
> SELECT topology.CreateTopology('topo1', 4326)";
> SELECT topology.ST_CreateTopoGeo('topo1', ST_Collect(geom)) from "countries_first";
> Btw, I'm intending to simplify later on in my SQL command list.

You could do something like this:

  DO $$
    DECLARE
      rec RECORD;
      tol FLOAT8;
    BEGIN
      tol := 0;
      FOR rec in SELECT gid, (ST_Dump(geom)).geom FROM countries_first
      LOOP
        BEGIN
          IF GeometryType(rec.geom) = 'POLYGON' THEN
            PERFORM topology.TopoGeo_AddPolygon('topo1', rec.geom, tol);
          ELSIF GeometryType(rec.geom) = 'LINESTRING' THEN
            PERFORM topology.TopoGeo_AddLinestring('topo1', rec.geom, tol);
          ELSIF GeometryType(rec.geom) = 'POINT' THEN
            PERFORM topology.TopoGeo_AddPoint('topo1', rec.geom, tol);
          END IF;
        EXCEPTION WHEN OTHERS THEN
          RAISE WARNING 'For geometry % we got exception % (%)', rec.id, SQLERRM, SQLSTATE;
        END;
      END LOOP;
    END;
  $$ LANGUAGE 'plpgsql';

You can tweak the above to do something different rather than raising
a WARNING (for example store ID of offending geoms in a table).
Then you can look at the offending geometries in isolation, possibly
tweaking the "tol" variable.

--strk;


More information about the postgis-users mailing list