Skip to content

gdf_to_grid never attaches the 'length' column for line features (geom_type string compared to a list) #574

Description

@bdestombe

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"].

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions