[postgis-users] Spike finder

Pier Lorenzo Marasco pl.marasco at gmail.com
Fri Jun 13 05:12:14 PDT 2014


Hi Birgit !

Thank you for your time and answer; actually I found a workaround to my
problem. I don't know if it's the right way but  actually it works.
The problem was the incorrect assignment of the result.
The correct way is to use an array of geometry to collect all points and
then, before the restitution command , create a geometry of multipoint made
by ST_collect.

result_pnt geometry[]; ...

result_pnt[point_id] := st_pointn(lineusp, point_id); ...

return ST_Collect(result_pnt);

As I told you, I'm pretty sure that there is a better, faster and smartest
way to do it and I'll be happy to receive any suggestion to improve my
solution.
Thank you again,

L.


2014-06-13 12:52 GMT+02:00 Birgit Laggner <birgit.laggner at ti.bund.de>:

>  Hi L.
>
> I would suspect the first assignment of the result_pnt (result_pnt :=
> ST_Collect(result_pnt, st_pointn(lineusp, point_id));) as the cause of the
> problem: Within your assignment, you try to use the geometry of result_pnt
> which does not yet exist at this moment. Maybe, you could work with an IF
> clause to assign some sort of start value to your result_pnt variable.
>
> Regards,
>
> Birgit.
>
>
> Am 11.06.2014 10:56, schrieb Pier Lorenzo Marasco:
>
>  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.
>
>
> _______________________________________________
> postgis-users mailing listpostgis-users at lists.osgeo.orghttp://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>



-- 
Pier Lorenzo Marasco
Via D.Moreni,2
50135 Firenze

cell/mobile   +39 329 35 37527
Casa/home  +39 055 011 71 20
skype pl.marasco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20140613/a0637556/attachment.html>


More information about the postgis-users mailing list