3

I have a problem when loading multiple raster files into a Postgis database. When I run this command in the cl

raster2pgsql -I -C -e -Y -F -s 4326 -t 100x100 *.tif public.newTable | psql -d db

the following warnings are returned:

NOTICE:  The rasters (pixel corner coordinates) are not aligned
NOTICE:  Unable to add constraint: enforce_same_alignment_rast

The rasters seem not to have exactly the same alignment. When looking at the corner coordinates, I see that they differ. Two corners that should collapse have the following coordinates (WGS):

Lower Left  (   0.0000000,   9.9996668) (  0d 0' 0.01"E,  9d59'58.80"N)
Upper Left  (   0.0000000,  10.0000001) (  0d 0' 0.01"E, 10d 0' 0.00"N)

I also tried to load the files to R using the raster package, but it didn't work either. However when loading the rasters directly into QGIS there is no problem.

Does anybody know how to resolve this issue? And why does it work in QGIS, but not in R and PostGIS?

2

You seem to think loading isn't working. It is.

the following warnings are returned:

NOTICE: The rasters (pixel corner coordinates) are not aligned

NOTICE: Unable to add constraint: enforce_same_alignment_rast

Just to sum up, you're violating a constraint that's added after the rasters are loaded. The rasters are being loaded perfectly fine (because you're adding the -C flag). The only way to remedy that is to fix the violation. Normally, you either create a superset raster and copy over what you want, or do it the easy way with ST_Resample()

ST_Resample — Resample a raster using a specified resampling algorithm, new dimensions, an arbitrary grid corner and a set of raster georeferencing attributes defined or borrowed from another raster.

  • Thanks Evan! Your answer is exactly what I was looking for. For clarification: Yes, the raster tiles can be loaded to the db regardless of the constraint. The problem was, that I couldn't query an extent of the raster that overlaps two or more tiles due to the same-alignment violation. For anyone facing the same problem: you may also consider ST_SnapToGrid(). – David Hanimann May 12 '17 at 7:27
0

You can load the rasters without the -C option and then use AddRasterConstraints() to add only the constraints you wish.

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.