Skip to content

Instantly share code, notes, and snippets.

@ndkv
Last active December 24, 2015 02:29
Show Gist options
  • Save ndkv/6730449 to your computer and use it in GitHub Desktop.
Save ndkv/6730449 to your computer and use it in GitHub Desktop.
Extract a raster as GeoTIFF from PostGIS 2 ht @bmmeijers
import psycopg2
conn_string = "host='' dbname='' user='' password=''"
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
cursor.execute("SELECT ST_AsTIFF(rast, 'JPEG90') as img FROM sq_rast WHERE rid=1;")
rast = cursor.fetchone()
with open('raster.tiff', 'wb') as f_out:
f_out.write((rast[0]))
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment