[postgis-users] raster2postgis gives a faulty image in QGIS

cheryl buckley cheryl.bckl at gmail.com
Wed Feb 22 07:26:42 PST 2012


Hi all,

I am using raster2postgis to store my raster images into postgis database.
The raster images I created, using GDAL. A hillshaded image and an
Aspect image. They are both in tiff format. When I store the
hillshaded image using raster2pgsql to postgis database and then
connect via QGIS to view the hillshaded image to postgis it works
perfectly. But when i do the same for the Aspect image, the aspect
image comes out faulty and simply shows grid blocks in QGIS. When I
skip the storing in the database step using raster2pgsql and i just
open the the aspect file via using QGIS the file looks perfect. could
the mistake lie with my raster2postgis script, am i doing something
wrong? Below is my scripts.

Hillshade was created as follows:

        gdal_translate -of GTiff -co "TILED=YES" -a_srs
"+proj=latlong" ${IMAGE} ${IMAGE}_Translate.tif
        gdalwarp -of GTiff -co "TILED=YES" -srcnodata 32767 -t_srs
"epsg:900913" -rcs -order 3 -multi ${IMAGE}
	${IMAGE}_Warped.tif
        gdaldem hillshade ${IMAGE} ${IMAGE}_Hillshade.tif -z 10

Aspect was created as follows:

        gdal_translate -of GTiff -co "TILED=YES" -a_srs
"+proj=latlong" ${IMAGE} ${IMAGE}_Translate.tif
        gdalwarp -of GTiff -co "TILED=YES" -srcnodata 32767 -t_srs
"epsg:900913" -rcs -order 3 -multi ${IMAGE}
        ${IMAGE}_Warped.tif
        gdaldem aspect ${IMAGE} ${IMAGE}_Aspect.tif



Raster2pgsql script

SRC_FOLDER="/usr/local/www/blahblah"
DATABASE="my_spatial_db"
TABLE="layy" #do not call it raster

TYPE="raster"


# =================== Enable Raster Support =================== #

# Create The Table
echo "CREATE TABLE ${TABLE}(rid serial primary key, rast ${TYPE});" |
psql -h 127.0.0.1 -U pgsql "$DATABASE"

echo "CREATE INDEX myrasters_rast_st_convexhull_idx ON ${TABLE} USING
gist ( ST_ConvexHull(rast) );" | psql -h 127.0.0.1 -U pgsql
"$DATABASE"

 		# CREATE INDEX [indexname] ON [tablename] USING GIST ( [geometryfield] );
		# (Creates a GIST Index)


################################################


cd "${SRC_FOLDER}"

CREATE_GiST_INDEX="1"   # I'm a robot indicator (SOMETHING means GREEN
  and    NOTHING means RED)
                        # SOMETHING in this case would be the "1"
                        # The Var $CREATE_GiST_INDEX will become
NOTHING when it is unset
                        #
                        # It is needed to initialize the table where
we want to store the shape data in.

for FOLDER in `find ./ -depth "1" -type d`; do

    # Change current working directory
    cd "${FOLDER}"

    for IMAGE in *.tif; do
            printf "\n\n#========================== $IMAGE
==========================#\n\n"

            echo "$IMAGE"

            if ((CREATE_GiST_INDEX != 0)); then
                raster2pgsql -s 4236 -I -C "$IMAGE" -F -t 100x100
"${TABLE}" | psql --quiet -h 127.0.0.1 -U pgsql "$DATABASE"
                CREATE_GiST_INDEX=0
                printf "\n\n"
            fi

            time ( raster2pgsql -s 4236 -I -C "$IMAGE" -F -t 100x100
"$TABLE" | psql --quiet -h 127.0.0.1 -U pgsql "$DATABASE" )

            printf
"\n\n#============================================================#\n\n\n"
    done


cd "${SRC_FOLDER}"

done

thanks in advance
Greetings
Cheryl



More information about the postgis-users mailing list