[postgis-users] ST_Buffer + grid problem

Pierre Racine Pierre.Racine at sbf.ulaval.ca
Fri Mar 23 05:55:36 PDT 2012


> Can you please let me know how I can do this? So I did the make empty raster ->
> map algebra -> pixel as polygons approach!
> Since there is no dependency on data now, is it possible for you to maybe
> outline the steps you performed at your end to get this working?
> MapAlgebra needed 2 rasters, so I inputted the same raster twice. So please

There is a one raster version of ST_MapAlgebraExpr(). That's the one to use....

> --SELECT (md).*
> --FROM (SELECT ST_MetaData(rast) As md
> --    FROM (select ST_MakeEmptyRaster( 8, 4, 8.07734039737749,
> 57.7505109647578, 0.000036,0.000036,0,0, 4326 ) rast) foo) foo2;
> 
> 
> create table vector_grid as
> select (ST_PixelAsPolygons(rastfin)).geom , (ST_PixelAsPolygons(rastfin)).val
> from ( select ST_MapAlgebraExpr(rast, rast, '([rast.x] - 1) * '  ||
> ST_Width(rast)::text || ' + [rast.y]' ) rastfin from (select ST_MakeEmptyRaster( 8,
> 4, 8.07734039737749, 57.7505109647578, 0.000036,0.000036,0,0, 4326 ) rast)
> foo) foo2;

If you want to assign the index values to the raster:

SELECT ST_MapAlgebraExpr(ST_MakeEmptyRaster(8, 4, 8.07734039737749, 57.7505109647578, 0.000036,0.000036,0,0, 4326 ), '32BUI', '([rast.x] - 1) * 8 + [rast.y]'::text)

If you are happy with the polygons:

SELECT (gvxy).geom, ((gvxy).x - 1) + (gvxy).y cellid
FROM (SELECT ST_PixelAsPolygons(ST_MakeEmptyRaster(8, 4, 8.07734039737749, 57.7505109647578, 0.000036,0.000036,0,0, 4326 )) gvxy) foo

Pierre





More information about the postgis-users mailing list