[postgis-users] Rasterize a vector

Bborie Park bkpark at ucdavis.edu
Tue May 29 11:33:32 PDT 2012


On 05/29/2012 11:20 AM, Paolo Cavallini wrote:
> Il 29/05/2012 20:06, Bborie Park ha scritto:
> 
>> WITH ref AS (
>> 	SELECT ST_MakeEmptyRaster(1, 1, 0, 0, 1, -1, 0, 0, 0) AS rast
>> )
>> SELECT
>> 	ST_AsRaster(g.geom, ref.rast, '32BUI', g.id, 0)
>> FROM mygeomtable g
>> CROSS JOIN ref
>>
>> That would convert your geometries into rasters, all of which have the
>> same alignment with pixel values set to the particular geometry's id.
>> So, for 20 input geometries, there would be 20 output rasters.
> 
> but:
> 
> WITH ref AS (
> SELECT ST_MakeEmptyRaster(1, 1, 0, 0, 1, -1, 0, 0, 3003) AS rast
> )
> SELECT
> ST_AsRaster(g.geom, ref.rast, '32BUI', g.id, 0)
> FROM province g
> CROSS JOIN ref;
> ERROR:  rt_raster_gdal_rasterize: Unable to add band to GDALDataset
> CONTEXT: PL/pgSQL function "st_asraster" line 26 at RETURN
> 

Strange.  That works for me on a variety of my geometry tables...

WITH ref AS (
	SELECT ST_MakeEmptyRaster(1, 1, 0, 0, 1, -1, 0, 0, 4326) AS rast
)
SELECT
	(ST_SummaryStats(ST_AsRaster(s.shape, ref.rast, '32BUI', s.id, -1))).*
FROM site s
CROSS JOIN ref
LIMIT 10

Can you provide the output of

SELECT postgis_full_version();

-bborie
-- 
Bborie Park
Programmer
Center for Vectorborne Diseases
UC Davis
530-752-8380
bkpark at ucdavis.edu



More information about the postgis-users mailing list