[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    Re: [postgis-users] Merge rasters with multiple bands
From:       Alexander Rumanovsk <rumanovsk () gmail ! com>
Date:       2016-08-15 17:24:29
Message-ID: CA+c+B3r+CZU_PGMnDuZtozGq4RT5b9H-RO0tfgkfuOyKPNkscg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Made it after some effort.
Here is the final query, exporting to a .hex file:

COPY (
select encode(ST_AsPNG(r, ARRAY[1,2,3]), 'hex')
FROM (

WITH original AS (
SELECT 1 AS rid,
ST_AddBand(ST_AddBand(ST_AddBand(ST_MakeEmptyRaster(100,100,0,0,1),
1, '8BUI', 16, 999), 2, '8BUI', 46, 999), 3, '8BUI', 184, 999) AS rast
), --0,0,255
empty AS (
SELECT 1 AS rid,
ST_AddBand(ST_AddBand(ST_AddBand(ST_MakeEmptyRaster(256,256,0,0,1),
1, '8BUI', 0, 999), 2, '8BUI', 0, 999), 3, '8BUI', 0, 999) AS rast
)--255,255,0

select
ST_AddBand(
ST_MapAlgebra(original.rast,1,empty.rast,1,'([rast1.val] +
[rast2.val])','8BUI','UNION'),
ARRAY[ST_MapAlgebra(original.rast,2,empty.rast,2,'([rast1.val] +
[rast2.val])','8BUI','UNION'), ST_MapAlgebra(original.rast,
3,empty.rast,3,'([rast1.val] + [rast2.val])','8BUI','UNION')]
)
as r
FROM original,empty

) AS t
) TO '/tmp/test.hex';

after that, I just run:
xxd -p -r test.hex > test.png

And voil=C3=A0.

--Rumanovsk

On Mon, Aug 15, 2016 at 1:15 PM, Pierre Racine <Pierre.Racine@sbf.ulaval.ca=
>
wrote:

> ST_Union works on overlapping rasters as well but maybe you have to
> provide two 3 bands rasters. If your rasters are tiled, you also have to
> GROUP BY tiles having the same alignment:
>
> GROUP BY ST_UpperleftX(rast), ST_UpperleftY(rast)
>
> ST_MapAlgebra() should work also. The expression should be equal to the
> raster with values and the extenttype to the 256x256 pixel one. They shou=
lp
> overlap.
>
> Pierre
>
>
> > -----Original Message-----
> > From: postgis-users [mailto:postgis-users-bounces@lists.osgeo.org] On
> Behalf
> > Of Alexander Rumanovsk
> > Sent: Wednesday, August 10, 2016 12:40 PM
> > To: postgis-users@lists.osgeo.org
> > Subject: [postgis-users] Merge rasters with multiple bands
> >
> > Hello all,
> >
> > I'm trying to merge a raster with 3 bands to an empty raster. The empty
> raster is
> > created with the query bellow:
> >
> > ST_AddBand(ST_MakeEmptyRaster(256,256,0,0,1), '8BUI'::text,200)
> >
> >
> > This empty raster is larger than the filled one (which is 100x100). I
> just need to
> > create a raster of 256x256 with the original raster (100x100)
> information and
> > the rest filled with empty information.
> > My first idea was to use ST_Union, but found out it just merges tiles,
> instead of
> > rasters.
> > Anyone have an idea how can I do that?
> >
> > thanks in advance
> > Rumanovsk
> _______________________________________________
> postgis-users mailing list
> postgis-users@lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/postgis-users

