1

Can someone explain to me what I am doing wrong here as I think I do not properly understand postgis raster bands.

I have a set of geometries that I want to merge with a raster and created a raster as a result.

I am creating the raster as follows:-

WITH RASTERS AS (
                 SELECT rast from raster_table
                ),

     GEOMETRIES AS (
                 SELECT ST_AsRaster(wkb_geometry,
                                    RASTERS.rast,
                                    {'8BUI,8BUI,8BUI'}::TEXT[],
                                    100,100,100,
                                    0,0,0
                                    ) AS raster_geom FROM geometries_table,RASTERS
                ),
     UNION AS (
       SELECT rast as rast FROM RASTERS
         UNION ALL
       SELECT raster_geom as rast FROM GEOMETRIES
     ) 
     SELECT ST_AsPng(ST_Union(rast)) FROM UNION

Now, this works and creates a merged raster but I am getting results as below where the color is completely out, the whole base raster becomes red.

enter image description here

I am sure this is to do with the Pixeltype/data/nodata values in the ST_AsRaster call, but I don't properly understand it. I am thinking that I should get these values from the base raster. This is the result I am trying to achieve, as you can see it works fine with a different base raster type:-

enter image description here

  • Are you sure that is what you are using. Your ST_AsRaster call makes no sense. I don't see how that can possibly run since you are missing critical commas. The first argument should be a geometry (not a raster) so perhaps that is casting to a geometry (which would be square). "8BUI,8BUI,8BUI" also makes no sense (should make this break) -- should use '{8BUI,8BUI,8BUI}'::text[] – LR1234567 Aug 21 '14 at 5:11
  • I've edited the query, the one I am actually using is slightly more complex as variables are passed in. I summarised it for clarity. It definitely works as the two images are produced using it. – user1331131 Aug 21 '14 at 7:39
  • How are you overlaying these rasters? You aren't using the ST_Union function, so I presume you are using something else to overlay the results. I'm guessing one of your rasters is RGBA or AGRB or something like that (and the raster you are generating only has 3 bands). So how the 4th band is treated is up to whatever your overlay software is doing and assuming. – LR1234567 Aug 22 '14 at 3:05
  • The rasters are overlaid using union a per the last part of the query – user1331131 Aug 22 '14 at 17:34
  • But what are you using to output? If you are using UNION ALL, you re getting back at least 2 rasters (as opposed to ST_Union) which would return 1 raster and require you to have the same number of bands? postgis.net/docs/manual-dev/RT_ST_Union.html. You should run ST_NumBands to make sure you have the same number of bands in each – LR1234567 Aug 23 '14 at 2:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.