I'm trying to clip a raster using a polygon but I end up with a result that doesn't seem right and where some raster pixels are outside the polygon used for the clip.
See image below where polygon is the green outline and each pixels centroid is red:
I'm using the following SQL statement:
select st_union(st_clip(a.rast,b.geom, true)) from temp_jonyp2.dhm a, ( select wkb_geometry geom from i.gdk_bygning where id=347910 ) b where st_intersects(a.rast,b.geom)
I'm running PostgreSQL 9.6 and PostGIS 2.4.
Output of postgis_full_version is:
POSTGIS="2.4.0 r15853" PGSQL="96" GEOS="3.5.0-CAPI-1.9.0 r4084" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.11.4, released 2016/01/25" LIBXML="2.9.1" LIBJSON="0.11" RASTER
This question might relate to PostGIS polygon clip inaccurate using ST_Clip and ST_Union from tiled raster, but I can't figure out if the issue has been resolved for the version of PostGIS I'm running.
How do I clip a raster with a polygon so that only pixels inside the polygon are included?
UPDATE: From Vince's suggestion in the comments I tried with a negative buffer. This did shave of the pixels touching the polygon in the areas where the clip looks right, but didn't help with the "wrong" parts. See image: