[postgis-users] Additional pixels returned by ST_AsRaster

Jiří Fejfar jurafejfar at gmail.com
Thu Feb 4 11:39:48 PST 2021

 Hi all,

I am wondering why ST_AsRaster returns pixels (with NoData) which are
outside of bounding box of geometry being rasterized.

Self-contained demo code is here

drop view if exists v_rasterization;create view v_rasterization aswith
w_aoi as (    select st_setsrid(        ST_GeomFromText(
'POLYGON((-491000 -1146394,-491000  -1140708, -480724 -1140708,
-480724 -1146394, -491000 -1146394))')        , 5221) as aoi), w_rast
as (    select '1km' as dscr, aoi, st_asraster(aoi, 1000.0, 1000.0,
0.0, 0.0, '8BUI') as rast from w_aoi union all    select '5km' as
dscr, aoi, st_asraster(aoi, 5000.0, 5000.0, 0.0, 0.0, '8BUI') as rast
from w_aoi union all    select '10km' as dscr, aoi, st_asraster(aoi,
10000.0, 10000.0, 0.0, 0.0, '8BUI') as rast from w_aoi), w_out as (
select         dscr,         aoi,         rast,
st_convexhull(rast) as c_h_geom,         (ST_PixelAsPolygons(rast, 1,
false)).geom as pix_geom,         (ST_PixelAsPolygons(rast, 1,
true)).geom as pix_exclND_geom    from w_rast)select row_number()
over() as gid, dscr, aoi, rast, c_h_geom,     st_collect(pix_geom) as
pixs_geom,    st_collect(pix_exclND_geom) as pixs_exclN_geomfrom w_out
group by dscr, aoi, rast, c_h_geom;

and can be found also in [1]. It will create view showing geometry being
rasterizd (aoi), raster, convex hull of raster and vectorized raster using
two variants of ST_PixelAsPolygons (with and without NoData pixels).

Given by ConvexHull and two lower pixels in pixs_geom (image included in
[1]) it seems, that raster contains two pixels with NoData value, which
doesn't intersect with bounding box of vectorized polygon (dashed line).
How is determined extent of the raster? Is it described somewhere in docs?

Thank you, with best regards, Jiří Fejfar

[1] https://gitlab.com/-/snippets/2071456
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20210204/b54e2651/attachment.html>

More information about the postgis-users mailing list