I am trying to upload a geoTIFF file into my PostGIS database. Using raster2psql, it works.

raster2pgsql -I -C -M *.tif -F -t auto mytablename > mytable.sql
psql -d mydatabase -f mytable.sql

However, my datatable is not what I expect it to be.

I get:

rid | rast | filename 
 1    01000001000F1111111111813F0F111111111181BF00000000008066C0FAFFFFFFFF7F564000000000000000000000000000000000E61000001E001E006AFDFF7FFFFDFF7... filename.tif

What I want is:

rid | geometry | value | filename
 1    0100AF...   12.3   filename.tif

Where geometry is the hex code associated, and the value is the band value from the raster.

How would I go about doing that?


So, I decided to forgo the use of raster2pgsql and trying to "fix" the datatable for my purposes. I instead wrote a python script to read a tif file and upload its information to PostGIS, using rasterio and psycopg2.

If anyone has a comment as to why this isn't a default behavior obtainable with raster2pgsql, I'm still curious. GeoTIFF, from my understanding, are often used to carry information as much, if not more so, than display.


As far as I know, PostGIS stores raster in bigger objects, not tile-wise. So your one line contains multiple raster cells, which you can see in any GIS program. Have you tried to use -t <a>x<b>, where a and b are the size of your raster cells? At least I've done that once and the corresponding value should be accessible with ST_Value. Check out the documentation for examples.

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.