[Attachment #5 (text/html)]

<div dir="ltr">Made it after some effort.<div>Here is the final query, exporting to a \
.hex file:</div><div><br></div><div><div style="font-size:12.8px">COPY (</div><div \
style="font-size:12.8px"><span style="white-space:pre-wrap">	</span>select \
encode(ST_AsPNG(r, ARRAY[1,2,3]), &#39;hex&#39;)</div><div \
style="font-size:12.8px"><span style="white-space:pre-wrap">	</span>FROM (</div><div \
style="font-size:12.8px"><br></div><div style="font-size:12.8px"><span \
style="white-space:pre-wrap">		</span>WITH original AS (</div><div \
style="font-size:12.8px"><span style="white-space:pre-wrap">			</span>SELECT 1 AS \
rid, ST_AddBand(ST_AddBand(ST_<wbr>AddBand(ST_MakeEmptyRaster(<wbr>100,100,0,0,1), 1, \
&#39;8BUI&#39;, 16, 999), 2, &#39;8BUI&#39;, 46, 999), 3, &#39;8BUI&#39;, 184, 999) \
AS rast</div><div style="font-size:12.8px"><span \
style="white-space:pre-wrap">		</span>), --0,0,255</div><div \
style="font-size:12.8px"><span style="white-space:pre-wrap">		</span>empty AS \
(</div><div style="font-size:12.8px"><span \
style="white-space:pre-wrap">			</span>SELECT 1 AS rid, \
ST_AddBand(ST_AddBand(ST_<wbr>AddBand(ST_MakeEmptyRaster(<wbr>256,256,0,0,1), 1, \
&#39;8BUI&#39;, 0, 999), 2, &#39;8BUI&#39;, 0, 999), 3, &#39;8BUI&#39;, 0, 999) AS \
rast</div><div style="font-size:12.8px"><span \
style="white-space:pre-wrap">		</span>)--255,255,0</div><div \
style="font-size:12.8px"><br></div><div style="font-size:12.8px"><span \
style="white-space:pre-wrap">		</span>select  </div><div \
style="font-size:12.8px"><span \
style="white-space:pre-wrap">		</span>ST_AddBand(</div><div \
style="font-size:12.8px"><span \
style="white-space:pre-wrap">			</span>ST_MapAlgebra(original.rast,1,<wbr>empty.rast,1,&#39;([rast1.val] \
+ [rast2.val])&#39;,&#39;8BUI&#39;,&#39;UNION&#39;),</div><div \
style="font-size:12.8px"><span \
style="white-space:pre-wrap">			</span>ARRAY[ST_MapAlgebra(original.<wbr>rast,2,empty.rast,2,&#39;([rast1.<wbr>val] \
+ [rast2.val])&#39;,&#39;8BUI&#39;,&#39;UNION&#39;), ST_MapAlgebra(original.rast, \
3,empty.rast,3,&#39;([rast1.val] + \
[rast2.val])&#39;,&#39;8BUI&#39;,&#39;UNION&#39;)]</div><div \
style="font-size:12.8px"><span style="white-space:pre-wrap">		</span>)</div><div \
style="font-size:12.8px"><span style="white-space:pre-wrap">		</span>as r</div><div \
style="font-size:12.8px"><span style="white-space:pre-wrap">		</span>FROM \
original,empty</div><div style="font-size:12.8px"><br></div><div \
style="font-size:12.8px"><span style="white-space:pre-wrap">	</span>) AS t</div><div \
style="font-size:12.8px">) TO &#39;/tmp/test.hex&#39;;</div></div><div \
style="font-size:12.8px"><br></div><div style="font-size:12.8px">after that, I just \
run:</div><div style=""><span style="font-size:12.8px">xxd -p -r test.hex &gt; \
test.png</span><br></div><div style=""><span \
style="font-size:12.8px"><br></span></div><div style=""><span \
style="font-size:12.8px">And voilĂ .</span></div><div style=""><span \
style="font-size:12.8px"><br></span></div><div style=""><span \
style="font-size:12.8px">--Rumanovsk</span></div></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 15, 2016 at 1:15 PM, \
Pierre Racine <span dir="ltr">&lt;<a href="mailto:Pierre.Racine@sbf.ulaval.ca" \
target="_blank">Pierre.Racine@sbf.ulaval.ca</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">ST_Union works on overlapping rasters as well but maybe you \
have to provide two 3 bands rasters. If your rasters are tiled, you also have to \
GROUP BY tiles having the same alignment:<br> <br>
GROUP BY ST_UpperleftX(rast), ST_UpperleftY(rast)<br>
<br>
ST_MapAlgebra() should work also. The expression should be equal to the raster with \
values and the extenttype to the 256x256 pixel one. They shoulp overlap.<br> <br>
Pierre<br>
<div><div class="h5"><br>
<br>
&gt; -----Original Message-----<br>
&gt; From: postgis-users [mailto:<a \
href="mailto:postgis-users-bounces@lists.osgeo.org">postgis-users-bounces@<wbr>lists.osgeo.org</a>] \
On Behalf<br> &gt; Of Alexander Rumanovsk<br>
&gt; Sent: Wednesday, August 10, 2016 12:40 PM<br>
&gt; To: <a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
 &gt; Subject: [postgis-users] Merge rasters with multiple bands<br>
&gt;<br>
&gt; Hello all,<br>
&gt;<br>
&gt; I&#39;m trying to merge a raster with 3 bands to an empty raster. The empty \
raster is<br> &gt; created with the query bellow:<br>
&gt;<br>
&gt; ST_AddBand(ST_MakeEmptyRaster(<wbr>256,256,0,0,1), &#39;8BUI&#39;::text,200)<br>
&gt;<br>
&gt;<br>
&gt; This empty raster is larger than the filled one (which is 100x100). I just need \
to<br> &gt; create a raster of 256x256 with the original raster (100x100) information \
and<br> &gt; the rest filled with empty information.<br>
&gt; My first idea was to use ST_Union, but found out it just merges tiles, instead \
of<br> &gt; rasters.<br>
&gt; Anyone have an idea how can I do that?<br>
&gt;<br>
&gt; thanks in advance<br>
&gt; Rumanovsk<br>
</div></div>______________________________<wbr>_________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" \
target="_blank">http://lists.osgeo.org/<wbr>mailman/listinfo/postgis-users</a></blockquote></div><br></div>



[Attachment #6 (text/plain)]

_______________________________________________
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/postgis-users

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic