8

I would like to add attributes to a raster stored in a postgis database. I use the following command to insert the raster in the database:

raster2pgsql -s 4236 -I -C -M /home/user/mysrc/outlabeled.tif public.test | psql -d template_postgis

The raster outlabeled.tif is in fact a one-band raster with a label per group of pixels (object). Then I have computed .txt files with attributes that I'd like to add to the raster (like an attribute table in a shapefile). Is it possible to do it (and how)? So far I've the impression that the only way to do it is actually to add a raster band (and not text files). If it's not possible, would an attribute table added with gdal before the importation do the job?

3

After adding your raster file to the template_postgis database as the public.test table you can use ALTER TABLE for creating new columns in public.test and then UPDATE statement to populate them with corresponding attributes. But this will be only one row per raster.

If you have multiple rasters in template_postgis table and you want to join them with a separate table of attributes, you need to use some key to bind them by a JOIN statement. For example you can import raster with a flag -F (which adds a column with the name of the file).

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.