Hi Alexandre,

perhaps you could run ST_Simplify in a function with a while loop testing over ST_NPoints:

CREATE OR REPLACE FUNCTION simplify_npoints(geometry, integer)
  RETURNS geometry AS
$BODY$

DECLARE
  InGeom alias for $1;
  maxpoints alias for $2;
  npoints integer;
  tolerance float;
  outGeom geometry;

Begin

npoints:=ST_NPoints(InGeom);
outGeom:=InGeom;
tolerance:=0.0;

while npoints > maxpoints loop
  tolerance:=tolerance + 0.001;
  outGeom:=ST_Simplify(InGeom, tolerance);
  npoints:=ST_NPoints(outGeom);
end loop;

return outGeom;

End;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION simplify_npoints(geometry, integer) OWNER TO postgres;



I don't know if it will work (didn't test). And perhaps bigger iteration steps would be sufficient, too...

Good luck! Regards,

Birgit.


Am 24.10.2012 14:29, schrieb Alexandre Saunier:
Hello.

I would like to know if some tools are available in PostGIS to
simplify a linestring to a given maximum number of points.
A bit like the "simplify,count=<...>" filter in GPSBabel:
http://www.gpsbabel.org/htmldoc-development/filter_simplify.html

ST_Simplify is close to what I need but I don't know in advance what
tolerance to use, only the final maximal number of points.

Is there a way to do that kind of simplification with PostGIS?

Thanks!
Alexandre
_______________________________________________
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users@postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

Reply via email to