Got an extra set of eyes looking at the code, and it identified a few bugs. I'll leave it here for now, until I find time to pick up the implementation.
Where: nlmod/dims/grid.py:2024 (dev), in gdf_to_grid.
Problem. The line branch reads:
if shp[geometry].geom_type == ["LineString", "MultiLineString"]:
This compares a geom_type string to a list, which is always False, so the per-cell length column is never attached for line features. The polygon branch just below (:2026-2027) correctly uses in:
if shp[geometry].geom_type in ["Polygon", "MultiPolygon"]:
Impact. Any consumer relying on the length column from gdf_to_grid silently gets a KeyError or a stale shapefile attribute. (The NHFLO 09pwnmodel2 script is unaffected because it computes geometry.length itself, which is how the bug went unnoticed.)
Suggested fix. Change the comparison to in ["LineString", "MultiLineString"].
Got an extra set of eyes looking at the code, and it identified a few bugs. I'll leave it here for now, until I find time to pick up the implementation.
Where:
nlmod/dims/grid.py:2024(dev), ingdf_to_grid.Problem. The line branch reads:
This compares a
geom_typestring to a list, which is alwaysFalse, so the per-celllengthcolumn is never attached for line features. The polygon branch just below (:2026-2027) correctly usesin:Impact. Any consumer relying on the
lengthcolumn fromgdf_to_gridsilently gets aKeyErroror a stale shapefile attribute. (The NHFLO 09pwnmodel2 script is unaffected because it computesgeometry.lengthitself, which is how the bug went unnoticed.)Suggested fix. Change the comparison to
in ["LineString", "MultiLineString"].