After loading the raster to PostGIS, you will inspect it both with SQL commands (analyzing the raster metadata information contained in the database), and with the gdalinfo
command-line utility (to understand the way the input raster2pgsql
parameters have been reflected in the PostGIS import process).
You will finally open the raster in a Desktop GIS and try a basic spatial query-mixing vector and raster tables.
The raster2pgsql
command is able to load any raster formats supported by GDAL in PostGIS. You can have a format list supported by your GDAL installation by typing the following command:
In this recipe, you have been importing one raster file using some of the most common raster2pgsql
options:
The -I
option creates a GIST spatial index for the raster column. The -C
option will create the standard set of constraints after the rasters have been loaded. The -F
option will add a column with the filename of the raster that has been loaded. This is useful when you are appending many raster files to the same PostGIS raster table. The -s
option sets the raster's SRID.
If you decide to include the -t
option, then you will cut the original raster in tiles, each inserted as a single row in the raster table. In this case, you decided to cut the raster in 100x100 tiles, resulting in 198 table rows in the raster table.
Another important option is -R
, which will register the raster as out-of-db
; in such a case, only the metadata will be inserted in the database, while the raster will be out of the database.
The raster table contains an identifier for each row, the raster itself (eventually one of its tiles, if using the -t
option), and eventually the original filename, if you used the -F
option, as in this case.
You can analyze the PostGIS raster using SQL commands or the gdalinfo
command. Using SQL, you can query the raster_columns
view for getting the most significant raster metadata (spatial reference, band number, scale, block size, and so on).
With gdalinfo
, you can access the same information, using a connection string with the following syntax:
The mode
parameter is not influential if you loaded the whole raster as a single block (for example, if you did not specify the -t
option). But, as in the use case of this recipe, if you split it in tiles, gdalinfo
will see each tile as a single subdataset with the default behavior (mode=1
). If you want GDAL to consider the raster table as a unique raster dataset, you have to specify the mode option and explicitly set it to 2
.