<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="SV" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">I am working on a program that stores GIS data in a PostgreSQL database, the program is using NHibernate (C#, Npgsql and
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas">NpgsqlParameter bound to columns</span><span lang="EN-US">) to map database objects to entities in the program.</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#2B91AF"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">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: 
<a href="http://trac.osgeo.org/postgis/browser/trunk/raster/doc/RFC2-WellKnownBinaryFormat">
<span style="color:windowtext;text-decoration:none">http://trac.osgeo.org/postgis/browser/trunk/raster/doc/RFC2-WellKnownBinaryFormat</span></a>, (using raster2pgsql.exe and extracting the hex string from the generated SQL).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">And I can’t use the SQL from raster2pgsql.exe to insert/update the database directly I have to do it by a
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas">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.</span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The problem is with inserting/updating the raster column from this data.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The SQL used to update/set the raster column looks like this:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">UPDATE "GeoObject" SET "the_geom" = :p0, "the_raster" = :p1, "MetaId" = :p2, "SymbolId" = :p3 WHERE "ObjectId" = :p4<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">It works  to set the raster column from a hex string if I add a cast of the raster parameter like this:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">UPDATE "GeoObject" SET "the_geom" = :p0, "the_raster" = :p1::raster, "MetaId" = :p2, "SymbolId" = :p3 WHERE "ObjectId" = :p4<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">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”.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-US">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
</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas">ST_AsBinary</span><span lang="EN-US">)</span><span lang="EN-US" style="font-size:9.5pt;font-family:Consolas;color:#A31515"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Daniel Hedén<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Sweco Position, Falun Sweden<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
</body>
</html>