<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Folks,</p>
    <p>I have a topology built from two business tables containing
      linestrings (pipes) and a table containing points (pits).<br>
    </p>
    <p>The business requirement means we need the topology to clean and
      form common topological primitives for these lines and their
      nodes.<br>
    </p>
    <p>The topology will never contain polygons (faces) - should I use
      pgRouting instead?<br>
    </p>
    <p>While fairly static, both tables are subject to occasional DML. <br>
    </p>
    <p><b>Insert Trigger:</b></p>
    <p>A before insert trigger (trigger function - tf) handles any
      additions (uses toTopoGeom).<br>
      <br>
      <font face="monospace">DECLARE </font><font face="monospace"><font
          face="monospace">-- pseudo code<br>
            </font>v_layer_id integer := 1;<br>
          v_geom     geometry;<br>
          v_topogeom topology.TopoGeometry;<br>
        BEGIN<br>
          IF ( TG_OP = 'INSERT') THEN<br>
            -- Create topology primitives for new linestring<br>
        <b>    v_topogeom := topology.toTopoGeom(NEW.path_line,'path',
          v_layer_id, 0.1);</b><br>
            -- The action of adding the linestring to the topology may
        see it become slightly different from the original NEW.path_line<br>
        <b>    v_geom := v_topogeom::geometry;</b><b><br>
        </b><b>
        </b>    -- Then conduct the insert to the business table<br>
            INSERT <table> (geom,topogeom) VALUES
        (v_geom,v_topoGeom);<br>
            RETURN NEW;<br>
          END IF;<br>
        END;</font><br>
    </p>
    <p>QUESTION: If the new linestring that is added to the existing
      topology causes an existing underlying edge to change (eg split),<br>
      what happens to any other topogeom objects in the table that
      reference the edge before it is changed? <br>
      Should the affected topogeoms be found and updated to reflect any
      splits to edges?<br>
    </p>
    <p>I am not sure what are the best topology methods to handle
      updates and/or deletes.<br>
    </p>
    <p><b>Update Trigger.</b></p>
    <p>Here I want to construct an UPDATE trigger (tf) to handle
      situations where points are moved or linestrings are reshaped.</p>
    <p>In both situations the existing topogeoms point to existing
      topological primitives. To handle a change should I first delete
      the existing topogeom using clearTopoGeom() which modifies the
      underlying topology, and then use toTopoGeom to construct the new
      topological primitives and the topogeom value?<br>
      <br>
      <font face="monospace">BEGIN -- pseudo code<br>
          IF ( TG_OP = 'UPDATE' ) THEN<br>
            -- clear any topology primitives the old topogeom uniquely
        referenced<br>
            v_topogeom := topology.clearTopoGeom(OLD.topogeom);<br>
            -- Construct new topology primitives for new linestring.<br>
            v_topogeom := topology.toTopoGeom(NEW.path_line,'path',
        v_layer_id, 0.1);<br>
      </font><font face="monospace"><font face="monospace"><b>    v_geom
            := v_topogeom::geometry;</b><b><br>
          </b><b> </b></font>    -- Then update the underlying topology<br>
            UPDATE <</font><font face="monospace"><font
          face="monospace">table</font>> SET topogeom = v_topogeom,
        geom = v_geom WHERE id = OLD.id;<br>
            RETURN NEW;<br>
          END IF;<br>
        END;</font><br>
    </p>
    <p><b>Delete Trigger</b></p>
    <p>Here I want to construct an DELETE trigger (tf). Is this all I
      need to do?</p>
    <p><font face="monospace">BEGIN -- pseudo code<br>
          IF ( TG_OP = 'DELETE' ) THEN<br>
            -- Synchronize delete with underlying topology<br>
            v_topogeom := topology.clearTopoGeom(NEW.topogeom);<br>
            -- Then delete the record<br>
            DELETE FROM <table> </font><font face="monospace"><font
          face="monospace">WHERE id = OLD.id;</font> <br>
            RETURN OLD;<br>
          END IF;<br>
        END;</font><br>
    </p>
    <p>Any help/pointers greatly appreciated.</p>
    <p>Simon<br>
    </p>
    <p>  </p>
    <br>
  </body>
</html>