The next function, GetEdgeByPoint, is designed to find edges. Its use is identical, and also throws an exception when there is more than one edge within tolerance. When no edge is found within tolerance, 0 is returned:
SELECT topology.GetEdgeByPoint('my_topology','SRID=4326;POINT(14.99327 50.92510)',0.015);
getedgebypoint
----------------
1626
SELECT topology.GetEdgeByPoint('my_topology','SRID=4326;POINT(14.82061 50.87269)',0.02);
ERROR: Two or more edges found
Another way to find edges in a topology is retrieving them by node. This time, more than one edge ID can be returned. Let's get back to our tripoint and use the topology.GetNodeEdges function:
SELECT topology.GetNodeEdges('my_topology', 1598);
getnodeedges
--------------
(1,-3470)
(2,1626)
(3,-1601)
This function returns a set of sequences: the edge appearance order (sequence) and the edge ID (edge).
Note that some IDs are returned as a negative value. This is because of edge direction:
SELECT edge_id, start_node,end_node FROM my_topology.edge_data WHERE edge_id IN (3470,1626,1601);
edge_id | start_node | end_node
---------+------------+----------
1601 | 1574 | 1598
1626 | 1598 | 3348
3470 | 3351 | 1598
For edges returned with a negative ID, the node in question is an end node; for nodes returned with a positive ID, the node is a start node. When the edge is closed (for example, forming a polygon face) it will be returned twice, with both signs.
This is useful information, but if we want to retrieve the edges' geometry by joining, the result will have to be wrapped in the abs() function:
SELECT ed.edge_id, ed.geom FROM my_topology.edge_data ed JOIN topology.GetNodeEdges('my_topology', 1598) ge ON abs(ge.edge) = ed.edge_id;