[postgis-users] Convert/cast bytea to raster

Hedén Daniel Daniel.Heden at sweco.se
Wed Jun 26 02:40:13 PDT 2013


I am working on a program that stores GIS data in a PostgreSQL database, the program is using NHibernate (C#, Npgsql and NpgsqlParameter bound to columns) to map database objects to entities in the program.
My problem is with saving raster data to the database I convert the raster file to a byte array with the format of described in:  http://trac.osgeo.org/postgis/browser/trunk/raster/doc/RFC2-WellKnownBinaryFormat, (using raster2pgsql.exe and extracting the hex string from the generated SQL).
And I can't use the SQL from raster2pgsql.exe to insert/update the database directly I have to do it by a NpgsqlParameter in an INSERT or UPDATE statement because there are more tables that are updated in the same transaction and objects cached and many clients work against the same server.

The problem is with inserting/updating the raster column from this data.

The SQL used to update/set the raster column looks like this:
UPDATE "GeoObject" SET "the_geom" = :p0, "the_raster" = :p1, "MetaId" = :p2, "SymbolId" = :p3 WHERE "ObjectId" = :p4

It works  to set the raster column from a hex string if I add a cast of the raster parameter like this:
UPDATE "GeoObject" SET "the_geom" = :p0, "the_raster" = :p1::raster, "MetaId" = :p2, "SymbolId" = :p3 WHERE "ObjectId" = :p4

I can insert smaller raster files like this, but if the file is to big I get an OutOfMemoryException because it can't allocate a string big enough to hold the hex string.
And if I try to use a bytea parameter I can't convert that to raster and I get the error "cannot cast type bytea to raster".

Is there a way to insert raster data from the binary equivalence of the hex string raster2pgsql generates ? (A function that takes bytea and returns raster, a reverse of ST_AsBinary)


Daniel Hedén
Sweco Position, Falun Sweden

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20130626/373ddc7e/attachment.html>

More information about the postgis-users mailing list