Skip to content

How to install and configure PostGIS Raster on Windows

March 10, 2011

A lot of people ask me about how to use PostGIS Raster and the GDAL PostGIS Raster driver in Windows systems. And most of them are, comprehensibly, using the last stable releases of both libraries (PostGIS and GDAL). The problem is PostGIS Raster and GDAL driver are being developed in these moments. There’s no stable release, so far.

PostGIS Raster was included as official part of PostGIS in October 2010. The old version, formerly named WKT Raster has been abandoned. So, if you want to use PostGIS Raster, with new functionalities and many bugs fixed, you’ll have to use the latest PostGIS development snapshot. The use of the old WKT Raster extension is strongly unrecommended, and there’s no support for it.

About GDAL, there was an important change in the driver on October 20st, 2010. A new version was committed, and this is the only version that works with PostGIS Raster. This new driver version was included in the release 1.8.0, currently the stable release. So, the use of an older release to connect with PostGIS Raster is also unrecommended.

With these facts in mind, I understand the Windows users who want to use PostGIS Raster and the GDAL driver are a bit unprotected. I’m not a Windows user, but I consider it my fault. For this reason, I’ve decided to create this howto. I’m going to install and configure PostGIS Raster and GDAL in Windows. And fortunately, you don’t need to compile anything. Let’s go for it:

Enviroment: Windows 7 32 bits

Step 1: Installing Python and Numpy

PostGIS Raster loader uses GDAL Python bindings and numpy. So, we’ll first install Python and numpy. Several options here:

  • Python 2.5, unofficial numpy 1.5.1 (download numpy-1.5.1.win32-py2.5.‌exe from here)
  • Python 2.6, unofficial numpy 1.5.1 (download numpy-1.5.1.win32-py2.6.‌exe from here)
  • Python 2.7, unofficial numpy 1.5.1 (download numpy-1.5.1.win32-py2.7.‌exe from here)

I’m using:

  • Python 2.6.6
  • Numpy 1.5.1 (numpy-1.5.1.win32-py2.6.‌exe)

Step 2: Installing GDAL

I think the easiest way to have a complete GDAL installation (library + binaries + Python bindings) working on Windows is using the GDAL binaries mantained by Tamas Szekeres, here. Last GDAL versions from trunk are compiled daily with MSVC 2003, MSVC 2005 and MSVC 2008. Pick one. For example, the version compiled with MSVC 2003, here.

The  faster way now would be to download the generic installer for the GDAL core components, and choose the complete installation

GDAL 1.8.0 core installer for Windows

GDAL 1.8.0 core installer for Windows

After the installation, you will need to add C:\Program Files\GDAL\ to the PATH enviroment var. And create this new var:

GDAL_DATA=C:\Program Files\GDAL\gdal-data

UPDATE 2011-10-07: About the GDAL Python bindings

After installing GDAL core components, you must install the Python bindings separately. You can use this installer (for Python 2.7 and GDAL 1.8.0), or grab one of the executables existent at http://www.lfd.uci.edu/~gohlke/pythonlibs/

Depending on your Python installation, you can choose GDAL-1.8.1.win32-py2.6.‌exe, GDAL-1.8.1.win32-py2.7.‌exe, GDAL-1.8.1.win32-py3.1.‌exe or GDAL-1.8.1.win32-py3.2.‌exe

UPDATE 2011-03-25: Alicia Duarte, from IDESF, told me she was to additionally set the next enviroment vars to make it work:

GDAL_DRIVER_PATH=C:\Program Files\GDAL\gdalplugins
PROJ_LIB=C:\Program Files\GDAL\projlib

WARNING: This directory (GDAL Python bindings location) may not exist in your GDAL installation. In my case, the bindings are in C:\Python27\Lib\site-packages\osgeo, and I didn’t need to define this variable.

PYTHONPATH=C:\Program Files\GDAL\python

UPDATE 2011-07-19:  I think I introduced some confusion in the comments. I apologize for that. Several people are having problems with GDAL Python bindings. I’ll  try to make it clearer:

  • On one hand, there’s a sure thing: you need GDAL library + GDAL Python bindings installed in your system. There’s an easy way of doing it, by executing the generic installer: gdal-18-1310-core.msi. This installer includes the Python bindings, and they’re installed at C:\Program Files\GDAL\python directory by default. This should be enough.
  • If you previously have a Python interpreter and a GDAL version installed on your system (check it from a console, executing gdalinfo –formats), you may want to simply install the proper GDAL Python bindings. Let’s assume your GDAL version is 1.8 (lower versions won’t work with PostGIS Raster), and your Python version is 2.7. Then, you simply need to install GDAL-1.8.0.win32-py2.7.msi. This installer will put GDAL Python bindings at C:\Python27\Lib\site-packages by default. This is a different location than above, but at the end, you should have a working version of GDAL Python bindings on your system.
  • Finally,  the PostGIS Windows experimental binaries with PostGIS Raster support (step 4) are packed with their own version of GDAL library, used only by the raster2pgsql loader.

GDAL installed. Now, let’s go with step 3

Step 3: Installing PostgreSQL

I recommend Postgresql 8.4.x or higher. You can download the 1-click-installer from here, and install it in the common Windows’ way.

During the installation, you’ll be asked to install some nice additional stuff using the Application Stack Builder, like PostGIS 1.5.x or PostGIS 1.4.x. Don’t install anything. The PostGIS versions that can be installed doesn’t include PostGIS Raster. And you can’t install it separately, because, remember, now is part of PostGIS. We’re going to install last PostGIS version by hand. Don’t be afraid, it’ll be easy.

Step 4: Installing PostGIS

We’re going to use the PostGIS Windows experimental binaries. We need the binaries compiled for PostgreSQL 8.4, these ones

Once uncompressed, you can see this

postgis20 windows

Contents of binary package PostGIS 2.0 for Windows

Following the instructions of README.txt file, let’s edit makepostgisdb.bat to adapt the vars to our enviroment. We may want to change these vars:

set PGPORT=5432
set PGHOST=localhost
set PGUSER=postgres
set PGPASSWORD=password_of_postgres_user
set THEDB=template_postgis20
set PGBIN=C:\Program Files\PostgreSQL\8.4\bin\
set PGLIB=C:\Program Files\PostgreSQL\8.4\lib\

After that, we make a backup of our PostgreSQL bin and lib directories (PGBIN and PGLIB). Just in case.

We now execute makepostgisdb.bat. Take into account you may want to execute the script as administrator, in case your Windows user doesn’t have needed privileges (it was my case).

UPDATE 2011-06-08: For all Windows XP Professional SP2 users:

when you run makepostgisdb.bat from the binaries of POSTGIS SVN2.0, please rename the libiconv-2.dll in bin folder of Postgresql/8.4/bin folder to any other name. Now run the makepostgisdb.bat file. You will not get any error of “operation aborted …. transaction block” (Thanks to C Patnaik)

Once executed, we have PostGIS 2.0 + PostGIS Raster installed and configured. A new database called template_postgis20 is created, enabled with PostGIS and PostGIS Raster. Easy! Let’s test it with the next query:

select postgis_full_version(), postgis_raster_lib_build_date(), postgis_raster_lib_version()

And the result:

PostGIS version installed

PostGIS version installed

Of course, you can create your own database using template_postgis20 as template. From the command line:

createdb -U postgres -T template_postgis20 your_database

Or from pgAdmin III:

Creating new database from template in pgAdmin III

Creating new database from template in pgAdmin III

