[postgis-users] Raster ST_Clip fails when a geometry either only touches or barely intersects.

Yosuke Kimura yosukesabai at gmail.com
Sat Mar 25 13:43:31 PDT 2017


Hello,

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.

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).


SELECT ST_Summary(
        ST_Clip(
                ST_AddBand(
                        ST_MakeEmptyRaster(16, 16, 0, 0, 1, 1, 0, 0),
                        ARRAY[
                        ROW(1, '8BUI'::text, 0, 255),
                        ROW(2, '8BUI'::text, 0, 255),
                        ROW(3, '8BUI'::text, 0, 255)
                        ]::addbandarg[]
                )
                -- this works
                --, ST_GeomFromText('POLYGON((15.999999 15.999999,
15.999999 17, 17 17, 17 15.999999, 15.999999 15.999999))')
                -- this fails
                , ST_GeomFromText('POLYGON((15.9999999 15.9999999,
15.9999999 17, 17 17, 17 15.9999999, 15.9999999 15.9999999))')
        )
);


psql:demo_clip_fail_barelyintersects.sql:16: ERROR:  RASTER_clip: Could not
get band from working raster
CONTEXT:  PL/pgSQL function st_clip(raster,integer[],geometry,double
precision[],boolean) line 8 at RETURN
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20170325/10a8ba2e/attachment.html>


More information about the postgis-users mailing list