Last active
May 7, 2022 02:15
-
-
Save leplatrem/5729022 to your computer and use it in GitHub Desktop.
Sandro Santilli's SimplifyEdgeGeom
http://strk.keybit.net/blog/2012/04/13/simplifying-a-map-layer-using-postgis-topology
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for sharing, actually reading further on your post i see you already provided the function ;)