2 585
edições
Linha 165: | Linha 165: | ||
<syntaxhighlight lang="sql"> | <syntaxhighlight lang="sql"> | ||
DROP FUNCTION IF EXISTS | DROP FUNCTION IF EXISTS ST_Transform_Resilient | ||
; | ; | ||
CREATE FUNCTION | CREATE FUNCTION ST_Transform_Resilient( | ||
g geometry, | g geometry, -- the input geometry | ||
srid integer, -- target SRID, to transform g | srid integer, -- target SRID, to transform g | ||
size_fraction float DEFAULT 0.05, -- 1/density | size_fraction float DEFAULT 0.05, -- 1/density. Density of points per charactDiam (or negative for absolute fraction). | ||
tolerance float DEFAULT 0 -- | tolerance float DEFAULT 0 -- E.g. on srid=4326 use 0.00000005 | ||
) RETURNS | ) RETURNS geometry | ||
language SQL IMMUTABLE | |||
AS $f$ | AS $f$ | ||
SELECT CASE | SELECT CASE | ||
WHEN COALESCE(size_fraction,0.0)>0.0 AND COALESCE(tolerance,0)>0 THEN | WHEN COALESCE(size_fraction,0.0)>0.0 AND COALESCE(tolerance,0)>0 THEN | ||
ST_SimplifyPreserveTopology(geom,tolerance) -- ST_Simplify enough for grid cells | |||
ELSE geom | ELSE geom | ||
END | END | ||
FROM ( | FROM ( | ||
SELECT CASE | SELECT CASE | ||
WHEN size>0.0 THEN ST_Transform( ST_Segmentize(g,size) , srid ) | WHEN size>0.0 THEN ST_Transform( ST_Segmentize(g,size) , srid ) | ||
Linha 195: | Linha 194: | ||
) t2 | ) t2 | ||
$f$; | $f$; | ||
COMMENT ON FUNCTION ST_Transform_Resilient IS | |||
'Avoid clothesline-effect. See problem/solution discussed at https://gis.stackexchange.com/q/444441/7505' | |||
; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Migrar função para o git oficial! |
edições