<div dir="ltr"><div><div>Thanks for this.<br></div>But it didn't work for me.<br><br></div>These queries work<br><div><br>SELECT (ST_SummaryStats(ST_MapAlgebra(rast, 1, '16BSI'::text, '[rast]+1'), 1)).* FROM rastertmp.ndvitmp<br>SELECT (ST_SummaryStats(ST_MapAlgebra(rast, 1, NULL, '[rast]+1'), 1)).* FROM rastertmp.ndvitmp<br><br></div><div>But not when I use the condition [rast] > 0<br><br>SELECT (ST_SummaryStats(ST_MapAlgebra(rast, 1, NULL, '[rast] > 0'), 1)).* FROM rastertmp.ndvitmp<br><br>ERROR:  cannot cast type boolean to double precision<br>LINE 1: SELECT ($1 > 0)::double precision<br><br></div><div>Replacing NULL for '16BSI'::text, or '16BSI'::smallint, '16BSI'::double precision doen't solve the problem<br></div><div><br></div><div>Any other suggestion?<br></div><div>Thanks<br><br><br><br><br><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Juli<div><span style="color:rgb(51,51,153)">--</span><br><font color="#333399"><b>CIDE, CSIC</b>  |  <a href="http://www.uv.es/jgpausas" target="_blank">www.uv.es/jgpausas</a>  | <br><br></font></div></div></div></div></div></div>
<br><div class="gmail_quote">On Tue, Jun 30, 2015 at 5:29 PM, Pierre Racine <span dir="ltr"><<a href="mailto:Pierre.Racine@sbf.ulaval.ca" target="_blank">Pierre.Racine@sbf.ulaval.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You can select pixels fulfilling an expression using the one-raster variant of ST_MapAlgebra<br>
<br>
<a href="http://postgis.net/docs/RT_ST_MapAlgebra_expr.html" rel="noreferrer" target="_blank">http://postgis.net/docs/RT_ST_MapAlgebra_expr.html</a><br>
<br>
So just do something like:<br>
<br>
ST_MapAlgebra(rast, '8BUI'::text, '[rast] > 0')<br>
<br>
before computing stats.<br>
<br>
To count the number of pixels of a certain value you can use ST_ValueCount().<br>
<br>
Pierre<br>
<div><div class="h5"><br>
> -----Original Message-----<br>
> From: <a href="mailto:postgis-users-bounces@lists.osgeo.org">postgis-users-bounces@lists.osgeo.org</a> [mailto:<a href="mailto:postgis-users-">postgis-users-</a><br>
> <a href="mailto:bounces@lists.osgeo.org">bounces@lists.osgeo.org</a>] On Behalf Of juli g. pausas<br>
> Sent: Monday, June 29, 2015 12:49 PM<br>
> To: PostGIS Users Discussion<br>
> Subject: [postgis-users] raster, stats conditioned to a set of values<br>
><br>
> Hi all<br>
><br>
> I'm just starting to discover postgis, it is really useful.<br>
><br>
> I have a raster file with different bands, that I have imported to postgres<br>
> (raster2pgsql, without the -R option, i.e., insite the database). I would like to<br>
> extract information from band 1, but filtering the data using only<br>
><br>
> 1) pixels with positive values (in that band, band 1)<br>
><br>
> 2) and pixels in which band 2 is equal to a given value, e.g. 1<br>
><br>
><br>
> The type of analysis I'd like to do is descriptive stats but also intersecting<br>
> with a vector map. If my raster is rastertmp.ndvitmp, two examples are:<br>
><br>
><br>
> SELECT (ST_SummaryStats(rast, 1)).* FROM rastertmp.ndvitmp WHERE rid<br>
> = 1<br>
><br>
><br>
><br>
> SELECT p.region_cod, ST_ValueCount(ST_Clip(r.rast,1, p.geom, true)) AS res<br>
>   FROM gis_wd.wd_regiones AS p, rastertmp.ndvitmp AS r<br>
>   WHERE ST_Intersects(r.rast, p.geom)<br>
>   AND p.region_cod = 'PA1214';<br>
><br>
><br>
><br>
> This works perfectly, but how can I compute the stats  only for pixels with<br>
> positive values and with a given value in another band?  The idea would be<br>
> something like:  WHERE ST_Values(rast, 1)>0 AND ST_Values(rast, 2)=1<br>
><br>
><br>
> Thanks for any help!<br>
><br>
><br>
> Juli<br>
> --<br>
> CIDE, CSIC  |  <a href="http://www.uv.es/jgpausas" rel="noreferrer" target="_blank">www.uv.es/jgpausas</a>  |<br>
><br>
<br>
</div></div>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
</blockquote></div><br></div>