osmc:Metodologia/Algoritmo SQL/Issues: mudanças entre as edições

m
Linha 165: Linha 165:


<syntaxhighlight lang="sql">
<syntaxhighlight lang="sql">
DROP FUNCTION IF EXISTS st_transform_resilient
DROP FUNCTION IF EXISTS ST_Transform_Resilient
;
;
CREATE FUNCTION public.st_transform_resilient(
CREATE FUNCTION ST_Transform_Resilient(
   g geometry,       -- the input 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 for target density of points, relative to ST_CharactDiam.
   size_fraction float DEFAULT 0.05,  -- 1/density. Density of points per charactDiam (or negative for absolute fraction).
   tolerance float DEFAULT 0 -- e.g. on srid=4326 use 0.00000005
   tolerance     float DEFAULT 0     -- E.g. on srid=4326 use 0.00000005
) RETURNS public.geometry
) RETURNS       geometry
    LANGUAGE sql IMMUTABLE
  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  
          ST_SimplifyPreserveTopology(geom,tolerance) -- ST_Simplify enough for grid cells  
       ELSE geom
       ELSE geom
       END
       END
  FROM (
  FROM (
  -- discuss ideal at https://gis.stackexchange.com/q/444441/7505
   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!
2 391

edições