Test data
- 1 TIF file (159KB)
Goal threefold:
- Load raster into PostGIS using
raster2pgsql
and visualize in QGIS - In my IPython Notebook connect to PostGIS and load raster into NumPy array
- In my IPyhton Notebook use Pandas to load a time-series of one pixel of rasters with different time step stored in PostGIS
Process so far
I've managed to get one raster image into PostGIS Raster using the raster2pgsql
command and visualize it in QGIS using the DB Manager:
raster2pgsql -s 4326 -d -I -C -M -R -l 4 D:\Downloads\raster//modis.tif -F -t 100x100 public.ndvi | psql -U postgres -d rastertest -h localhost -p 5432
But how to access/query this raster from within IPython Notebook?
I found this presentation, which is going about SQLALchemy and GeoAlchemy2. And where it is mentioned that it support PostGIS Raster as well. It seems to be very interesting! But using the documentation I don't see how I can apply this to Raster data
I think I can make a connection to my PostGIS database using the following code, where postgres=user
, password=admin
and database=rastertest
:
from sqlalchemy import create_engine
engine = create_engine('postgresql://postgres:admin@localhost/rastertest', echo=True)
But then.. any advice is very much appreciated.
ipython-sql
(pypi.python.org/pypi/ipython-sql), which allows you to connect to a database and write queries in IPython notebook with %sql and %%sql magic, avoiding the ORM route entirely. – herrfz