Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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 Apr 20 '13 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 May 1 '13 at 13:34
    
I have a raster the size of America. Guess I should be tiling it into... 256 x 256px? –  Nyxynyx May 1 '13 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 May 2 '13 at 9:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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