I'm having a problem with ST_MapAlgebra.

An error stating The set of rasters provided (custom extent included, if appropriate) do not have the same alignment is shown.

I've been trying to know where the error comes from and nothing seems to fix it.

My SELECT is this one:

SELECT ST_MapAlgebra(rast, 
                 (430276.740772 - 429856.518926)::numeric::integer, 
                 (4581915.18987 - 4581587.0391)::numeric::integer, 
                  429856.518926, 4581915.18987, 2), 
            '8BUI'::text, 1, 0), 
        '[rast1]', '8BUI', 'SECOND') 
FROM bigraster;

SELECT ST_SetBandNoDataValue(rast, 1) FROM bigraster; is '8BUI'
select st_pixelwidth(rast) FROM bigraster is 2

What else could be wrong?


1 Answer 1


To work, rasters passed to the two rasters variant of ST_MapAlgebra() must:

1) be in the same coordinate system. You can reproject one raster to the coordinate system of the other raster with ST_Transform(). Do not do this on tiled rasters. Only on one-row rasters. If your raster is tiled (multiple-rows), merge it with ST_Union() into a one-row raster before reprojecting it. If it's too big to be merged in the DB, reproject it outside the DB with GDAL and reload it.

2) be aligned. i.e. every corners of every pixels of each raster must fall exactly on one of the corner of the other raster so that the grid of pixels are well aligned. If they are not, you can reallign one of the two rasters with ST_Resample(), if they do not have the same pixel size, using the other raster as reference or, if they have the same pixel size, with ST_SnapToGrid() using the other raster upperleft corner.

Always check visually, in QGIS or OpenJump, with ST_PixelAsPolygons() or ST_DumpAsPolygons(), that your two rasters are well aligned.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.