Skip to content

fix: link every OSM way that covers a 3D building - #204

Merged
jravani merged 1 commit into
mainfrom
fix/link-every-osm-way
Oct 19, 2026
Merged

jravani merged 1 commit into
mainfrom
fix/link-every-osm-way

Conversation

@jravani

@jravani jravani commented Oct 19, 2026

Copy link
Copy Markdown
Member

The link step kept one OSM way per 3D building (DISTINCT ON (b.object_id), UNIQUE (object_id, country_code)). Where OSM maps one building as several ways, the others got no building_link row although each cleared the 0.5 threshold, so a caller asking for them found no 3D data.

Closes #203

Change

  • sql/scripts/link/pylovo/01_build_pylovo_link.sql links every way with confidence ≥ 0.5, from res and oth. Ranking per 3D building: res before oth, confidence to two decimals (exact copies differ only by reprojection noise), larger overlap, osm_id. Rank 1 keeps match_type 1; every further way gets the new match_type 4 with the same object_id.
  • building_link is unique per (object_id, osm_id, country_code) and allows match_type 4. internal/process/link_table.go brings a table from an earlier release to that shape once per link run, under an advisory lock.
  • GetGridBatches excludes linked buildings with NOT EXISTS instead of a join, since a building can now have several rows.
  • GET /api/v1/buildings?osm_ids= returns each 3D building once, however many of its ways are asked for. osm_id stays the best way; the new osm_ids lists every linked way, best first, then by confidence. It is always present and [] in bbox mode.
  • Docs: docs/code/pylovo-link/index.md, the OpenAPI Building schema and getBuildings description, CHANGELOG.md.

Example, DEBY_LOD2_7595822: asking for 1265475272 returns that building once, with osm_id 223728275 and osm_ids [223728275, 1265475272, 1414567368, 1414567366, 1414567367].

Effect on existing data

Re-linking a copy of the German demo database (-link-pylovo -relink) adds 63 further-way rows on 49 buildings. No building's best way changes. 1,173 distinct OSM ways have 3D data afterwards, against 1,120 before. Existing databases need -link-pylovo -relink to fill in further ways for buildings that are already linked.

Tests

  • TestRunPyLovoLinkBuild_LinksEveryWayAboveThreshold: one 3D building with four ways of known confidence. It requires one primary, two further ways ordered by confidence, nothing for the way below 0.5, and the building returned once with all three ways whichever of them is asked for. On main it fails with a single link row.
  • TestRunPyLovoLinkBuild_UpdatesOldLinkTable: a table in the old shape is updated by the link step and then holds both ways of one building.
  • readBuildingLink in the existing link tests now reads a building's primary row, since a building can have more than one.

go vet ./..., go test -race ./... and the integration tests for process, db, importer, api and onrequest pass locally, onrequest against citydb-tool 1.3.2.

The link step kept one OSM way per 3D building (DISTINCT ON object_id,
UNIQUE (object_id, country_code)). Where OSM maps one building as
several ways, the others got no building_link row although each
cleared the 0.5 threshold, so a caller asking for them found no 3D
data. On the Mainkofen campus DEBY_LOD2_7595822 has five such ways and
only one was linked.

01_build_pylovo_link.sql now ranks every way at 0.5 or more per 3D
building: res before oth, then the confidence to two decimals (exact
copies differ only by reprojection noise), then the larger overlap,
then osm_id. The best way keeps match_type 1, every further way gets
the new match_type 4 with the same object_id. building_link is unique
per (object_id, osm_id, country_code). A table from an earlier release
is brought to that shape once per link run, under an advisory lock
because parallel runs would race on the DDL. The link batches use NOT
EXISTS instead of a join, since a building can now have several rows.

GET /api/v1/buildings?osm_ids= returns each 3D building once however
many of its ways are asked for, with osm_id as the best way and a new
osm_ids listing every linked way, best first, then by confidence. It
is [] in bbox mode.

Re-linking the German demo data adds 63 further ways on 49 buildings
and changes no building's best way.

Closes #203
@jravani jravani added this to the v0.11.2 milestone Oct 19, 2026
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.00000% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/process/link_table.go 65.21% 4 Missing and 4 partials ⚠️
internal/onrequest/query.go 90.47% 1 Missing and 1 partial ⚠️
internal/process/feature_extraction.go 66.66% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@jravani
jravani merged commit b4dc4b4 into main Oct 19, 2026
7 of 8 checks passed
@jravani
jravani deleted the fix/link-every-osm-way branch October 19, 2026 01:52
@jravani jravani mentioned this pull request Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Link every OSM way that covers a 3D building, not only the best match

1 participant