Skip to content

Instantly share code, notes, and snippets.

View fralc's full-sized avatar

Francesco LoConti fralc

View GitHub Profile
@fralc
fralc / raster_postgis.py
Last active June 5, 2020 15:54 — forked from gzagatti/raster_postgis.py
Loads raster data from POSTGIS directly to numpy.array using rasterio
import psycopg2
from rasterio.io import MemoryFile
conn = pscopg2.connect("<connection string>")
cur = conn.cursor()
# ensure that the GTiff driver is available,
# see https://postgis.net/docs/postgis_gdal_enabled_drivers.html
cur.execute('''
SET postgis.gdal_enabled_drivers TO 'GTiff';
WITH temp as (