[postgis-users] Adding raster to PostGIS database

218 views
Skip to first unread message

Smaran Harihar

unread,
Nov 26, 2012, 4:23:43 PM11/26/12
to PostGIS Users Discussion
Hi Guys,

I am trying to add a raster to PostGIS database using,

raster2pgsql -c -D -s 4326 -I Quercus_acutifolia_raw.tif public.Quercus_acutifolia_raw | psql -h localhost -d dbnm -U usr

But I am getting this error,

ERROR: Unable to read raster file: -D

Any idea what is wrong? The database already has numerous point and polygon shapefiles. Is that a problem that I cannot add rasters to the same database having shapefiles?

--
Thanks & Regards
Smaran Harihar

Bborie Park

unread,
Nov 26, 2012, 4:27:00 PM11/26/12
to postgi...@lists.osgeo.org
-D is not a valid flag recognized by raster2pgsql. Remove the flag as
raster2pgsql is assuming that -D is a file.

-bborie
> _______________________________________________
> postgis-users mailing list
> postgi...@lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users
>

--
Bborie Park
Programmer
Center for Vectorborne Diseases
UC Davis
530-752-8380
bkp...@ucdavis.edu
_______________________________________________
postgis-users mailing list
postgi...@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

Smaran Harihar

unread,
Nov 26, 2012, 4:37:43 PM11/26/12
to PostGIS Users Discussion
Thanks for the reply bborie,

I ran this command,

raster2pgsql -c -s 4326 -I Quercus_acutifolia_raw.tif public.Quercus_acutifolia_raw | psql -h localhost -d rasterdb -U postgres

But this is the new error,

ERROR: Unable to read raster file: Quercus_acutifolia_raw.tif

Thanks,
Smaran

Bborie Park

unread,
Nov 26, 2012, 4:46:50 PM11/26/12
to postgi...@lists.osgeo.org
That error would only happen if raster2pgsql can't find the file in your
current working directory. raster2pgsql supports relative paths for
input rasters.

-bborie

Smaran Harihar

unread,
Nov 26, 2012, 5:03:54 PM11/26/12
to PostGIS Users Discussion
But I am executing the command in the directory where it is located

I can list that raster using `ls`

Bborie Park

unread,
Nov 26, 2012, 5:07:57 PM11/26/12
to postgi...@lists.osgeo.org
Run the following...

gdalinfo Quercus_acutifolia_raw.tif

If that returns an error, something may be wrong with the tif file.

-bborie

Smaran Harihar

unread,
Nov 26, 2012, 5:30:17 PM11/26/12
to PostGIS Users Discussion
Hmmm.

This was the output,

gdalinfo failed - unable to open 'Quercus_acutifolia_raw.tif'.

For 

gdalinfo Quercus_acutifolia_raw.tif

Thanks,
Smaran

Smaran Harihar

unread,
Nov 26, 2012, 11:40:25 PM11/26/12
to PostGIS Users Discussion
Oh it seems the error was due to ownership being in the name of another user.

Now I am able to get the gdalinfo,

Driver: GTiff/GeoTIFF
Files: Quercus_acutifolia_raw.tif
Size is 3864, 1583
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["unknown",
        SPHEROID["WGS84",6378137,298.257223563]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433]]
Origin = (-179.960724061474451,86.577964063072983)
Pixel Size = (0.093000000000000,-0.090400000000000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-179.9607241,  86.5779641) (179d57'38.61"W, 86d34'40.67"N)
Lower Left  (-179.9607241, -56.5252359) (179d57'38.61"W, 56d31'30.85"S)
Upper Right ( 179.3912759,  86.5779641) (179d23'28.59"E, 86d34'40.67"N)
Lower Right ( 179.3912759, -56.5252359) (179d23'28.59"E, 56d31'30.85"S)
Center      (  -0.2847241,  15.0263641) (  0d17' 5.01"W, 15d 1'34.91"N)
Band 1 Block=3864x1 Type=Float32, ColorInterp=Gray
  Min=0.000 Max=0.923 
  Minimum=0.000, Maximum=0.923, Mean=0.000, StdDev=0.000
  NoData Value=-3.39999999999999996e+38
  Metadata:
    STATISTICS_MAXIMUM=0.92262234256096
    STATISTICS_MEAN=0
    STATISTICS_MINIMUM=5.6834812171638e-19
    STATISTICS_STDDEV=0

But when I execute,

raster2pgsql -c -s 4326 -I Quercus_acutifolia_raw.tif public.Quercus_acutifolia_raw | psql -h localhost -d dbname -U usr

I am still not able to create a Table? This is the output,

Processing 1/1: Quercus_acutifolia_raw.tif
Password for user postgres: 
BEGIN
NOTICE:  CREATE TABLE will create implicit sequence "quercus_acutifolia_raw_rid_seq" for serial column "quercus_acutifolia_raw.rid"
ERROR:  type "raster" does not exist
LINE 1: ...us_acutifolia_raw" ("rid" serial PRIMARY KEY,"rast" raster);
                                                               ^
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ERROR:  current transaction is aborted, commands ignored until end of transaction block
ROLLBACK

Thanks,
Smaran

Duncan Golicher

unread,
Nov 27, 2012, 1:33:28 AM11/27/12
to PostGIS Users Discussion
Hello Smaran,

My best guess is that you aren't using a database that has PostGIS
raster correctly installed. I have been trying to help some of my
students to install and use PostGIS raster from scratch recently and
they have had similar issues to yours and reported the same error
messages. Maybe this might help.

http://duncanjg.wordpress.com/2012/11/20/the-basics-of-postgis-raster/

It is all a bit confusing at first, but it does get easier once you
get past the first hurdles. Most problems are due to permission issues
and missing steps when installing the database.

All the best,

Duncan
Dr Duncan Golicher
Investigador Titular,
El Colegio de la Frontera Sur, Chiapas,Mexico
Mexico tel +52 1 967 137 94 20
Skype name duncangolicher

Publications: http://www.mendeley.com/profiles/duncan-golicher

Senior lecturer, Bournemouth University, UK
Centre for Conservation Ecology & Environmental Change
School of Applied Sciences
Christchurch House rm C218a
Bournemouth University
Fern Barrow
Poole (Dorset) BH12 5BB UK
Tel. +44 (0)1202 961682

For list of publications see Researcher ID:
http://www.researcherid.com/rid/B-4240-2009

dgol...@bournemouth.ac.uk
dgol...@ecosur.mx

Researcher ID:
http://www.researcherid.com/rid/B-4240-2009

José Pedro Santos

unread,
Nov 27, 2012, 3:13:49 AM11/27/12
to postgi...@lists.osgeo.org
Hi,

Try to see if you have Postgis correct installed. In the PGSQL console type: SELECT * FROM Postgis_lib_version();

If not is correct install try to do this in the terminal as postgresql SU:

1 - Find /usr -name 'rtpostgis.sql' (copy the path of this file)

2 - pgsql -d yourDBname -f thepreviouspath

3 - Try again to import the file

Best Regards
José Santos

From: smaran....@gmail.com
Date: Mon, 26 Nov 2012 21:40:25 -0700
To: postgi...@lists.osgeo.org
Subject: Re: [postgis-users] Adding raster to PostGIS database
Reply all
Reply to author
Forward
0 new messages