Skip to content

Instantly share code, notes, and snippets.

@leplatrem leplatrem/gist:5729022
Last active May 24, 2019

Embed
What would you like to do?
CREATE OR REPLACE FUNCTION SimplifyEdgeGeom(atopo varchar, anedge int, maxtolerance float8)
RETURNS float8 AS $$
DECLARE
tol float8;
sql varchar;
BEGIN
tol := maxtolerance;
LOOP
sql := 'SELECT topology.ST_ChangeEdgeGeom(' || quote_literal(atopo) || ', ' || anedge
|| ', ST_Simplify(geom, ' || tol || ')) FROM '
|| quote_ident(atopo) || '.edge WHERE edge_id = ' || anedge;
BEGIN
RAISE DEBUG 'Running %', sql;
EXECUTE sql;
RETURN tol;
EXCEPTION
WHEN OTHERS THEN
RAISE WARNING 'Simplification of edge % with tolerance % failed: %', anedge, tol, SQLERRM;
tol := round( (tol/2.0) * 1e8 ) / 1e8; -- round to get to zero quicker
IF tol = 0 THEN RAISE EXCEPTION '%', SQLERRM; END IF;
END;
END LOOP;
END
$$ LANGUAGE 'plpgsql' STABLE STRICT;
@rcoltp

This comment has been minimized.

Copy link

commented May 27, 2017

thanks for sharing, actually reading further on your post i see you already provided the function ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.