Skip to content

Cell rasterized despite not being covered by polygon #14615

@chau-intl

Description

@chau-intl

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:

Image

Both the lower vertices are exactly on the cell border with northing = 6114970.

Steps to reproduce the issue

Simple script to reproduce the issue:

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())

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

Metadata

Metadata

Assignees

Labels

not for AI loversSee https://gdal.org/en/stable/community/ai_tool_policy.html

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions