Raster ST_Clip fails when a geometry either only touches or barely intersects.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Raster ST_Clip fails when a geometry either only touches or barely intersects.

Yosuke Kimura

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_MakeEmptyRaster(16, 16, 0, 0, 1, 1, 0, 0),
                        ROW(1, '8BUI'::text, 0, 255),
                        ROW(2, '8BUI'::text, 0, 255),
                        ROW(3, '8BUI'::text, 0, 255)
                -- 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

postgis-users mailing list
[hidden email]