1

I have a postgresql remote database where all postgis and raster features have been enabled.

I am trying to execute a query of a raster table within a schema but the system returns the following error

rt_raster_to_gdal: Could not load the output GDAL driver

by using the following code

import psycopg2
from rasterio.io import MemoryFile
import rioxarray as riox
    
# DB Configuration
dbname = "Database"
dbuser = "user"
dbpass = "pass"
dbhost = "host.com"
dbport = "8080"

try:
    conn = psycopg2.connect(database=dbname, user=dbuser, password=dbpass, host=dbhost, port=dbport)
    curs = conn.cursor()
    print("Database connected successfully")
except:
    print("Database not connected successfully")
curs.execute("select ST_AsGDALRaster(st_union(rast), 'GTIFF') from schema.table;")
result = curs.fetchone()

I have tried also to add the follow code to previouse script but nothing change

curs.execute("SET postgis.gdal_enabled_drivers = 'ENABLE_ALL';")

how can i fix this issue?

1 Answers1

0

For GTiff output, access to out-db raster bands must be enabled. You can read more about this configuration option here: https://postgis.net/docs/postgis_enable_outdb_rasters.html

Enable it for your current session with

SET postgis.enable_outdb_rasters = True;

Please note that for this option to have any effect you still need the necessary GDAL drivers to be enabled in the PostGIS environment. Namely, the driver for GTiff.

Elisabeth Strunk
  • 516
  • 1
  • 6
  • 15