I have a simple polygon I am trying to rasterize and an extra cell is touched even though the polygon doesn't extend into it:
from osgeo import gdal, ogr, osr
polygon = ogr.CreateGeometryFromWkt('POLYGON ((872512 6114970, 872512 6114970.4, 872513.3 6114970.4, 872513.1 6114970, 872512 6114970))')
srs = osr.SpatialReference()
srs.ImportFromEPSG(25832)
raster_ds = gdal.GetDriverByName('MEM').Create('', 8, 5, 1, gdal.GDT_Byte)
raster_ds.SetGeoTransform((872511.2, 0.4, 0, 6114971.2, 0, -0.4))
raster_ds.SetProjection(srs.ExportToWkt())
vector_ds = ogr.GetDriverByName('MEM').CreateDataSource('')
layer = vector_ds.CreateLayer('polygon', srs, ogr.wkbPolygon)
feature = ogr.Feature(layer.GetLayerDefn())
feature.SetGeometry(polygon)
layer.CreateFeature(feature)
err = gdal.RasterizeLayer(raster_ds, [1], layer, burn_values=[1], options=['ALL_TOUCHED'])
print(raster_ds.ReadAsArray())
What is the bug?
I have a simple polygon I am trying to rasterize and an extra cell is touched even though the polygon doesn't extend into it:
Both the lower vertices are exactly on the cell border with
northing = 6114970.Steps to reproduce the issue
Simple script to reproduce the issue:
Versions and provenance
OS: Windows 11
Python: 3.12.13 (from the OSGeo4W installer)
GDAL: 3.13.0 (from the OSGeo4W installer)
Additional context
No response