I have created a IDW heatmap using QGIS 1.8.0 and need to import the raster into PostGIS 2.0.1. QGIS saves the raster layer as a .asc file.

How do you import the raster into PostGIS as a Raster? What format should QGIS save the raster as? Can pgAdmin's PostGIS Shapefile and DBS Loader be used?

1 Answer 1


I don't believe the Shapefile loader will work in your case. However, PostGIS comes with a raster loading tool called raster2pgsql. This tool will load any GDAL supported raster format into PostGIS Raster. It is a command-line tool so to execute it you just need to run:

raster2pgsql raster_options schema.table_name > output.sql

So, the tool will take the input raster options (which includes the raster file you want to load, or a folder of files) and then generate a SQL script which you can then use to load the data into PostGIS using the command:

psql -d database_name -f output.sql

Of course you can also combine the commands using UNIX pipes:

raster2pgsql raster_options schema.table_name | psql -d database_name -u username -h host -p port

Chapter 5 of the PostGIS documentation provides all the necessary details you need with regards the possible raster_options you can use. If you want to know if the format you have is supported by the tool then you can run the command:

raster2pgsql -G

The .asc file is an ASCII grid which is normally supported by GDAL so you shouldn't have too many problems.

  • What is the purpose for tiling the raster? Is cutting the raster into tiles recommended? I'm currently importing a raster for a US state.
    – Nyxynyx
    Commented Apr 20, 2013 at 16:15
  • @Nyxynyx It very much depends on the application and size of the source raster. In most cases you would tile in order to create smaller areas which can be loaded faster than loading an entire image.
    – CHenderson
    Commented May 1, 2013 at 13:34
  • I have a raster the size of America. Guess I should be tiling it into... 256 x 256px?
    – Nyxynyx
    Commented May 1, 2013 at 16:23
  • Yes, I would tile that to make it more manageable. 256 x 256 will give you a very large number of files though.
    – CHenderson
    Commented May 2, 2013 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.