<div dir="ltr">Hi All,<div><br></div><div>I'm working to do some overlay analyses between raster and vector layers, and having an issue getting an accurate count of pixels per polygon.</div><div><br></div><div>My query is below - basically my raster layer has values ranging 1-5, with some nodata pixels (defined as such, with values of 0). I want to calculate, for each polygon, the proportion of pixels, of the total (including nodata), with values of 1 and 2. </div><div><br></div><div>The first ST_CountAgg statement (yielding 'count_undevel') seems to be working as expected, and reports an accurate number. However, the second one, to create the 'count_total' field consistently gives an over-count.  </div><div><br></div><div>Any guess as to what might be going on/how to correct? I'll gladly share the properties of the data if that would be useful.</div><div><br></div><div>Thanks!</div><div>Mike</div><div><br></div><div><br></div><div><br></div><div><div>SELECT *,</div><div> count_undevel/(count_total)::float as PropVeg --Calculates proportion of pixels within each building that are class 1 or 2 based on count_undevel and count_total</div><div>INTO resultsvectorlayers.pctgrn</div><div>FROM(</div><div><span class="" style="white-space:pre">       </span>SELECT </div><div><span class="" style="white-space:pre">   </span>p.*,</div><div>--Count number of pixels per building with values 1 or 2</div><div><span class="" style="white-space:pre">        </span>ST_CountAgg(</div><div><span class="" style="white-space:pre">               </span>ST_Reclass(</div><div><span class="" style="white-space:pre">                        </span>ST_Clip(rast, p.geom_2263),</div><div><span class="" style="white-space:pre">                        </span>1,'[1-2]:1, [3-5]:0', '8BUI',0), 1,TRUE) --reclassifies classes 1 and 2 as 1, reclassifies values 3-5 as 0, and designates 0 as nodata</div><div><span class="" style="white-space:pre">             </span>as count_undevel,</div><div>--Count total number of pixels</div><div><span class="" style="white-space:pre">     </span>ST_CountAgg(</div><div><span class="" style="white-space:pre">               </span>ST_Clip(rast, p.geom_2263),</div><div><span class="" style="white-space:pre">                </span>1,FALSE)</div><div><span class="" style="white-space:pre">           </span>as count_total</div><div><span class="" style="white-space:pre">     </span>FROM staging.naip_ndvi_classified_2013 r, staging.nycbldgs p</div><div><span class="" style="white-space:pre">       </span>WHERE ST_INTERSECTS(r.rast, p.geom_2263) --and rid = 2</div><div><span class="" style="white-space:pre">     </span>group by p.geom_2263, p.gid</div><div>) AS FOO;</div></div><div><br></div><div><br></div><div><br></div></div>