[GIS] Importing GeoTIFF into PostGIS without raster2pgsql

postgispostgis-2.0postgis-raster

I know that one can import GeoTIFF into PostGIS via raster2pgsql. I was wondering if there is any easy way (as a sequence of SQL statements) to do the same without resorting to the command line tool?

Essentially, I am interested in a PostgreSQL function that is the inverse of ST_AsTIFF, which given a pathname to a GeoTIFF, creates a pgraster table or a row in such a table.

The reason I ask is that I need such a function in a SQL stored procedure to import and process GeoTIFFs (not known in advance).

Best Answer

Take a look at ST_FromGDALRAster.

http://postgis.net/docs/manual-2.1/RT_ST_FromGDALRaster.html

Though that function assumes you imported the GTIFF as a bytea in PostgreSQL. If you want to keep the file out of the database and you have out-db enabled for your raster, you can use ST_AddBand. There is an example of an out-db tiff on the reference of this page:

http://postgis.net/docs/manual-2.1/RT_ST_AddBand.html