Last active
December 24, 2015 02:29
-
-
Save ndkv/6730449 to your computer and use it in GitHub Desktop.
Extract a raster as GeoTIFF from PostGIS 2 ht @bmmeijers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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