8000 Streetscape never matches the first building in the frame (building id 0 is falsy) · Issue #776 · pysal/momepy · GitHub
[go: up one dir, main page]

Skip to content

Streetscape never matches the first building in the frame (building id 0 is falsy) #776

Open

Description

@thistlec

Streetscape never matches the first building in the buildings frame it is given, so every sightline that should stop at that building runs on to the next one (or to sightline_length and a gap).

Cause. In Streetscape.__init__ the buildings are numbered positionally:

buildings["street_index"] = np.arange(len(buildings))

and _compute_sigthlines_indicators then tests a match by truthiness:

match_sl_building_id = match_building_ids[sightline_pos]
...
if match_sl_building_id:

so building id 0 reads as "no building" (both the left and right branches). Present on main (lines 198, 698, 717 of momepy/streetscape.py as of 84fd2a7) and in 1.0.0.

Minimal example (momepy 1.0.0, geopandas 1.1.3, shapely 2.1.2, Python 3.12):

import geopandas as gpd, momepy
from shapely.geometry import LineString, box

streets = gpd.GeoDataFrame(geometry=[LineString([(0, 0), (60, 0)])])
blds = [box(0, 5, 30, 20), box(30, 8, 60, 20), box(0, -30, 60, -6)]
for label, geoms in [("as given", blds), ("dummy first", [box(1000, 1000, 1001, 1001)] + blds)]:
    b = gpd.GeoDataFrame({"height": [10.0] * len(geoms)}, geometry=geoms)
    pts = momepy.Streetscape(streets, b, height_col="height").point_level()
    print(label, list(zip(pts.geometry.x.round(1), pts["left_sb"].round(2))))

Output:

as given    [(0.5, nan), (3.6, nan), (6.7, nan), (9.8, nan), (12.9, nan), (16.0, nan), (19.1, nan), (22.2, nan), (25.3, nan), (28.4, nan), (31.6, 8.0), ..., (59.5, 8.0)]
dummy first [(0.5, 5.0), (3.6, 5.0), (6.7, 5.0), (9.8, 5.0), (12.9, 5.0), (16.0, 5.0), (19.1, 5.0), (22.2, 5.0), (25.3, 5.0), (28.4, 5.0), (31.6, 8.0), ..., (59.5, 8.0)]

The first building (box(0, 5, 30, 20), 5 m north of the street) is invisible: left_sb along x 0–30 is NaN instead of 5.0. Everything derived from the matches is affected for streets near that building (sb, os, h, hw, par_*, built_freq, the *_seq_sb_index lists).

Suggested fix. Test the match explicitly, e.g. if match_sl_building_id is not None: (the array is initialised with None), in both branches.

Workaround we use meanwhile: prepend a dummy building far outside every sightline's reach, with no height, so the real buildings are ids 1…n (and shift any lookup by those ids by one).

Activity

  1. martinfleis commented on Oct 13, 2026

    @martinfleis
    Member

    Thanks, will fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0