Describe the bug
Empty geometries produce NaN bounds, and rasterize() propagates those NaNs into the inferred output extent rather than rejecting them.
Two paths trigger this:
-
_geometry_bboxes() returns Shapely bounds as-is. Shapely returns (nan, nan, nan, nan) for empty geometries. The caller computes the inferred extent with plain .min()/.max() over the per-geometry bbox array, so a single empty geometry poisons all four bounds. The downstream check xmin < xmax does not catch NaN.
-
_parse_input() returns tuple(geometries.total_bounds) directly for any GeoDataFrame, including an empty one. GeoPandas returns NaN bounds for an empty frame. This bypasses the "bounds must be provided when geometries are empty" guard.
Reproducer:
from shapely.geometry import Polygon, box
from xrspatial import rasterize
empty = Polygon()
result = rasterize([(empty, 99), (box(0,0,1,1), 1)], width=2, height=2)
# Returns a (2, 2) raster with x = [nan, nan], y = [nan, nan]. Nothing is burned.
Expected behavior
Drop empty geometries from the inferred-bounds calculation. If the result is non-finite or there are no usable geometries, raise the existing "bounds must be provided" error.
Suggested fix
In _geometry_bboxes() filter NaN rows. In _parse_input(), return None for inferred_bounds when total_bounds contains NaN. Add a non-finite check before the existing xmin < xmax test in rasterize() so the failure mode is explicit.
Files: xrspatial/rasterize.py:1457, 1941, 2210-2225
Describe the bug
Empty geometries produce NaN bounds, and
rasterize()propagates those NaNs into the inferred output extent rather than rejecting them.Two paths trigger this:
_geometry_bboxes()returns Shapely bounds as-is. Shapely returns(nan, nan, nan, nan)for empty geometries. The caller computes the inferred extent with plain.min()/.max()over the per-geometry bbox array, so a single empty geometry poisons all four bounds. The downstream checkxmin < xmaxdoes not catch NaN._parse_input()returnstuple(geometries.total_bounds)directly for anyGeoDataFrame, including an empty one. GeoPandas returns NaN bounds for an empty frame. This bypasses the "bounds must be provided when geometries are empty" guard.Reproducer:
Expected behavior
Drop empty geometries from the inferred-bounds calculation. If the result is non-finite or there are no usable geometries, raise the existing "bounds must be provided" error.
Suggested fix
In
_geometry_bboxes()filter NaN rows. In_parse_input(), returnNoneforinferred_boundswhentotal_boundscontains NaN. Add a non-finite check before the existingxmin < xmaxtest inrasterize()so the failure mode is explicit.Files:
xrspatial/rasterize.py:1457,1941,2210-2225