[postgis-users] Problem using ST_AsRaster

Mark Wynter mark at dimensionaledge.com
Sat Jun 23 23:04:22 PDT 2012


I can rasterise a vector layer, but I'm having trouble mapping it to a reference raster.

The reference raster, called dummy_rast is a 1x1 raster tile with a height and width of 500pixels, each of 250m in size.  I created using a pl/pgsql function:
SELECT make_tiled_raster('public', 'dummy_rast', 576000, -3780000, 1, 1, 500, 500, 250, -250);
The result is 
 
 srid | scale_x | scale_y | blocksize_x | blocksize_y | num_bands | pixel_types | nodata_values 
------+---------+---------+-------------+-------------+-----------+-------------+---------------
 3577 |     250 |    -250 |         500 |         500 |         1 | {8BUI}      | {NULL}


I now wish to burn a vector layer onto this raster:

CREATE TABLE viewshed_rast AS
WITH vt as (SELECT ST_Union(geometry) as geometry FROM viewshed_vectors)
SELECT rt.rid, ST_AsRaster(vt.geometry, rt.rast, '8BUI', 120, 100) as rast FROM dummy_rast as rt, vt;

The result is 
srid | scale_x | scale_y | blocksize_x | blocksize_y | num_bands | pixel_types | nodata_values 
------+---------+---------+-------------+-------------+-----------+-------------+---------------
 3577 |     250 |    -250 |          67 |          38 |         1 | {8BUI}      | {100}
(1 row)

I do not understand why the resultant raster does not map to the reference raster?   Refer screenshot attached showing the resultant layers in QGIS.  The upperleftx and upperlefty, and the block size of the resultant raster are defined by the extent of the vector layer and not the reference raster.   

Is there something obvious I'm doing wrong?  Thanks.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen shot 2012-06-24 at 3.54.12 PM.png
Type: image/png
Size: 33816 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120624/2eb48a5c/attachment.png>


More information about the postgis-users mailing list