3

I am having some trouble with the raster2pgsql function (on a Windows 7 in the OSGeo4W shell). I am receiving the error "Unable to read raster file". I can import shapefiles, ok using org2org so I know that the connection works, it just does not work for the raster2pgsql function.

To retrace my steps, I first changed the directory from m:/> to the folder containing my raster:

cd M:\Users\userID\Documents\R\Koala_Proj\koala_data\koala_information_base\habitat_suitability

I then check the files within the directory using >dir to see what the raster is called. From this, I receive a list of the one raster in this folder and the affiliated files, such as: koala_raster.tif

I then try to use the raster2pgsql to import this raster to the above directory in postgresql:

raster2pgsql -s 4283 -I -C -t 100x100 koala_raster.tif public.khsm │
psql -h localhost -p 1234 -d koala -U postgres

I have also tried:

raster2pgsql -s 4283 -I -C -t 100x100 *.tif public.khsm │
psql -h localhost -p 1234 -d koala -U postgres

From these queries, I receive the error "Unable to read raster file".

However, rather than the file that this error refers bring named "koala_raster.tif" it prints "._koala_raster.tif". I am not sure what the "._" at the beginning of my raster refers to, or how to fix this problem I am having.

I have looked for fixes in

However, I still have not found a solution that fixes my problem.

  • 1
    Have you tried the full path to your raster? Or change directory to the folder the raster lives in? Does GDALInfo on your raster show meaningful values? – Michael Stimson Oct 29 at 7:11
  • I have tried the full path to the raster and in the above example I do just change to the folder the raster lived in: raster2pgsql -s 4283 -I -C -t 100x100 M:\Users\userID\Documents\R\Koala_Proj\koala_data\koala_information_base\habitat_suitability\koala_raster.tif public.khsm_northcoast │psql -h localhost -p 1234 -d krprivate19 -U postgres But the error changes to: "Unable to read raster file: M:\Users\userID\Documents\R\Koala_Proj\koala_data\koala_information_base\habitat_suitability\koala_raster.tif " GDALInfo koala_raster.tif works for me and displays info about the raster – CarlaBirdy Oct 29 at 7:23
  • I'm suggesting the full path may be too long; all software has limits on string length. If you were to move/copy or subst so that the path is a lot shorter it might work. Have you installed raster support for PostGIS? postgis.net/docs/RT_FAQ.html#idm29635 suggests more libs are required. – Michael Stimson Oct 29 at 7:49
  • That's a good point. Would that still be a problem when change directory to the folder the raster is in? I am sure raster2pgsql should work as I am using to on a shared server and other people have used it before with no issues. Do you think it could have anything to do with the capital first letter of the raster? – CarlaBirdy Oct 29 at 11:03
  • Capitals should have no bearing but if you're using a non UTF8 codepage there could be issues; I see no special characters in your string so I'd say that's not the case. Spaces and non-alphanumeric characters can be a problem but again I see none of those. So either your PostGIS isn't configured for rasters or for some reason your GeoTIFF can't be read by the utility... either the compression isn't understood or it's looking for a errata file that doesn't exist or can't be interpreted, to mitigate this problem try converting to GDAL HFA (ERDAS img) format before import. – Michael Stimson Oct 29 at 23:30
0

UPDATE: I found a solution. I set the directory to my raster location:

cd M:\Users\userID\Documents\R\Koala_Proj\koala_data\koala_information_base\habitat_suitability

What I ended up doing wrong was I set the -p as the password, not the port. Once I changed this, the import worked successfully:

M:\PostgreSQL\10\bin\raster2pgsql -s 4283 -I -C -t 100x100 koala_raster.tif | psql -h localhost -d krprivate19 -p 5432 -U postgres

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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