If you want to use the SHP2PGSQL GUI, you must copy the postguisgui folder (inside bin folder in the downloaded PostGIS experimental binaries file) into pgAdmin III folder (mine is C:\Program Files\pgAdmin III\1.12) and add the next lines to plugins.ini file, inside pgAdmin III folder too:

;
;PostGIS shp2pgsql-gui (Windows):
;
Title=PostGIS Shapefile and DBF loader
Command="$$PGBINDIR\postgisgui\shp2pgsql-gui.exe" -h "$$HOSTNAME" -p $$PORT -U "$$USERNAME" -d "$$DATABASE" -W "$$PASSWORD"
Description=Open a PostGIS ESRI Shapefile or Plain dbf loader console to the current database.
KeyFile=$$PGBINDIR\postgisgui\shp2pgsql-gui.exe
Platform=windows
ServerType=postgresql
Database=Yes
SetPassword=Yes

After that, you can use the GUI inside pgAdmin III:

SHP2PGSQL GUI installed under pgAdmin III

SHP2PGSQL GUI installed under pgAdmin III

Now you can load raster data into your database in 2 steps. In the first step, you will generate a SQL file. Open a command line and execute this:

python C:\Program Files\Postgresql\8.4\bin\raster2pgsql.py -r image.tif -t tablename -o image.sql

As result of this step, a SQL file named image.sql will be created in the directory where you executed the Python line above.

In the second step, you’ll need to load the SQL file in your_database, by using your favourite PostgreSQL client. For example, pgAdmin. If your use the psql command line client, the line to execute is:

psql -h localhost -U postgres -d your_database -f image.sql

If you want to translate your raster data from the database to image files at disk again, execute gdal_translate.

gdal_translate PG:"dbname=your_database user=postgres table=your_table mode=2" your_file.tif

Basically, this is all what you need to work with PostGIS Raster in Windows. Anyway, take into account the next additional notes:

Additional notes:

In step 2, I installed the whole GDAL library, including binaries and Python bindings. In step 4, I installed PostGIS 2.0 with all its pre-requisites. One of them is GDAL. The optimal way would be to use the existent GDAL library, but we’re working with pre-compiled binaries and DLLs. So, we have 2 copies of GDAL library:

  • C:\Program Files\GDAL\gdal18.dll: Installed with generic installer for GDAL, in step 2. Used by gdal_translate, when reading data from database, and in any operation involving GDAL, except the raster loading with raster2pgsql.py script
  • C:\Program Files\PostgreSQL\8.4\bin\libgdal.dll: Installed with PostGIS Windows experimental binaries, in step 4. Used by raster2pgsql.py script, to load raster data into PostgreSQL.

Both library files were compiled from GDAL 1.8.0 from trunk. But they will be slightly different, for sure. This is a suboptimal solution, of course, but it shouldn’t cause problems, because libgdal.dll is only used when loading raster data into the database. The rest of operations involving GDAL will be executed linking with gdal18.dll

If you want to translate the raster data to any image format different from TIFF, you can use the -of option in gdal_translate. For example:

gdal_translate -of "PNG" PG:"dbname=your_database user=your_user password=your_password table=your_table mode=2" your_file.png

To get available raster formats:

gdalinfo --formats

UPDATE 2011-06-11: I changed the gdal_translate line. I’m using the ‘postgres’ user and the ‘trust’ method to authenticate this user (so, no password is needed), but it’s only a simplification. In general, you should use a different user and a password-enabled authentication method, like md5. Thanks to C.Patnaik again, because his comment remainded me this issue

Conclussions:

It’s possible to work with the last version of PostGIS Raster and GDAL PostGIS Raster driver in Windows, but assuming that:

  • You’re using experimental build. Not recommended for production enviroments.
  • The previous versions of PostGIS Raster (WKT Raster) and GDAL PostGIS Raster driver (before GDAL 1.8.0) are discontinued. Don’t use them.
  • It’s a suboptimal solution, because you install 2 copies of GDAL library. But I think this is the best available solution right now.

Do you have problems, something to add, modify or correct? Let me know it in the comments

 

