<div dir="ltr"><div>Hello,</div><div><br></div><div>I am trying to work on spatial statistics between a polygon and raster.  My code works like 99.99+% of time but once in a while it fails because ST_Clip fails.</div><div><br></div><div>Below is an example case.  As you see, when a polygon barely intersects with raster, I am getting "RASTER_clip: Could not get band from working raster".  How do I work around it?  In my application I have millions of polygons and raster table of hundreds of thousands of record.  I use ST_Intersects(p.geom, r.rast) between table of polygons p and table of raster r, then ST_Clip(r.rast, p.geom).  </div><div><br></div><div><br></div><div>SELECT ST_Summary(<br>        ST_Clip(<br>                ST_AddBand(<br>                        ST_MakeEmptyRaster(16, 16, 0, 0, 1, 1, 0, 0),<br>                        ARRAY[<br>                        ROW(1, '8BUI'::text, 0, 255),<br>                        ROW(2, '8BUI'::text, 0, 255),<br>                        ROW(3, '8BUI'::text, 0, 255)<br>                        ]::addbandarg[]<br>                )<br>                -- this works<br>                --, ST_GeomFromText('POLYGON((15.999999 15.999999, 15.999999 17, 17 17, 17 15.999999, 15.999999 15.999999))')<br>                -- this fails<br>                , ST_GeomFromText('POLYGON((15.9999999 15.9999999, 15.9999999 17, 17 17, 17 15.9999999, 15.9999999 15.9999999))')<br>        )<br>);</div><div><br></div><div><br></div><div>psql:demo_clip_fail_barelyintersects.sql:16: ERROR:  RASTER_clip: Could not get band from working raster<br>CONTEXT:  PL/pgSQL function st_clip(raster,integer[],geometry,double precision[],boolean) line 8 at RETURN</div></div>