<html><head></head><body><div>Hi,</div><div><br></div><div>I have recently started working with the postgis raster functionality. In general, I have found this really useful and have been able to do some neat things fairly simply with this raster functionality. Nevertheless, there are a few basic things that I am confused about and I was hoping someone could give me a hand.</div><div><br></div><div>(1) First of all, I have a table with a bunch of rasters that have the same extent, alignment, scale, etc. and I want to aggregate them together into a single raster using pixel-by-pixel addition. It seems like there should be a function to do this, but I can't find one. Is there an aggregate "ST_MapAlgebra" function? </div><div><br></div><div>Given that I couldn't find one, I defined an aggregate function as follows:</div><div><br></div><pre>CREATE OR REPLACE FUNCTION AddRasters(r1 raster, r2 raster)</pre><pre>       RETURNS raster AS</pre><pre>$BODY$</pre><pre>SELECT ST_MapAlgebra($1,$2,'[rast1]+[rast2]');</pre><pre>$BODY$ LANGUAGE 'sql' IMMUTABLE STRICT;</pre><pre><br></pre><pre>CREATE AGGREGATE sum (raster)</pre><pre>(</pre><pre>    sfunc = AddRasters,</pre><pre>    stype = raster</pre><pre>);</pre><pre><br></pre><div>(2) This seems to work, but it has the unexpected behavior that it replaces 0 values with NULL. In my case, this is fine, but I am wondering why it does this? I can't find anything that indicates that it should be replacing zeros with NULL. Here is the metadata associated with one of my rasters (the others are similar):</div><div><br></div><pre># SELECT ST_BandMetadata(rast), ST_Metadata(rast), ST_SummaryStats(rast) FROM blah;</pre><pre>-[ RECORD 1 ]---+-------------------------------------------------------</pre><pre>st_bandmetadata | (16BUI,,f,)</pre><pre>st_metadata     | (-180,90,360,180,1,-1,0,0,4326,1)</pre><pre>st_summarystats | (64800,417,0.00643518518518519,0.223617719977485,0,46)</pre><pre></pre><pre><br></pre><div>I have not defined a nodataval for these layers and the original layers have no NULL values.</div><pre><br></pre><div>(3) Is there a postgis command to turn all the NULL values back into zeros?</div><div><br></div><div>(4) I was also considering just defining the '+' operator for raster + raster to be pixel-by-pixel addition. Is there any reason that I wouldn't want to do this?</div><div><br></div><div>(5) Finally, I have been visualizing results with QGIS using the DB Manager. However, I don't see how to select a row from a raster table and incorporate just that row into the canvas. Is there a way to do this?</div><div><br></div><div>Thanks for the assistance,</div><div>David</div><div><br></div><div><br></div><div><br></div><div><span><pre>-- <br></pre><div>**********************************</div><div>David M. Kaplan</div><div>Charge de Recherche 1</div><div><br></div><div>Institut de Recherche pour le Developpement (IRD)</div><div>UMR MARBEC (IRD/Ifremer/CNRS/UMII)</div><div>av. Jean Monnet</div><div>CS 30171</div><div>34203 Sete cedex</div><div>France</div><div><br></div><div>Email: <a href="mailto:david.kaplan@ird.fr">david.kaplan@ird.fr</a></div><div>Phone: +33 (0)4 99 57 32 25</div><div>Fax: +33 (0)4 99 57 32 95</div><div><br></div><div><a href="http://www.umr-marbec.fr/kaplan-david.html">http://www.umr-marbec.fr/kaplan-david.html</a></div><div><a href="http://www.davidmkaplan.fr/">http://www.davidmkaplan.fr/</a></div><div>**********************************</div><div></div></span></div></body></html>