Topology topology_ 7: Topology processing

7. Topology processing

7.1. Polygonize

Polygonize - finds and registers all faces defined by topological edges

7.1. 1. Summary

text Polygonize(varchar toponame);

7.1. 2. Description

By registering all the faces, you can create a topology edge primitive.

Assume that the target topology does not contain self intersecting edges.

  • Known faces can be recognized, so it is safe to call Polygonize multiple times on the same topology
  • This function does not use or set the next of the edge table_ left_ Edge and next_right_edge field.

7.2. AddNode

AddNode - adds a point node to the node table in the specified topology pattern and returns the nodeid of the new node. If the point already exists as a node, the existing nodeid is returned.

7.2. 1. Summary

integer AddNode(varchar toponame, geometry apoint, boolean allowEdgeSplitting=false, boolean computeContainingFace=false);

7.2. 2. Description

Adds a point node to the node table in the specified topology schema. The adddge function automatically adds the start point and end point of an edge when called, so there is no need to explicitly add the node of an edge.

If any edge passing through the node is found, either an exception is thrown or the edge is split, depending on the allowEdgeSplitting parameter value.

If computeContainingFace is true, the newly added node will get the correct containing face.

  • If the apoint geometry already exists as a node, the node is not added, but the existing nodeid is returned.

7.2. 3. Example

SELECT topology.AddNode('ma_topo', ST_GeomFromText('POINT(227641.6 893816.5)', 26986) ) As nodeid;
nodeid
4

7.3. AddEdge

AddEdge - adds a linestring edge to the edge table using the specified linestring geometry, adds the relevant start and end points to the point node table of the specified topology mode, and returns the edgeid of the new (or existing) edge.

7.3. 1. Summary

integer AddEdge(varchar toponame, geometry aline);

7.3. 2. Description

Adds an edge to the edge table using the specified linestring geometry, adds the associated node to the nodes table of the specified toponame mode, and returns the edge id of a new record or an existing record. The newly added edge has a "cosmic" side on both sides and is connected to itself.

  • If the aline geometry crosses, overlaps, contains or contains existing linestring edges, an error is thrown and the edges are not added.
  • The geometry of aline must have the same srid as the topology definition, otherwise an invalid spatial reference system error will be thrown.

7.3. 3. Example

SELECT topology.AddEdge('ma_topo', ST_GeomFromText('LINESTRING(227575.8 893917.2,227591.9 893900.4)', 26986) ) As edgeid;
edgeid
1
SELECT topology.AddEdge('ma_topo', ST_GeomFromText('LINESTRING(227591.9 893900.4,227622.6 893844.2,227641.6 893816.5,227704.5 893778.5)', 26986) ) As edgeid;
edgeid
2
SELECT topology.AddEdge('ma_topo', ST_GeomFromText('LINESTRING(227591.2 893900, 227591.9 893900.4,227704.5 893778.5)', 26986) ) As edgeid;

-- gives error --
ERROR: Edge intersects (not on endpoints) with existing edge 1

7.4. AddFace

AddFace - registers a face with the topology and gets its identifier

7.4. 1. Summary

integer AddFace(varchar toponame, geometry apolygon, boolean force_new=false);

7.4. 2. Description

Register the face to the topology and get its identifier.

For newly added faces, the edges that make up their boundaries and the edges contained in the faces are updated to be left_face and right_ The face field has the correct value. The orphaned nodes contained in the face will also be updated to have the correct containment_ Face field value.

  • This function does not use or set the next of the edge table_ left_ Edge and next_right_edge field

Assume that the target topology is valid (does not contain self intersecting edges). An exception is thrown if the polygon boundary is not completely defined by an existing edge or if the polygon overlaps an existing face.

If the polygon geometry already exists as a face, then: force_ If new is false (default), the face id of the existing face is returned; If force_ If new is true, a new id will be assigned to the newly registered face.

  • When a new registration of an existing face is executed (force_new=true), no action is taken to resolve the dangling reference to the existing face at the edge, the node has a relationship table, and the MBR field of the existing face record will not be updated. This is handled by the caller.
  • The polygon geometry must have the same srid as the topology definition, otherwise an invalid spatial reference system error will be thrown.

7.4. 3. Example

-- First add edges, we use generate_series As iterator(As shown below)  
-- Only applicable to polygons less than 10000 points, because our maximum gs)  

SELECT topology.AddEdge('ma_topo', ST_MakeLine(ST_PointN(geom,i), ST_PointN(geom, i + 1) )) As edgeid
    FROM (SELECT ST_NPoints(geom) AS npt, geom
        FROM
            (SELECT ST_Boundary(ST_GeomFromText('POLYGON((234896.5 899456.7,234914 899436.4,234946.6 899356.9,234872.5 899328.7,234891 899285.4,234992.5 899145, 234890.6 899069,234755.2 899255.4,234612.7 899379.4,234776.9 899563.7,234896.5 899456.7))', 26986)) As geom
        ) As geoms) As facen CROSS JOIN generate_series(1,10000) As i
        WHERE i < npt;

edgeid
3
4
5
6
7
8
9
10
11
12
SELECT topology.AddFace('ma_topo',ST_GeomFromText('POLYGON((234896.5 899456.7,234914 899436.4,234946.6 899356.9,234872.5 899328.7,234891 899285.4,234992.5 899145, 234890.6 899069,234755.2 899255.4,234612.7 899379.4,234776.9 899563.7,234896.5 899456.7))', 26986) ) As faceid;
faceid
1

7.1. ST_Simplify

ST_Simplify - returns a "simplified" geometry version of a given TopoGeometry using the Douglas Peucker algorithm.

7.1. 1. Summary

geometry ST_Simplify(TopoGeometry geomA, float tolerance);

7.1. 2. Description

Use the Douglas Peucker algorithm on each component edge to return a "simplified" geometric version of a given TopoGeometry.

  • The returned geometry may not be simple or invalid.
  • Splitting component edges helps maintain simplicity / effectiveness

Keywords: PostgreSQL

Added by unplugme71 on Mon, 13 Dec 2021 18:22:23 +0200