# [postgis-users] Use of tolerances in topology

Jose Carlos Martinez jomarlla at cgf.upv.es
Tue Apr 17 08:35:42 PDT 2012

```Hi Sandro, Im learning from topology.sql how the topology functions are
working with more detail.

I have a question about how the tolerances are managed, for example:

I see (ST_AddIsoEdge) that you have used some times spatial predicates
as st_contains or st_intersects. As you know these predicates (and
others too) just work in a good way if the geometries are snapped to
each other previously,  so my question is why you didnt use st_Dwithin
with a tolerance? or maybe these functions expect the geometries to be
already snapped by totopogeom for example and they shouldnt be used
directly?

regards,
Jose

CREATE OR REPLACE FUNCTION topology.ST_AddIsoEdge(atopology varchar,
anode integer, anothernode integer, acurve geometry)
....

--
-- n) Check if curve crosses (contains) any node
-- I used _contains_ here to leave endpoints out
--
FOR rec IN EXECUTE 'SELECT node_id FROM '
|| quote_ident(atopology) || '.node '
|| ' WHERE geom && ' || quote_literal(acurve::text)
|| ' AND ST_Contains(' || quote_literal(acurve::text)
|| ',geom)'
LOOP
RAISE EXCEPTION
'SQL/MM Spatial exception - geometry crosses a node';
END LOOP;

--
-- o) Check if curve intersects any other edge
--
FOR rec IN EXECUTE 'SELECT * FROM '
|| quote_ident(atopology) || '.edge_data
WHERE ST_Intersects(geom, ' || quote_literal(acurve::text) ||
'::geometry)'
LOOP
RAISE EXCEPTION 'SQL/MM Spatial exception - geometry intersects an
edge';
END LOOP;

```