[postgis-users] Spike finder

Pier Lorenzo Marasco pl.marasco at gmail.com
Wed Jun 11 01:56:33 PDT 2014


I tried to modify spikeRemover from Schmidt & Krüger to obtain just the
spike position. For some reason, that I can't figure out, my script fails
and I don't obtain a multipoint position. Probably there is a problem in
the aggregation of different points but I don't know how to manage it in
another way. I tried with ST_collect and ST_union but with both I don't
obtain a right geometry.

CREATE OR REPLACE FUNCTION ST_SpikeFinder (geometry, angle double precision)
     returns geometry as
     $body$
     DECLARE
     ingeom alias for $1;
     angle  alias for $2;
     lineusp geometry;
     newgeom geometry;
     numpoints integer;
     point_id integer;
     result_pnt geometry;

    begin
            -- input geometry or rather set as default for the output
        newgeom := ingeom;
       -- check polygon
        if (select st_geometrytype(ingeom)) = 'ST_Polygon' then
            if (select st_numinteriorrings(ingeom)) = 0 then
            lineusp := st_boundary(ingeom) as line;
                    numpoints := st_numpoints(lineusp);
            point_id := 0;
                -- the geometry passes pointwisely
            while (point_id <= numpoints) loop
                        result_pnt := ST_Collect(result_pnt,
st_pointn(lineusp, point_id));
                    -- the check of the angle at the current point of a
spike including the special case, that it is the first point.
                    if (select abs(pi() - abs(st_azimuth(st_pointn(lineusp,
case when point_id= 1 then st_numpoints(lineusp) - 1 else point_id - 1
end),
                                st_pointn(lineusp, point_id)) -
st_azimuth(st_pointn(lineusp, point_id), st_pointn(lineusp, point_id +
1))))) <= angle then
        (probably the problem is here)      --->        result_pnt :=
ST_Union(result_pnt, st_pointn(lineusp, point_id));
end if;
            point_id = point_id + 1;
            end loop;
        end if;
        end if;
            return result_pnt;
     end;
     $body$
       language 'plpgsql' volatile;

Any idea ?
Thank you in advance.


L.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20140611/f81e183f/attachment.html>


More information about the postgis-users mailing list