<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p> </p>
<div class="moz-text-html" lang="x-unicode">
<p>I have a 1 band raster, srid 4326, (0.001 x 0.001 roughly 100m
x 100m) , called <b>gbr100x100d</b>, whose pixels are coded 0
and 1 where 1 is water deeper than 100m and 0 water shallower
than 100m. <br>
</p>
<p>It was created as follows:<br>
</p>
<p><b><font face="monospace">create table gbr100x100d<br>
as<br>
SELECT row_number() over (order by 1) as rid,<br>
ST_SetSrid(ST_MapAlgebra(a.rast, 1, NULL,
'([rast.val]<-100.0)::integer'),4326) as rast<br>
from gbr100x100c as a;</font></b><br>
</p>
<p>First question: how can one recode <b>gbr100x100d </b>so that
all pixels with value 0 are NODATA?</p>
<p>Next. <br>
</p>
<p>Polygons of size 0.02x 0.01 need to be extracted from the 1
valued 0.001 pixels.<br>
</p>
<p>I think this should be done as follows.</p>
<p>First we resample to get a raster with cells of size 0.02 x
0.01:</p>
<p><font face="monospace"><b>create table gbr2kmx1kmd1</b><b><br>
</b><b>as</b><b><br>
</b><b>SELECT row_number() over (order by 1) as rid,</b><b><br>
</b><b>
ST_SetSrid(ST_Rescale(a.rast,0.02,-0.01,'Bilinear',0.125),4326)
as rast</b><b><br>
</b><b> from gbr100x100d as a;</b><b><br>
</b></font></p>
<p>Then we extract the polygons of these 0.02 x 0.01 pixels.<br>
</p>
<p><font face="monospace"><b>create table gbr2kmx1kmd1p</b><b><br>
</b><b>as </b><b><br>
</b><b>SELECT row_number() over (order by 1) as id, (gv).val,
ST_SnapToGrid((gv).geom,0.001)::geography as geog</b><b><br>
</b><b> FROM (SELECT ST_PixelAsPolygons(a.rast,1,true) as gv
</b><b><br>
</b><b> FROM gbr2kmx1kmd1 as a</b><b><br>
</b><b> ) gv</b><b><br>
</b><b> WHERE (gv).val = 1;</b><br>
</font></p>
<p>The result is close as the polygons are 0.02 x 0.01 but they
are organised as a set of striped polygons where the columns
don't touch. <br>
</p>
<p>See attached.</p>
<p>What was expected was a complete coverage of abutting polygons.
<br>
</p>
Can anyone spot what I am doing wrong?
<p>regards</p>
<p>Simon<br>
</p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"><legend
class="mimeAttachmentHeaderName">2021-03-17_10-27-06.png</legend></fieldset>
<div class="moz-attached-image-container"><img
class="moz-attached-image"
src="cid:part1.1DF14142.98C7B83C@spdba.com.au"></div>
</body>
</html>