From b2f3788a202b93dc47b282f31ddcd3c6e721a49c Mon Sep 17 00:00:00 2001 From: Jay Ravani Date: Wed, 21 Oct 2026 19:30:35 +0200 Subject: [PATCH 1/2] fix: avoid division by zero for flat faces on PostgreSQL 18 surface_dimensions divides the face normal by h = sqrt(nx^2 + ny^2) to build its in-plane axes, and filters out near-horizontal faces with WHERE ABS(nz) <= 0.985. PostgreSQL 16 and 17 apply that filter first. PostgreSQL 18 computes the axes of a flat face (h = 0) anyway and raises division by zero, which fails script 03 for every batch that holds a flat roof or ground surface, so no building is extracted. h is now NULLIF(..., 0). Flat faces still get NULL in both extents and every other face is unchanged: a flat face gives (,) and a 2 x 3 m wall (2,3) on PostgreSQL 16.4, 17.0 and 18.6 alike. --- sql/functions/01_surface_area_corrected_geom.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/functions/01_surface_area_corrected_geom.sql b/sql/functions/01_surface_area_corrected_geom.sql index e6c0f6d..6ee3732 100644 --- a/sql/functions/01_surface_area_corrected_geom.sql +++ b/sql/functions/01_surface_area_corrected_geom.sql @@ -78,7 +78,9 @@ CREATE FUNCTION {city2tabula_schema}.surface_dimensions( WITH axes AS ( SELECT -ny / h AS ux, nx / h AS uy, -nz * nx / h AS vx, -nz * ny / h AS vy, h AS vz - FROM (SELECT sqrt(nx * nx + ny * ny) AS h) s + -- NULLIF because PostgreSQL 18 computes the axes of a flat face (h = 0) + -- before the WHERE below discards it, and raises division by zero. + FROM (SELECT NULLIF(sqrt(nx * nx + ny * ny), 0) AS h) s WHERE ABS(nz) <= 0.985 ), projected AS ( From b82923de070f0e94e83c6b2b7370b435570d1b79 Mon Sep 17 00:00:00 2001 From: Jay Ravani Date: Thu, 22 Oct 2026 17:57:28 +0200 Subject: [PATCH 2/2] docs: changelog entry for the PostgreSQL 18 extraction fix --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a5dc53..f421f6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,15 @@ Each release is listed with its breaking changes first. Releases before v0.8.0 are described in their tag messages. +## Unreleased + +Fixes: +- Feature extraction works on PostgreSQL 18. There every batch holding + a flat roof or ground surface failed with division by zero in + surface_dimensions, so no building was extracted. PostgreSQL 16 and + 17 were not affected. A database created by an earlier release gets + the fixed function on its next -reset-city2tabula. + ## v0.11.4 (2026-10-20) Features: