[postgis-users] Raster pixel value
Tom van Tilburg
tom.van.tilburg at gmail.com
Mon Dec 19 02:17:16 PST 2011
Yes, well found.
I'm not familiar with plpgsql, but I'm sure it's easy to include some
conditional statement. Just check the postgres documentation.
You can also check if you can put the conditional into your SQL query
(something like 'WHERE count(rast) > 0') so that you don't feed empty
rasters to the function.
all the best,
Tom
On 19-12-2011 11:13, Andreas Forø Tollefsen wrote:
> Line 59 to 77 in the st_summarystatsagg.sql.
> Could it be that line 69: ($1).sum / ($1).count leads to division by
> zero error if ($1).count is 0?
> How could i change this so this is not the case?
>
> -- raster_summarystatsfinal
> -- Final function used by the ST_SummaryStatsAgg aggregate
> CREATE OR REPLACE FUNCTION raster_summarystatsfinal(ss summarystats)
> RETURNS summarystats
> AS $$
> DECLARE
> ret summarystats;
> BEGIN
> ret := (($1).count,
> ($1).sum,
> ($1).sum / ($1).count,
> null,
> ($1).min,
> ($1).max
> )::summarystats;
> RETURN ret;
> END;
> $$
> LANGUAGE 'plpgsql';
>
> 2011/12/19 Andreas Forø Tollefsen <andreasft at gmail.com
> <mailto:andreasft at gmail.com>>
>
> Updated to latest trunk, and now it works.
> However, I ran into a new "division by zero" error. This halts the
> query.
> Could it be that something is divided by integer rather than
> decimal in the query, or what else causes this:
>
> ERROR: division by zero
> CONTEXT: PL/pgSQL function "raster_summarystatsfinal" line 5 at
> assignment
>
> ********** Error **********
>
> ERROR: division by zero
> SQL state: 22012
> Context: PL/pgSQL function "raster_summarystatsfinal" line 5 at
> assignment
>
> Best,
> Andreas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20111219/b7ad216d/attachment.html>
More information about the postgis-users
mailing list