About these ads
125 Comments leave one →
  1. Eman permalink
    March 28, 2011 12:06 pm

    it give me that error

    “ImportError: No module named osgeo”

    when i run raster2pgsql.py

    please help
    thanks

    • March 28, 2011 12:32 pm

      That error is caused because the GDAL Python bindings are not properly installed. Execute python from a console and try this:

      >>> from osgeo import gdal

      If you get an error like:

      Traceback (most recent call last):
      File “”, line 1, in
      ImportError: cannot import name gdal

      You have to install GDAL Python bindings. Do it following instructions in step 2, by using the GDAL generic installer for core components. Choose the “complete” installation or the custom installation, if you want to manually choose the components to install. In that case, be sure the last option (Python bindings) is selected.

      Let me know if you continue having problems.

      • Eman permalink
        March 28, 2011 12:59 pm

        give me that in the python console
        >>> from osgeo import gdal

        LookupError: unknown encoding: cp720

  2. Eman permalink
    March 28, 2011 1:11 pm

    i reinstall GDAL-1.8 “complete” and still the same problem

  3. March 28, 2011 1:26 pm

    Sounds like your console is using a locale unsupported by Python. To help you, I should know the python version you’re running and the locale of your console. If you’re using Python 3.x, you should try executing this:

    http://hg.python.org/cpython/file/default/Lib/encodings/cp720.py

    Further information here: http://www.velocityreviews.com/forums/t722822-encoding-issue-cp720.html

  4. Eman permalink
    March 28, 2011 1:31 pm

    python version 2.6

    • March 28, 2011 2:12 pm

      Probably, your console is using a locale not supported by Python. Could you change it?

  5. Eman permalink
    March 28, 2011 3:00 pm

    i reinstall python to be 2.6.5 and change locale
    and give me this error

    >>> from osgeo import gdal
    File “”, line 1
    from osgeo import gdal
    ^
    IndentationError: unexpected indent
    >>>

    • March 28, 2011 3:16 pm

      You probably introduced a space before starting writing in python console. Simply call python interpreter from console and write this, with no spaces at all before or after the text:

      from osgeo import gdal

  6. Eman permalink
    March 28, 2011 3:29 pm

    i’m sorry but there is another error

    >>> from osgeo import gdal
    Traceback (most recent call last):
    File “”, line 1, in <modul
    ImportError: No module named osgeo

    and thank you for your replay

  7. March 28, 2011 3:47 pm

    Ok, try with:

    import gdal

    instead of:

    from osgeo import gdal

    Maybe you’ve installed old-gen python bindings, because you chose an old binary version of GDAL.

    Did you install GDAL 1.8? It’s the only GDAL version that will properly work with PostGIS Raster

  8. Eman permalink
    March 28, 2011 4:14 pm

    thank you very much
    it is success after install GDAL-1.8.0.win32-py2.6.exe

    i am trying now to import .jpg image by

    raster2pgsql.py -r 555.jpg -t public.image -o image.sql

    psql -h localhost -U postgres -d template_postgis -f image.sql

    the sconde command give me this error

    CREATE TABLE
    psql:image.sql:3: ERROR: function addrastercolumn(unknown, unknown, unknown, in
    teger, text[], boolean, boolean, numeric[], numeric, numeric, unknown, unknown,
    unknown) does not exist
    LINE 1: SELECT AddRasterColumn(‘public’,’image’,’rast’,-1, ARRAY[’8B…
    ^
    HINT: No function matches the given name and argument types. You might need to
    add explicit type casts.
    psql:image.sql:4: ERROR: current transaction is aborted, commands ignored until
    end of transaction block
    ROLLBACK

  9. March 28, 2011 4:35 pm

    Check if the template_postgis database has a table named “raster_columns”. This message seems to appear because the PostGIS Raster extension wasn’t properly installed in template_postgis. Strange.

  10. Eman permalink
    March 28, 2011 4:46 pm

    when i make new database and it’s tamplate is postgis20 it create
    2 schemas the first one “public”
    contain one table “raster_overviews”
    and the second schema called “topology”
    which contain two tables “layer and topology”
    and no tables called “raster_columns”.

  11. March 28, 2011 5:00 pm

    If you use http://postgis.refractions.net/download/windows/pg84/experimental/postgis/postgis-pg84-binaries-2.0.0svn.zip as PostGIS binaries, the database template_postgis should be created with all the PostGIS and PostGIS Raster stuff, in only 1 schema (public schema). If it wasn’t created (I don’t know the reason), you can create it manually:

    Inside that zip file, there are several SQL files with all the functions and tables you need to activate a new or existent PostgreSQL database with PostGIS and PostGIS Raster. These SQL files are inside \share\contrib\postgis-2.0 folder.

    So, do these steps, from console:

    createdb -U postgres
    createlang -U postgres plpgsql
    psql -U postgres -f postgis.sql -d
    psql -U postgres -f spatial_ref_sys.sql -d
    psql -U postgres -f rtpostgis.sql -d

    Then, you’ll can load raster files in by using raster2pgsql.py

  12. Chang permalink
    March 30, 2011 12:31 am

    Hi, I am trying to use the postgis raster, after i installed postgis raster and GDAL and python3.2
    when I run type raster2pgsql.py, i got the following error, don’t know how to fix.

    C:\Program Files\OpenGeo\OpenGeo Suite\pgsql\8.4\bin>raster2pgsql.py
    File “C:\Program Files\OpenGeo\OpenGeo Suite\pgsql\8.4\bin\raster2pgsql.py”, l
    ine 633
    print ‘BEGIN BLOCK SCANLINES (numpy): (%d, %d)’ %(len(pixels[0]), len(pixels
    ))
    ^
    SyntaxError: invalid syntax

    • March 30, 2011 10:41 am

      Hello,

      This line is from a debug only function (dump_block_numpy). Calls to that function are commented in the official version of the script, in PostGIS trunk (http://trac.osgeo.org/postgis/browser/trunk/raster/scripts/python/raster2pgsql.py).

      Could you check if the calls to function dump_block_numpy (in lines 799 and 824) are commented? If not, please comment them and execute the script again.

      • haochangli@gmail.com permalink
        March 30, 2011 9:06 pm

        Hi, thank you for the reply. However, both lines are commented.

      • Chang permalink
        March 30, 2011 11:43 pm

        Hi,

        The error is fixed. This’s just python 3.2 has different print function.

        But now I am facing another problem:
        C:\Program Files\OpenGeo\OpenGeo Suite\pgsql\8.4\bin>raster2pgsql.py
        Traceback (most recent call last):
        File “C:\Program Files\OpenGeo\OpenGeo Suite\pgsql\8.4\bin\raster2pgsql.py”, line 34, in
        from osgeo import gdal
        File “C:\Program Files\GDAL\python\osgeo\__init__.py”, line 21, in
        _gdal = swig_import_helper()
        File “C:\Program Files\GDAL\python\osgeo\__init__.py”, line 17, in swig_import_helper
        _mod = imp.load_module(‘_gdal’, fp, pathname, description)
        ImportError: DLL load failed: The specified module could not be found.

        C:\Program Files\OpenGeo\OpenGeo Suite\pgsql\8.4\bin>

      • March 31, 2011 12:21 pm

        This error is because the GDAL library can not be found. Did you add the path to gdal bin folder to your PATH enviroment var?

        Further information here: http://lists.osgeo.org/pipermail/gdal-dev/2010-October/026526.html

      • March 31, 2011 12:25 pm

        More related info: http://trac.osgeo.org/gdal/ticket/3426

      • Chang permalink
        March 31, 2011 7:56 pm

        Hi, I think i already set up the PATH:
        Variable name: Path
        Variable value: C:\Program Files\GDAL

        I install GDAL 18 by default (complete program file/), the postSQL under program file/opengeo/opengeo suite/

    • March 31, 2011 9:20 pm

      Your PATH var should include more things. For example, if you open a console and put “dir” on it, you’ll get a directory listing. This is because the path to “dir” binary is part of PATH enviroment var.

      Open a console and put:

      set

      You’ll get all your enviroment vars. PATH between them. You’ll have to see the complete path to GDAL binaries (I guess C:\Program Files\GDAL\bin), and the path to your gdal18.dll file (I guess C:\Program Files/opengeo/opengeo suite/).

      You can test if GDAL is correctly added to your PATH var by executing

      gdalinfo –formats

      in a console.

  13. eman permalink
    March 30, 2011 6:23 am

    hello Mr.jorgearevalo

    i build a new enviroment with postgres9.0 and postgis-pg90-binaries-2.0.0svn, the postgis20 template contain “raster_columns”
    there is no error in raster2pgsql.py command and take alot of time to convert one image .jpg in to one table with one row but i could’t see it becouse there is an error on the starting the web site
    ERROR: function force_2d(geometry) does not exist
    so what i can do please?

  14. eman permalink
    March 30, 2011 6:38 pm

    the jpg size 1.45 MB it is converted in to one table with only one row is this correct?
    but i can’t see it on the map and there is no erorrs
    i changed the extent of the map but still nothing seen although it is added as a layer in the legend map!

    • March 30, 2011 6:53 pm

      The image is small, and one row is enough. No problem there.

      About the rest… Sorry, but I don’t understand you. You could execute raster2pgsql with no problems, and you’re trying to see the image in any kind of visualizator (web based?, geoserver?). Am I right?

      In that case, the problem probably is in another part, not in PostGIS Raster (the GDAL driver, if you’re using it, for example).

      • eman permalink
        March 30, 2011 8:34 pm

        i am using mapserver for windows (ms4w) pmapper template and try to see the raster on the website

        note:when i am trying to open the raster table data which contain one row on postgres , postgres stopped and hanging!

      • March 31, 2011 12:24 pm

        Ah, ok. I didn’t test Mapserver yet. I think Regina Obe did it. I think we should move this discussion to PostGIS user list… Could you send a mail to the list with your problem?

        Anyway, if postgres backend crash, it should generate a log output. Could you provide it?

  15. eman permalink
    March 31, 2011 2:20 pm

    thank you for replay,
    the log file of postgres told me that when i opened the raster table:
    2011-03-31 14:15:23 EET LOG: could not receive data from client: No connection could be made because the target machine actively refused it.

    2011-03-31 14:15:25 EET LOG: unexpected EOF on client connection

    • March 31, 2011 2:45 pm

      Sorry, no clues on what’s happening. I recommend you to translate the question to PostGIS list.

  16. jignasha permalink
    May 24, 2011 11:14 am

    Hi,

    I installed POSTGIS successfully and also was able to execute raster2pgsql.py and store the raster data in POSTGIS but when i execute GDAL-translate I m getting the below error

    GDALOpen failed – 1
    Error checking geometry type existence. Is PostGIS correctly installed?: no connection to the server

    Can you pls help

    • May 24, 2011 11:21 am

      Which version of gdal did you install? Could you please paste the line that caused the error?

  17. C Patnaik permalink
    June 8, 2011 1:52 pm

    For all Windows XP Professional SP2 users:
    when you run makepostgisdb.bat from the binaries of POSTGIS SVN2.0, please rename the libiconv-2.dll in bin folder of Postgresql/8.4/bin folder to any other name. Now run the makepostgisdb.bat file. You will not get any error of “operation aborted …. transaction block”. I discovered it the hard way, Jorge!! As long as this file exists, the batch file does not do the Xcopy and then the prob starts. Cheers!

  18. Varunika permalink
    June 8, 2011 7:23 pm

    raster2pgsql.py [with its arguments of -r, -t and -o] – when invoked from python throws an error mentioning OCI.dll could not load. This pops up 3-4 times followed by the message : “Cant load requested dll: C:\gdal\bin\gdal\plugins\gdal_GEOR.dll. The specified module could not be found.” I have this file in its proper place and environment properly set ! In spite of this message, the corresponding sql file gets created and has been successfully incorporated in postgreSQl->PGAdminIII.
    I assume this error is non-fatal.

    • C Patnaik permalink
      June 11, 2011 2:55 pm

      You can borrow the OCI.dll file from any software installed on any Windows machine or get from a reliable site. Put this OCI.dll in the GDAL folder [I have also put in the PostgresQL folder] It works and it stops the gdal_GEOR.dll error too.

  19. June 9, 2011 11:11 pm

    Hi, I’m getting the dreaded “ImportError: No module named osgeo” message when trying to run raster2pgsql. GDAL seems to be working otherwise. I set PYTHONPATH=C:\Program Files\GDAL\python but I now see that there is no \GDAL\python folder……is this the problem? I used the core components installer and selected “complete”.

    Thanks.

    • Varunika permalink
      June 11, 2011 2:43 pm

      Stevie, please download the mapserver version of GDAL called “release-1500-gdal-1-8-0-mapserver-6-0-0″. Run this. This will create a GDAL version on C:\ only. This will have python too but in C;\GDAL\bin\gdal\python. Please maintain this GDAL installation separate from C:\Program Files\GDAL.

      • June 11, 2011 2:56 pm

        Thanks for the response!

      • June 13, 2011 4:40 pm

        Thanks for the reply, but I’m still a bit confused. When going to the link you specify, there are a list of files:

        release-1500-gdal-1-8-0-mapserver-6-0-0.zip
        GDAL-1.8.0.win32-py2.6.exe
        gdal-18-1500-core.msi etc.

        Which of these do I need? I have python 2.6 so I thought it made sense to install “GDAL-1.8.0.win32-py2.6.exe” and “gdal-18-1500-core.msi”, but you mentioned GDAL would install to just “C:\GDAL” but it installed in “C:\Program Files\GDAL”. So now I’m not sure which PATH to set, etc.

        Thanks for the help,
        Steve

      • June 13, 2011 5:39 pm

        Stevie, you should simply install “GDAL-1.8.0.win32-py2.6.exe”. This file installs GDAL at C:\Program Files\GDAL by default. As result of that installation, you’ll get C:\Program Files\GDAL\gdal18.dll. This is the GDAL library used in your system.

        Apart from this, when you install PostGIS 2.0 using PostGIS Windows experimental binaries, you get C:\Program Files\PostgreSQL\8.4\bin\libgdal.dll. This version of GDAL library is only used by the raster2pgsql.py loader, to read raster data from disk. The rest of the operations involving GDAL use the previous GDAL library, installed in step 2 at C:\Program Files\GDAL

      • June 13, 2011 9:46 pm

        Working great!. Thanks a lot, I think this will work very well for my project.

      • June 13, 2011 11:21 pm

        Happy to hear that :-D

  20. C Patnaik permalink
    June 11, 2011 2:51 pm

    For Windows XP SP2 users: [Jorge, I would help out with Windows components as the ball rolls!]:
    In the event of the following error with gdal_translate
    “error checking geometry type existence: Is PostGIS correctly installed? No connection to the server.”
    Please do the following:
    1. Open the configuration file C:\Program Files\PostgreSQL\8.4\data\pg_hba.conf in notepad.
    2. Optionally you may read thru the file OR do the next step:
    3. For a stand alone system: change the METHOD to “trust”. [towards the end of the file].
    But for a server based system please chek the server connection and establish proper authentications accordingly. Your sys admin can help you out.

  21. Varunika permalink
    July 4, 2011 6:34 pm

    1. Once a raster is loaded into PostGreSQl database, how do we get the
    >> attribute values. We tried the ST_Values but it displayed on screen or
    >> into an Excel file. We would like to store them in a db file to be
    >> accessed later. How?
    >>
    >> 2. How to view changes on the raster in real time after running an SQL
    >> query? Should linkages be established to OpenEV/Fwtools? If so, how? We
    >> need a display system, something like what ARC/INFO or ARCView does.
    >>
    >> 3. How to optimise the run time for running SQLs on large images, say,
    >> 10000×10000 lines and pixels (~400 MB). We have tried GIST indexes but
    >> still it takes 15-20 minutes.
    >>
    >> 4. How to dump results onto the table/new table? We need these results as
    >> an accessible field in the table.
    >>
    >> 5. How to run a mathematical model or any algorithm specific to a raster
    >> in conjunction with other attributes/values?
    In short how do we read/load raster attributes and use them for further zonating regions on image for analysis?

    • July 9, 2011 12:05 pm

      Hello, sorry for taking so much time to response. I had some hard days.

      1.- You may try the “CREATE TABLE AS” command, to store the query results as a new table (check http://www.postgresql.org/docs/8.4/static/sql-createtableas.html)

      2.- The PostGIS Raster data visualization with graphical clients is still immature. See http://trac.osgeo.org/postgis/wiki/WKTRaster, “Displaying PostGIS Raster” section

      3.- Which kind of queries are you running? If you could provide an example directly to postgis-user list (postgis-users@postgis.refractions.net) I think you would get some help.

      4.- See point 1. I think it applies here.

      5.- Mmmm… I’m not sure. You may use GDAL to abstract your algorithm from the raster source used. Anyway, I recommend you to ask this question in postgis-user list.

      Best regards

  22. celati laurent permalink
    July 11, 2011 4:45 pm

    Hello,
    I am at step 3. I have installed postgis2.0. But i don’t understand how to loading raster in my database. I have an error message when i try to generate this sql file with DOS :

    python C:\Program Files\Postgresql\9.0\bin\raster2pgsql.py -r image.tif -t tablename -o image.sql”.

    “python” is not recognized as a command.

    Could you throw light for me please?

    • July 11, 2011 5:53 pm

      You don’t have Python installed in your system, or it isn’t properly configured. Ensure you installed Python and the path to Python exec (python.exe) was added to PATH enviroment variable.

  23. celati laurent permalink
    July 12, 2011 5:43 pm

    Hello,

    Thank you for your message. today, i have begun again the installation procedure. i have already the same error message when i run the following command line via DOS :

    python C:\Program Files\Postgresql\9.0\bin\raster2pgsql.py -r image.tif -t tablename -o image.sql

    “python” is not recognized as a command. Nevertheless, Python is well installed on my computer and i have given good information about python path (path to python.exe).

    Really, i’m embrassed. I don’t. What is to be done?

    If you have got an idea, don’t hesit to throw light for me. in advance, i thank you.

    Kind regards.

    • July 13, 2011 10:42 am

      Hello,

      Did you install the Python interpreter from http://www.python.org/download/releases/? What happens if you open a command line (cmd.exe), write python and hit enter key? It should show you the python interpreter.

      If you get an error instead, maybe you installed python only for a user of your machine, and you’re in another user’ session. I’m not a Windows user, but I think you should be able to install Python interpreter for all your machine’s users. I did it with Windows 7 for this tutorial.

      If you’re sure you installed Python properly and still get that error, you should try adding the path to Python interpeter (C:\Python26\python.exe in my case) to the PATH enviroment variable. You have instructions on how to do this:

      - Here, for Windows 2000/XP: http://www.computerhope.com/issues/ch000549.htm
      - Here, for Windows 7: http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx

      Try to execute Python interpreter after doing this.

  24. vkm2 permalink
    July 18, 2011 10:51 pm

    Hello,
    I’ve used your helpful steps to install python 2.2.2, numpy1.6,gdal18,postgres 9.0.4.1 and postgis svn 2.0

    It worked as you said except for 2 cases: one was minor: in step 4, the bat file needs to be edited so that the xcopy commands are copying the files form postgis2.0 to postgres bin folders.

    but i havent quite gotten the raster support to work. when i try
    python “C:\Program Files\Postgresql\8.4\bin\raster2pgsql.py” –help

    i get ‘no module named osgeo’

    should i try editing the raster2pgsql.py and remove the osge reference? i do have various Paths defined as in your post, except
    - in step 2:PYTHONPATH=C:\Program Files\GDAL\python : i dont python under the GDAL folder
    -and mmy path to Python is set as C:\Python27 (not C:\Python27\python.exe)

    Can you suggest what i need to do to get it working?
    Thanks!

    • vkm2 permalink
      July 18, 2011 10:52 pm

      sorry i meant python 2.7.2 above..

      • July 19, 2011 10:34 am

        Hello,

        Don’t modify raster2pgsql. The ‘osgeo’ include is necessary to work. The problem is your system can’t find the GDAL Python bindings. The PYTHONPATH enviroment var must point to the directory containing these bindings (osgeo directory, gdal.py, ogr.py, gdalconst.py, gdalnumeric.py). If you installed GDAL properly in step 2, you should see C:\Program Files\GDAL\Python directory.

        Anyway, if you installed GDAL in a different location, please check it. Run a search in your system for gdal.py, or ogr.py. The directory containing these files is the directory that should be pointed by PYTHONPATH.

        As a quick test, execute the python console and simply write this:

        import osgeo

        What do you see? An error message? nothing?

  25. vkm2 permalink
    July 19, 2011 6:14 pm

    Jorge,

    I installed GDAL from your link ‘generic installed for gdal core components’ which was gdal-18-1310-core.msi
    This installer installed GDAL under C:\Program Files (x86)\GDAL
    But it did not install a python folder under the above.

    And ‘import osgeo’ in a Python installer gives me an error like ‘…import error: no module named osgeo’

    Also, i searched for gdal.py and ogr.py on my machine- i found them under a different application on my machine (QGIS) under gdal-17 (which i guess is not what we want anyway for this exercise).

    Last, in your additional notes you refer to
    “C:\Program Files\PostgreSQL\8.4\bin\libgdal.dll: Installed with PostGIS Windows experimental binaries, in step 4. Used by raster2pgsql.py script, to load raster data into PostgreSQL”
    In my case, I have
    C:\Program Files (x86)\PostgreSQL\9.0\bin\libgdal-1.dll

    I’m wondering if maybe i also have to install one of the other gdal?, namely
    GDAL-1.8.0.win32-py2.7.msi from the other link in step 2 i.e
    http://vbkto.dyndns.org/sdk/PackageList.aspx?file=release-1310-gdal-1-8-mapserver-5-6.zip

    I have tried to follow the June 13th conversations but am still confused. Do i need to install BOTH gdal-18-1310-core.msi as well as GDAL-1.8.0.win32-py2.7.msi

    or just one of these?

    thanks again,
    V

  26. vkm2 permalink
    July 22, 2011 12:45 am

    And THANKS for your help!
    Vishal

  27. July 22, 2011 11:23 am

    Hi,

    Glad to see things working :-). And to help you, of course. I’ll carefully read your blog post and try to answer your questions. It’s nice to have the user’s feedback.

    Just a comment. Your blog has a spanish name. Are you a spanish spoker?

    • vkm2 permalink
      July 22, 2011 8:44 pm

      Jorge, i speak some spanish, but am not a native speaker. for example i cant do technical spanish:) i am originally from India, live in Davis, California right now.
      I am developing some geospatial information tools and would like to connect a bit more with the community. we are a non-profit research group and dont have in-house web-programming skills to develop the kinds of application i would like to. Still, I have some good experiences with GRASS-R-PHP -Postgis that I would like to take further…perhaps with interns or in some collaborative fashion…
      cheers,
      Vishal

  28. K-gis permalink
    July 25, 2011 12:25 am

    Hi Jorge,
    I was trying to do what you wrote regarding Postgis raster on Win, but I stacked somewhere…pls can you help me to solve this:
    I downloaded postgis-pg84-binaries-2.0.0svn.zip and extracted on C, than I made all this changed in makepostgisdb.bat, and when run it as admin I got following massage in cmd:

    C:\Windows\system32>”C:\Program Files (x86)\PostgreSQL\9.0\bin\psql” -d “template_postgis20″ -f “share\contrib\postgis-2.0\postgis.sql”
    share/contrib/postgis-2.0/postgis.sql: No such file or directory

    Where I made mistake?
    FYI, I Have Win 7 Pro, x64, postgresql 9.0 (x86)

    Thak you in advance,
    Kemal

    • July 28, 2011 11:22 am

      Hello,

      I don’t see any obvious mistake. Try to directly execute that line from console:

      C:\Program Files (x86)\PostgreSQL\9.0\bin\psql -d template_postgis20 -f share\contrib\postgis-2.0\postgis.sql

      You may want to include the complete path to postgis.sql before.

      Anyway, you can manually execute all the commands included in the BAT file. Could you try it?

  29. July 27, 2011 11:58 am

    Hello
    i’m installing gdal 1.8 and python 1.6 but when i commande in python console
    from osgeo import gdal i’s not working error of module !

    Thanks

    • July 28, 2011 10:43 am

      Hello,

      Which error are you getting from Python console? The exact text.

      Did you test with?

      import gdal

      instead of

      from osgeo import gdal

      • July 29, 2011 12:04 am

        Traceback (most recent call last):
        File “”, line 1, in
        import gdal
        ImportError: No module named gdal

  30. July 29, 2011 12:07 am

    Hello
    i installed
    Windows x86 MSI Installer (2.6.6) (sig)
    numpy-1.6.1.win32-py2.6.exe
    gdal MSV 2003
    But This problem and Other question is what i wright in python console line, is that!

    python C:\Program Files\Postgresql\8.4\bin\raster2pgsql.py -r image.tif -t tablename -o image.sql
    SyntaxError: invalid syntax : C:\ is colored by red

    Thanks Jorge

    • July 29, 2011 1:07 am

      good now is work when i make from osgeo import gdal ( when i install GDAL-1.8.0.win32-py2.6.exe with gdalMSV …)
      But Now i work in python console and i have a image called torn.tiff in C : i write this in python console:

      python C:\Program Files\Postgresql\8.4\bin\raster2pgsql.py -r torno.tif -t tablename -o image.sql

      thers is error :
      SyntaxError: invalid syntax the caracter c is colored by red ( it’s accept pas C:)???????????????!!!!!!!
      All THANKS(sorry of english :)

      • July 30, 2011 12:04 pm

        Hi,

        Silly question, but did you enter the Python console or are you writing that directly in the command line (cmd.exe)?

        Follow these steps:

        1.- Start –> Run –> cmd.exe
        2.- From command like (NOT entering python console) write this (or the equivalent with your paths):

        python C:\Program Files\Postgresql\8.4\bin\raster2pgsql.py -r torno.tif -t tablename -o image.sql

        (You may get an error because python.exe is not part of the PATH enviroment variable. Add the path to python.exe to PATH in that case)

        And don’t worry, I’m not a native english spoker :-)

  31. July 30, 2011 5:42 pm

    Thank you for this information
    Then it’s back to the command (cmd.exe), after I set the directory python (python.exe) in the path:::
    C: \ Python26 to PATH and
    PYTHONPATH to C: \ Python26 \ Lib \ site-packages
    But there are some errors in syntax near surtoout C: Program Files???

  32. July 30, 2011 6:17 pm

    error : python cant’t open file ‘C:program’: No such file or directry

    • August 9, 2011 1:08 pm

      Hi, sorry for the delay

      Are you sure the complete path does exist? Could you paste the whole line that caused that error?

      • August 9, 2011 5:10 pm

        cant’t open file ‘C:program’: No such file or directry

      • August 9, 2011 5:13 pm

        I mean the line that caused that error message

  33. August 10, 2011 12:15 pm

    Currently, I stopped working on this but I will restart again. I think the history of the path that poses the problem
    I will work to solve even
    thank you

  34. Iyke permalink
    August 29, 2011 11:21 am

    Jorge,
    please i need your help on this,
    I followed your instructions and conversations on biding GDAL on python, still this refused to work.
    This is just a pain!
    I still receive this error:

    Traceback (most recent call last):
    File “”, line 1, in
    import gdal
    File “C:\Python27\lib\site-packages\gdal.py”, line 2, in
    from osgeo.gdal import deprecation_warn
    File “C:\Python27\lib\site-packages\osgeo\__init__.py”, line 21, in
    _gdal = swig_import_helper()
    File “C:\Python27\lib\site-packages\osgeo\__init__.py”, line 17, in swig_import_helper
    _mod = imp.load_module(‘_gdal’, fp, pathname, description)
    ImportError: DLL load failed: The specified module could not be found.

    I really need to install postgis 2.0 for my research work.

    • August 29, 2011 4:17 pm

      When did you receive that error? What did you execute? What was you trying to do? I need the whole context

      Looks like Windows is not detecting GDAL dll. What happens if you execute gdalinfo –formats from the command line (cmd.exe)? Any error message?

      • Iyke permalink
        August 29, 2011 4:37 pm

        Yeah Jorge just saw your response now, i had to uninstall and install again, then configured properly the system’s environment variables and it eventually worked on the importing gdal.

  35. Iyke permalink
    August 29, 2011 4:32 pm

    Now succeded in binding GDAL on python, but i dont think this PostGIS Windows experimental binaries is running properly becuase it was saying some file can not be found while i ran it.
    The template_postgis2.0 it created does not have a raster column.
    I did not see any file like libgdal.dll in the postgres bin folder
    I only saw 2 schemas the first one “public”
    contain one table “raster_overviews”
    and the second schema called “topology”

    Please Jorge, how can i get this postgis2.0 working in my machine.
    Does it has have both vector geometry functions as well as raster?

    Thanks in advance.

    • August 29, 2011 4:49 pm

      About your question: yes, PostGIS 2.0 have both, vector and raster functions.

      About your problem, I assume you followed my instructions. So, let’s see how all pieces work. First of all, which version of GDAL, Python, PostgreSQL and PostGIS are you using? I mean the concrete exe name tou used to install each program.

      Now, perform these tests:

      GDAL: execute gdalinfo –formats or gdalinfo –version in cmd. If there’re no errors, we can assume GDAL is properly installed (check version is 1.8.x)

      Python: from cmd, execute python interpreter (simply write python and hit ENTER). If you see the Python command line, we can assume Python is properly installed

      GDAL python bindings: from Python command line, write: import gdal. And hit ENTER. If you get an error “ImportError: No module named gdal”, the bindings are not installed.

      PostgreSQL + PostGIS 2.0: Execute a PostgreSQL client (pgAdmin or psql) and connect to your template_postgis20 database (and tell me how many tables this schema has, and their names). Then, execute this query:

      select postgis_full_version()

      And paste here the information you get.

      If any of these steps cause an error, paste it here, as detailed as possible.

  36. Iyke permalink
    August 29, 2011 5:06 pm

    Jorge,
    both gdalinfo-format or version and python are said not recognised as an internal or external operable programs or batch files.
    Could this be the problem?, but i called up python command line or the python GUI and typed ‘import gdal’ and it worked.
    Is really tiring!

  37. Iyke permalink
    August 29, 2011 5:22 pm

    Jorge,
    on the template_postgis20 database schema, i have only one table called raster_overviews
    and i did ran this query : select postgis_full_version()
    and it gave me this :
    ERROR: function postgis_full_version() does not exist
    LINE 1: select postgis_full_version()
    ^
    HINT: No function matches the given name and argument types. You might need to add explicit type casts.

    ********** Error **********

    ERROR: function postgis_full_version() does not exist
    SQL state: 42883
    Hint: No function matches the given name and argument types. You might need to add explicit type casts.
    Character: 8

  38. Iyke permalink
    August 29, 2011 5:39 pm

    Sorry I forgot to mention, i installed, numpy, Python 2.7, gdal-18-1310-core.msi as well as GDAL-1.8.0.win32-py2.7.msi, Postgres 9.0 and PostGIS Windows experimental binaries for 9.0.

  39. August 29, 2011 6:15 pm

    Lyke,

    You must add the GDAL installation path (C:\Program Files\GDAL, I guess) to your enviroment variable PATH. Check the PostgreSQL bin path (C:\Program Files\PostgreSQL\9.0\bin) is in PATH too.

    And about PostGIS, the error tells me your database has not been spatially enabled. Delete the database “template_postgis20″ and manually create it. Then, connect with it and execute, in order, the files:

    1.- postgis.sql
    2.- spatial_ref_sys.sql
    3.- rtpostgis.sql

    Thy should be in the directory created when you unzipped PostGIS Windows experimental binaries.

    After this, your template_postgis20 database should have the tables:

    - geometry_columns
    - spatial_ref_sys
    - raster_columns
    - raster_overviews

  40. Iyke permalink
    August 29, 2011 8:18 pm

    Jorge, thanks for this help, we really have to get this working on my system.

    I have added the directory paths for GDAL and PosgreSQL as you said.
    Deleted and Created manually the templete_postgis20 table
    then try to execute the first file postgis.sql on this table
    comes this error message:
    ERROR: could not access file “$libdir/postgis-2.0″: No such file or directory

    ********** Error **********

    ERROR: could not access file “$libdir/postgis-2.0″: No such file or directory
    SQL state: 58P01

  41. Iyke permalink
    August 29, 2011 8:53 pm

    Jorge,
    in which directory should i unzipp this folder, postgis-pg90-binaries-2.0.0svn
    becuase I discovered that when i run the ‘makepostgisdb’ file, nothing is copied from this postgis-pg90-binaries-2.0.0svn folder.
    Becuase it says File not found, 0 File copied.
    That means all the neccesary files that should be copied from that folder to postgres directory are not copied. Which are supposed to be copied in by this statements
    xcopy bin\*.* “%PGBIN%”
    xcopy /I /S bin\postgisgui\* “%PGBIN%\postgisgui”
    xcopy lib\*.* “%PGLIB%”

  42. August 29, 2011 9:08 pm

    Ok. So, the problem is your “PostGIS enviroment” hasn’t been set, and the DLL files are not found. Execute the BAT file from the command line, to see the output (not from the Windows explorer).

    Unzip the file wherever you want. The important thing is to execute the BAT file. Once unzipped, the files under ‘bin’ directory are copied to PGBIN, and ‘lib’ files are copied to PGLIB. Ensure these enviroment variables point to the right directories: the ‘bin’ and ‘lib’ directories of your PostgreSQL installation. Probably:

    - C:\Program Files\PostgreSQL\9.0\bin\
    - C:\Program Files\PostgreSQL\9.0\lib\

    And your welcome :-)

  43. Iyke permalink
    August 29, 2011 9:40 pm

    Jorge, please can you give me a little bit detail on this command line execution?.
    Because when i click Run as Administrator, it automatically executes it on the ‘black’ command line. Am really not too sure of what to do right now.

    • August 29, 2011 11:31 pm

      You need to run cmd.exe (the ‘black’ command line) in Administrator mode. So:

      - If you’re running Windows 2000/XP, open the file explorer and go to C:\Windows\System32. Locate cmd.exe, right click on it and select “Run as administrator”.

      - If you’re running Windows Vista/7, follow these instructions http://www.softwareok.com/?seite=faq-Win-7&faq=23

      Once a command line is opened, go to the directory where the bat file is located. So, if you unzipped the PostGIS binaries at C:\postgis-pg90-binaries-2.0.0svn, write in command line:

      cd C:\postgis-pg90-binaries-2.0.0svn

      Then, execute the bat file, writing in the command line:

      makepostgisdb.bat

      You will see the bat execution option. If there’s a problem, an error will be raised. I recommend you to make a screenshot of the command line and paste it here.

      • Iyke permalink
        August 30, 2011 12:39 am

        Jorge,
        i was trying to paste the screenshot here, but am not sure if images can be pasted here because it could not be pasted. If there another way i can send u the screen shot, please i will glad to do that immediately.
        There were errors everywhere that the files don’t exist.

  44. August 30, 2011 11:07 am

    Send me an e-mail to jorge.arevalo@deimos-space.com

    • Iyke permalink
      August 30, 2011 11:47 am

      Thanks Jorge,
      I have sent you an email.

  45. varma permalink
    September 2, 2011 8:24 am

    Thanks for the information, It really works fine.

  46. Wendi A permalink
    October 6, 2011 8:52 am

    Hai Jorge, thanks for the information.
    I have try this on my windows 7 but those steps do not give same result.
    There is no PostGIS Raster in my PostgreSQL tree (but you have , based on screenshot above).
    Can you give me advices about that? Please send me by email to wendiadriansaga@yahoo.com.
    Thank you.

    • October 6, 2011 10:18 am

      Hi Wendi,

      I’ve responded you in the postgis-users list.

      • Wendi A permalink
        October 7, 2011 5:32 am

        Hi Jorge,

        can you let me know how to install Mercator and PostGIS Raster which are displayed on screenshot of SHP2PGSQL GUI installed under pgAdmin III above?
        Because they are not appear on my PostgreSQL.
        Please advise. Thanks.

  47. October 7, 2011 10:14 am

    Hi Wendi,

    I’ve used the list to response you (because the wider audience) and I’ve updated the post again. Now, it should work.

    Best regards

  48. Deeepak permalink
    October 10, 2011 12:39 pm

    HI,
    I have followed all your step to install postresql in my machine having OS windows 7 home premium.As such I installed python 2.7, related numpy extension(i.e.numpy-1.5.1-win32-superpack-python2.7), GDAL core and binding( GDAL-1.8.0.win32-py2.7)as well. I create the environment for GDALtoo. After that I install PostgreSQL 9.1 and PostGIS 2.0. Up to this everything is ok. I can create a table with a data type raster as well as geometry. Now the Problem in loading *.tif file using raster2pgsql.py with command line. Error is as :

    Traceback (most recent call last):
    File “C:\Program Files\Postgresql\9.1\bin\raster2pgsql.py”, line 34, in
    from osgeo import gdal
    File “C:\Python27\lib\site-packages\osgeo\__init__.py”, line 21, in
    _gdal = swig_import_helper()
    File “C:\Python27\lib\site-packages\osgeo\__init__.py”, line 17, in swig_impor
    t_helper
    _mod = imp.load_module(‘_gdal’, fp, pathname, description)
    ImportError: DLL load failed: The specified module could not be found.

    C:\Python27>

    So here is the error in the first line of the file raster2pgsql.py while importing gdal.

    Can you please give me idea regarding this problem.

    Regards,
    Deepak

    • October 10, 2011 1:34 pm

      Hello,

      Your system can’t find the GDAL dll. It should be placed at C:\Program Files\PostgreSQL\9.1\bin\libgdal.dll

      Please check that file exists, and add C:\Program Files\PostgreSQL\9.1\bin to your system path (PATH enviroment var). Then check raster2pgsql again.

      • Deepak permalink
        October 10, 2011 9:49 pm

        Hello jorgearevalo,
        Thanks for your reply.
        In the place C:\Program Files\PostgreSQL\9.1\bin\ there is libgdal-1.dll instead of libgdal.dll. However I set the system path for C:\Program Files\PostgreSQL\9.1\bin and still not working. Shall I have to change libgdal-1.dll to libgdal.dll or not?

        with best regards,
        Deepak

      • October 10, 2011 11:06 pm

        Hello,

        Yes, change the name to libgdal.dll and test again.

        Best regards,
        Jorge

  49. Deepak permalink
    October 10, 2011 11:31 pm

    Hi,
    Sorry, again same error it does not work even I changed the dll name. What can be the problem.

    best regards
    Deepak

    • Deepak permalink
      October 11, 2011 11:35 am

      Hi Jorge,
      Though I have install PostGIS 2.0, I think there was a problem in the installation of it thats why I am facing the problem mentioned above. Actually when I first run the makepostgisdb.bat it gave error even in copying file from Postgis unzipped folder to postgresql folder. Later I did first four step of makepostgisdb.bat file manually i.e. copied my self in the respective folder of postgresql. These are the following four steps

      xcopy bin\*.* “%PGBIN%”
      xcopy /I /S bin\postgisgui\* “%PGBIN%\postgisgui”
      xcopy /I plugins.d “%PGADMIN%\plugins.d”
      xcopy lib\*.* “%PGLIB%”

      And then I removed these four line and run the batch file with administrator and it runs with some error. When I connected the database with pgadmin I found only three table in postgis 2.0 templete and are:

      - spatial_ref_sys
      - raster_columns
      - raster_overviews

      where as geometry_column and geography_column appear in a views folder.

      So now I can create the raster and vector table using script by create command but facing problem in loading thats why my intuition is that there is problem in running the batch file.
      I though it might be security issue of windows 7 and even disable the firewall and antivirus and run the batch file from command prompt but still not working .

      Hope you can give me best solution.

      thanks

      best regards,
      Deepak

      • October 11, 2011 11:53 pm

        Mmm… not sure. I’m not a Windows user. Try starting a Python console and simply importing gdal module:

        from osgeo import gdal;

        Are you getting the same error?

  50. Dimitar permalink
    October 12, 2011 12:05 am

    Maybe there are some changes in the latest Postgis 2.0.0 binaries, because it worked before, but now I’m getting the same error. I tried this with Postges 8.4 and 9.0, Python 2.6.6 and 2.7.1. No change. I’m getting the same error from Python console.

    • October 12, 2011 12:15 am

      Are you getting the GDAL error too?

      • Dimitar permalink
        October 12, 2011 12:18 am

        Yes, the same error like Deepak discribed it.

      • October 12, 2011 12:57 pm

        Try the same solution I’ve proposed to him: open a Python console and load the gdal module, if possible:

        from osgeo import gdal

      • Dimitar permalink
        October 13, 2011 9:17 am

        Hi Jorge,

        Earlier there was an error when I executed from osgeo import gdal from Python conlsole. I forgot to set C:\Program Files (x86)\GDAL\ to my PATH environment variable (I’m on 64 bit Windows 7). Now it works. Thanks!

        Regards,
        Dimitar

  51. Deepak permalink
    October 12, 2011 3:16 pm

    Hi Jorge,
    Yes earlier there was error on running the from osgeo import gdal . Then I again install binding and set again path variable now I can load raster via raster2pgsql.py loader.

    But I would like share the problem in running makepostgisdb.bat file in windows .As mentioned in my earlier post while running batch file it still unable to copy the files from postgis bin, lib etc to postgresql bin , lib etc. I did manually these things and run the batch file by removing these lines.
    Yes I able to run now the batch but it runs with error and finally I obtained three table in templete_postgis20 folder as
    - spatial_ref_sys
    - raster_columns
    - raster_overviews

    where as geometry_column and geography_column appear in a views folder.

    Anyway,so far I have access some functions related to raster and they work well if I get error in some case of-course I remember you on that time. Thanks

    Another things I would like to know about the source code for raster datatype especially “geomval” how it construct. Do you have idea about it if yes can you please provide me the link for it . Thanks a lot.

    Regards,
    deepak

  52. celati laurent permalink
    November 13, 2011 3:36 am

    Hello dear Jorge,

    -I have a error message when i try to generate this SQL file (command line C:\Program Files\Postgresql\9.0\bin\raster2pgsql.py -r image.tif -t tablename -o image.sql ) :

    python : can’t open file ‘C:\Program’: [Errno2] No such file or directory

    -However, when i try to load sql file in my data base via command line (psql -h localhost
    -U postgres -d template_postgis20 -f image.sql), all seems ok and i have not error message.

    .According to my configuration and installation is ok?
    .How to load a sql file via pgadmin 3?

    Could you throw light for me please?

    Have a good sunday?

    Laurent Celati.

    • November 14, 2011 1:33 pm

      Hello Laurent,

      You should add C:\Program Files\Postgresql\9.0\bin to your PATH enviroment variable. Other way, you could change to that directory in your command line:

      cd “C:\Program Files\Postgresql\9.0\bin”

      And then execute raster2pgsql without the path

      raster2pgsql.py -r /path/to/image.tif -t tablename -o image.sql

      But I’d chose the first option (add the path to PostgreSQL bin directory to PATH variable)

      To load a SQL file via pgAdmin III, you need to:
      1.- Open pgAdmin III and open a connection to your database
      2.- Click in the SQL button in the menu bar
      3.- In the new Window, choose “Open” and select your SQL file
      4.- Once the file is open, Click on the “play” button (or hit F5 in your keyboard). This will execute the sql file against your database, like psql does.

      Best regards,
      Jorge

      • November 15, 2011 11:09 pm

        Hello,

        Thank you for your reply. i have suceed in generating and loading sql file in my databse.

        What is the next step ? How import raster file (tiff for instance) in my databse? Sorry if my question seems idiotic but i’m a thematic geograph and i ‘ m starting out with data base and postgis…

        Thank you to throw light for me.

        Laurent Celati.

  53. laurent celati permalink
    November 15, 2011 1:52 pm

    Dear Jorge,

    Thank you for your reply. I have succed in generating sql file in my database. Is there a next step ? How import raster files (.tiff for instance) in my database now?

    i ‘m sorry if my question seems idiotic but i ‘m start out with data base.

    Thank to throw light for me.

    Laurent.

  54. November 16, 2011 1:34 am

    Dear Jorge,
    Thank you for your last reply. I have suceed in generating and loading sql file in my
    database.

    What is the next step ? How import raster file (tiff for instance) in my databse? Sorry
    if my question seems idiotic but i’m a thematic geograph and i ‘ m starting out with data
    base and postgis?

    Thank you to throw light for me.

    Laurent Celati.

    • November 16, 2011 1:25 pm

      Hello,

      If you’ve loaded the SQL file generated by raster2pgsql.py into your PostGIS Raster-activated database, you actually got it. The raster file you specified with ‘-r’ parameter is imported in your database.

      If you wanna see your data, check http://trac.osgeo.org/postgis/wiki/WKTRaster#DisplayingPostGISrasters

      Anyway, the PostGIS Raster visualization is related with the GDAL PostGIS Raster driver. You can use it (GDAL 1.8.0 or superior. Check http://trac.osgeo.org/gdal/wiki/frmts_wtkraster.html), but It’s under development. I’d love to devote more time to this task, and I’m actually working on it (until end of 2011, I couldn’t work on it harder). Stay tuned, because I’ll notifiy here when I finish a complete and stable version.

      And don’t worry about questions. I’m the first one with a looooooot of things to learn. I still consider myself as a ‘GIS n00b’ :-)

  55. Guillaume permalink
    November 29, 2011 5:58 pm

    Dear Jorge,

    Everything seems fine with my install after I followed your tutorial. My setup is:

    Windows 7 64-bit
    Python 3.2.2 (64-bit)
    PostgreSQL 9.0 (32-bit)
    GDAL 1.8.1 (64-bit)

    I can successfully import shapefiles into my DB and view them in QGIS. My problem is with the raster2pgsql.py function (I replaced the calls to “print” with “print()”, following python 3). When I run (with no line break):

    >python “C:\Program Files (x86)\PostgresPlus\9.0SS\bin\raster2pgsql.py” -r “E:\temp\p019r25_5t890906_nn4.tif” -t public.landsat -o “E:\temp\landsat.sql”

    I get this message:

    Traceback (most recent call last):
    File “C:\Program Files (x86)\PostgresPlus\9.0SS\bin\raster2pgsql.py”, line 104
    0, in
    main()
    File “C:\Program Files (x86)\PostgresPlus\9.0SS\bin\raster2pgsql.py”, line 100
    3, in main
    gt = wkblify_raster(opts, filename.replace( ‘\\’, ‘/’) , i, gt)
    File “C:\Program Files (x86)\PostgresPlus\9.0SS\bin\raster2pgsql.py”, line 945
    , in wkblify_raster
    summary = wkblify_raster_level(options, ds, options.overview_level, band_ran
    ge, infile, i)
    File “C:\Program Files (x86)\PostgresPlus\9.0SS\bin\raster2pgsql.py”, line 897
    , in wkblify_raster_level
    hexwkb += wkblify_raster_header(options, ds, level, (xoff, yoff))
    File “C:\Program Files (x86)\PostgresPlus\9.0SS\bin\raster2pgsql.py”, line 694
    , in wkblify_raster_header
    hexwkb += wkblify(‘B’, options.endian)
    TypeError: Can’t convert ‘bytes’ object to str implicitly

    Can this be due to the fact I’m using Windows 7 64-bit or is it something else I can’t think of?

    Thanks for helping me!

  56. Mark permalink
    December 16, 2013 4:57 pm

    Not so far I have found new cool tool to work with postgresql on win- Valentina Studio. Its free edition can do things more than many commercial tools!!
    I very recommend check it. http://www.valentina-db.com/en/valentina-studio-overview

Trackbacks

  1. Experiments with Postgis2.0 rasters « Vishal Mehta’s weblog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: