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'm trying to follow the instructions here to load a raster into a PostGIS database:

python raster2pgsql.py -s 4269 -I -r *.tif -F myschema.demelevation -o elev.sql

I understand that I replace * with the path to my raster, but I don't understand the part myschema.demelevation or elev.sql. Should I have my own schema for this file? And what does the elev.sql part mean?

I also read through the gdal PostGIS raster driver to try and understand this with more examples. Similarly, they suggest loading a raster katrina

python raster2pgsql.py -r /path/to/katrina.tif -t katrina -l 1 -k 64x64 -o katrina.sql -s 4326 -I -M

Using my current setup, I tried loading the katrina raster in:

    python2.6 ~/src/postgis-2.0.0SVN/raster/scripts/python/raster2pgsql.py -r ~/tmp/katrina.tif -t katrina -l 1 -k 64x64 -o katrina.sql -s 4326 -I -M

However, I got the following errors:

Traceback (most recent call last):
  File "/home/src/postgis-2.0.0SVN/raster/scripts/python/raster2pgsql.py", line 34, in <module>
    from osgeo import gdal
  File "/home/lib/python2.6/GDAL-1.8.1-py2.6-linux-i686.egg/osgeo/__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "/home/lib/python2.6/GDAL-1.8.1-py2.6-linux-i686.egg/osgeo/__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: /home/lib/python2.6/GDAL-1.8.1-py2.6-linux-i686.egg/osgeo/_gdal.so: undefined symbol: GDALSetRasterUnitType

I don't fully understand these errors mean; when I compiled gdal should I have specified an argument for GDALSetRasterUnitType ?

More generally, I'm having difficulty understanding why I am not specifying the database that I am trying to load this data into.


After following MerseViking's advice I ran:

python /usr/lib/postgresql/8.4/bin/raster2pgsql.py -r /home/celenius/Downloads/katrina.tif -t katrina -l 1 -k 64x64 -o katrina.sql -s 4326 -I -M

which returned the following output:

------------------------------------------------------------
 Summary of GDAL to PostGIS Raster processing:
------------------------------------------------------------
Number of processed raster files: 1 (/home/celenius/Downloads/katrina.tif)
List of generated tables (number of tiles):
1   katrina (256)

Then I ran:

psql -d test -f katrina.sql - U postgres -W

which returned the following:

    addrastercolumn                                                                                                                                                                                        
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 public.katrina.rast srid:4326 pixel_types:{8BUI,8BUI,8BUI} out_db:false regular_blocking:true nodata_values:NULL scale_x:'0.029325513196481' scale_y:'-0.029325513196481' blocksize_x:'64' blocksize_y:'64' extent:POLYGON((-100.014662756598 9.98533724340176,-100.014662756598 40.0146627565982,-69.9853372434018 40.0146627565982,-69.9853372434018 9.98533724340176,-100.014662756598 9.98533724340176))
(1 row)

(END)

This message and a blinking cursor appear on screen. I assume that it is loading into the database, but I'm not sure. The tif file is just 3MB - I had assumed that it would not take long to load a file of this size but the blinking cursor has already been on the screen for ~1 hour. Has this crashed or do I just need to wait a long time? I have 4GB of RAM and a dual-processor of 2.5 GHz.

share|improve this question
    
I have found that if I hit the key q, that it executes this command, and inserts the data into the database test. Is this normal behavior and should I be doing this? –  djq Nov 7 '11 at 19:32

1 Answer 1

up vote 2 down vote accepted

It seems there's a typo on that page; in the line:

python raster2pgsql.py -s 4269 -I -r *.tif -F myschema.demelevation -o elev.sql

The -F parameter should be -t which specifies the table name to import the data into. The part before the . is the optional schema name if you want your table in a schema other than public. The -o parameter specifies the file that is generated by the Python script. This file is the SQL representation of your table definition and the actual data from the source raster, so it can get pretty large. Once this file is generated, you need to run it through psql -d <db_name> -f elev.sql to actually populate the database, after which it can be deleted.

However, what strikes me as odd is that you're calling raster2pgsql.py from the PostGIS 2.0 source directory. Have you actually compiled (by running make) and installed (by running make install as root) PostGIS 2.0? Because it should be on your path, and IIRC the installer automatically updates your PYTHON_PATH environment variable.

As for the missing GDALSetRasterUnitType, the thing I would first check for is that you don't have an earlier version of GDAL libraries installed that Python is picking up instead of 1.8.1. Try gdalinfo --version This site may shed some light on your problem.

share|improve this answer
    
Thanks for the suggestions - I'll test it out. I am quite confused about how to call this script. I have run make and make install;I should have been calling it from ./bin/raster2pgsql.py. I am using shared hosting that does not have root access, but I can install programs. When I run gdalinfo --version I get GDAL 1.5.3, released 2008/09/09; which is the server version; I have installed GDAL 1.8.1 but it's not being picked up by this command. –  djq Nov 4 '11 at 13:11

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.