Import rasters file to PostGIS database using raster2pgsql

Import rasters file to PostGIS

raster2pgsql is GIS command line utility which is installed as a part of PostGIS. To install raster2pgsql, you have to install PostGIS and raster2pgsql will be installed with it.

To import raster to postgis, type following command in terminal and replace file name and database details with yours. It will successfully import your raster to postgis.

When you are working with command line utilities, it is very important to understand their command line parameters. Let’s discuss above parameters that we have used with raster2pgsql.

  • -F will create filename column to store the file name of raster being imported.
  • -I will create Gist index or raster spatial index which is used to optimize raster processing in postgis
  • -C Apply raster constraints — srid, pixelsize etc. to ensure raster is properly registered in postgis.
  • -s Apply the coordinate system to output raster
  • -t Apply the tile size to raster. The output will be divided into multiple raster tiles based on the tile size and will create multiple records in output postgis table. If tile size is not given, the raster will be stored as single tile.
  • GRAY_LR_SR_W.tif is raster file that we are importing
  • public.world_elevation is the table name which will have our raster file in postgis
  • psql postgresql://postgres:admin@localhost:5432/postgis_in_action is database details like username, host, password, database

We have imported our raster file to postgis. It has imported it in multiple tiles as you can see below.

I hope this tutorial will create a good foundation for you and will help you to import raster data to postgis.

If you want tutorials on another GIS topic or you have another queries, please send an email at contact@spatial-dev.guru

Leave a Reply Cancel reply

%%footer%%