Thanks Tom,<br><br>I tried to select WHERE (ss).count > 0 and (ss).sum > 0, but i still got the same error. I assume that this is something that need to be changed in the script.<br>I will do some more testing.<br><br>
Does anyone have an idea for something that could bypass this in my query?<br><br>SELECT foo2.gid, (ss).sum / 3600 AS meanttime<br>INTO accessgrid FROM (SELECT foo.gid, ST_SummaryStatsAgg(gv) ss <br> FROM (SELECT p.gid, ST_Clip(r.rast, p.cell) gv FROM access r, priogrid_land p WHERE ST_Intersects(r.rast, p.cell)) foo <br>
GROUP BY foo.gid) foo2 <br>ORDER BY foo2.gid;<br><br>Thanks!<br><br>Andreas<br><br><div class="gmail_quote">2011/12/19 Tom van Tilburg <span dir="ltr"><<a href="mailto:tom.van.tilburg@gmail.com">tom.van.tilburg@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Yes, well found.<br>
<br>
I'm not familiar with plpgsql, but I'm sure it's easy to include
some conditional statement. Just check the postgres documentation.<br>
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.<br>
<br>
all the best,<br><font color="#888888">
Tom</font><div><div></div><div class="h5"><br>
<br>
On 19-12-2011 11:13, Andreas Forø Tollefsen wrote:
<blockquote type="cite">Line 59 to 77 in the st_summarystatsagg.sql.<br>
Could it be that line 69: ($1).sum / ($1).count leads to division
by zero error if ($1).count is 0?<br>
How could i change this so this is not the case?<br>
<br>
-- raster_summarystatsfinal<br>
-- Final function used by the ST_SummaryStatsAgg aggregate <br>
CREATE OR REPLACE FUNCTION raster_summarystatsfinal(ss
summarystats)<br>
RETURNS summarystats <br>
AS $$<br>
DECLARE<br>
ret summarystats;<br>
BEGIN<br>
ret := (($1).count,<br>
($1).sum,<br>
($1).sum / ($1).count,<br>
null,<br>
($1).min,<br>
($1).max<br>
)::summarystats;<br>
RETURN ret;<br>
END;<br>
$$<br>
LANGUAGE 'plpgsql';<br>
<br>
<div class="gmail_quote">2011/12/19 Andreas Forø Tollefsen <span dir="ltr"><<a href="mailto:andreasft@gmail.com" target="_blank">andreasft@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Updated to
latest trunk, and now it works.<br>
However, I ran into a new "division by zero" error. This halts
the query.<br>
Could it be that something is divided by integer rather than
decimal in the query, or what else causes this:<br>
<br>
ERROR: division by zero<br>
CONTEXT: PL/pgSQL function "raster_summarystatsfinal" line 5
at assignment<br>
<br>
********** Error **********<br>
<br>
ERROR: division by zero<br>
SQL state: 22012<br>
Context: PL/pgSQL function "raster_summarystatsfinal" line 5
at assignment<br>
<br>
Best,<br>
<font color="#888888">Andreas</font><br>
</blockquote>
</div>
</blockquote>
<br>
</div></div></div>
<br>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
<br></blockquote></div><br>