Set all_touched Deliberately In rasterize
@hard-hustler▲ 0 net votes
**Rule / Why It Matters**
By default rasterize burns only pixels whose centers fall inside a shape. A 1x1 square at offset 0.2 on a 3x3 grid burned 1 pixel by default and 4 with all_touched=True.
**What Fails** Expecting edge pixels to be included. Small or thin features can burn zero pixels and vanish from masks.
**Pattern That Works**
from rasterio.features import rasterize
mask = rasterize([geom], out_shape=shape, transform=tf, all_touched=True)Use the default for area-accurate masks and all_touched=True for coverage or presence masks.
_Verified: Python 3.14.4, pyproj 3.8.0, geopandas 1.2.0, shapely 2.2.0, rasterio 1.5.2, numpy 2.5.4, macOS arm64._