This is great! Fantastic. I will do some testing.<br><br><div class="gmail_quote">2011/12/1 Tom van Tilburg <span dir="ltr"><<a href="mailto:tom.van.tilburg@gmail.com" target="_blank">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">
Pierre,<br>
<br>
This is great you're working on this. It is exactly what I think that pgraster is going to make a great tool.<br>
<br>
Last days I didn't really have time to check out things, hopefully this week.<br>
<br>
Cheers,<br><font color="#888888">
 Tom</font><div><div></div><div><br>
<br>
On 30-11-2011 19:19, Pierre Racine wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Andreas, Tom,<br>
<br>
I have put two new functions you might be interested by in<br>
<br>
<a href="http://trac.osgeo.org/postgis/browser/trunk/raster/scripts/plpgsql" target="_blank">http://trac.osgeo.org/postgis/<u></u>browser/trunk/raster/scripts/<u></u>plpgsql</a><br>
<br>
The first one, st_areaweightedsummarystats.<u></u>sql, is usefull when you want to compute summary stats (like the weighted mean) of values coming from a raster table for a series of polygons and that you use ST_Intersection(raster, geometry) to compute the intersection. You normally use it this way:<br>


<br>
SELECT <a href="http://gt.id" target="_blank">gt.id</a>,<br>
        (aws).count,<br>
        (aws).distinctcount,<br>
        (aws).geom,<br>
        (aws).totalarea,<br>
        (aws).meanarea,<br>
        (aws).totalperimeter,<br>
        (aws).meanperimeter,<br>
        (aws).weightedsum,<br>
        (aws).weightedmean,<br>
        (aws).maxareavalue,<br>
        (aws).minareavalue,<br>
        (aws).maxcombinedareavalue,<br>
        (aws).mincombinedareavalue,<br>
        (aws).sum,<br>
        (aws).mean,<br>
        (aws).max,<br>
        (aws).min<br>
FROM (SELECT ST_AreaWeightedSummaryStats(<u></u>gv) aws<br>
       FROM (SELECT ST_Intersection(rt.rast, gt.geom) gv<br>
             FROM rasttable rt, geomtable gt<br>
             WHERE ST_Intersects(rt.rast, gt.geom)<br>
            ) foo<br>
       GROUP BY <a href="http://gt.id" target="_blank">gt.id</a><br>
      ) foo2<br>
<br>
The second one, st_summarystatsagg.sql, serve the same purpose but when you are using ST_MapAlgebra() (soon ST_Clip()) to compute the intersection. you normally use it like this:<br>
<br>
SELECT (ss).count,<br>
        (ss).sum,<br>
        (ss).mean,<br>
        (ss).min,<br>
        (ss).max<br>
FROM (SELECT ST_SummaryStatsAgg(gv) ss<br>
       FROM (SELECT ST_Clip(rt.rast, gt.geom) gv<br>
             FROM rasttable rt, geomtable gt<br>
             WHERE ST_Intersects(rt.rast, gt.geom)<br>
            ) foo<br>
       GROUP BY <a href="http://gt.id" target="_blank">gt.id</a><br>
      ) foo2<br>
<br>
This is very equivalent to what you were doing. The ST_Clip() replace the ST_MapAlgebra() part and the ST_SummaryStatsAgg() replace the ST_SummaryStats(ST_Union())  part. This should be faster since it does a ST_Union() less.<br>


<br>
I'm working on a plpgsql version of ST_Clip(). I will post it very soon.<br>
<br>
Pierre<br>
<br>
______________________________<u></u>_________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.<u></u>refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.<u></u>net/mailman/listinfo/postgis-<u></u>users</a><br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.<u></u>refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.<u></u>net/mailman/listinfo/postgis-<u></u>users</a><br>
</div></div></blockquote></div><br>