hypercadaster-ES 1.4.2__tar.gz → 1.4.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hypercadaster_es-1.4.2/hypercadaster_es.egg-info → hypercadaster_es-1.4.4}/PKG-INFO +4 -3
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/README.md +3 -2
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/__init__.py +1 -1
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/_db.py +41 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/building_inference.py +144 -9
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/energy.py +932 -368
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/energy_config.yaml +43 -22
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/topology.py +104 -24
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/utils.py +764 -529
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4/hypercadaster_es.egg-info}/PKG-INFO +4 -3
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/setup.py +1 -1
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_db_layer.py +22 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_energy_scenarios.py +264 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_floorplan_partition.py +199 -3
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_shadow_rules.py +50 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_topology.py +64 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/LICENSE +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/MANIFEST.in +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/_pretty.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/cached_files/ine_inspire_codes.xlsx +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/downloaders.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/functions.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/interoperability.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/mergers.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/reporting.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/social.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_ES/weather.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_es.egg-info/SOURCES.txt +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_es.egg-info/dependency_links.txt +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_es.egg-info/requires.txt +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/hypercadaster_es.egg-info/top_level.txt +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/setup.cfg +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_aggregation.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_agricultural_archetype.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_cartociudad_api.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_cat_address.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_cat_cache.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_cat_empty_schema.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_census_tract_aggregations.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_code_normalisation.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_codes.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_dem_tiles.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_energy_config.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_geometry.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_import_surface.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_live_smoke.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_social.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_theoretical_cat_spaces.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_weather.py +0 -0
- {hypercadaster_es-1.4.2 → hypercadaster_es-1.4.4}/tests/test_zero_floor_buildings.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hypercadaster_es
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.4
|
|
4
4
|
Summary: Python library to obtain the Spanish cadaster data joined with external attributes.
|
|
5
5
|
Home-page: https://github.com/BeeGroup-cimne
|
|
6
6
|
Author: Jose Manuel Broto Vispe
|
|
@@ -107,7 +107,7 @@ A comprehensive Python library for downloading, processing, and analyzing Spanis
|
|
|
107
107
|
|
|
108
108
|
[](https://python.org)
|
|
109
109
|
[](https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12)
|
|
110
|
-
[](https://github.com/BeeGroup-cimne/hypercadaster_ES)
|
|
111
111
|
|
|
112
112
|
## 🎯 Overview
|
|
113
113
|
|
|
@@ -134,6 +134,7 @@ A comprehensive Python library for downloading, processing, and analyzing Spanis
|
|
|
134
134
|
### Library Reference
|
|
135
135
|
- [**Energy Model & Scenarios**](docs/energy-model.md) - How the EnergyPlus model is built, the occupant-behaviour model, and the scenarios
|
|
136
136
|
- [**Library Structure**](docs/library-structure.md) - Module overview and key entry points
|
|
137
|
+
- [**Visualisation**](docs/visualisation.md) - Every plot the library draws, with figures: maps, terrain, wall types, thermal zones, shadows, the 3-D views and the scenario report
|
|
137
138
|
- [**Data Sources & Coverage**](docs/data-sources-coverage.md) - Available datasets and geographic coverage
|
|
138
139
|
- [**Output Data Schema**](docs/output-schema.md) - Complete data structure and column reference
|
|
139
140
|
- **API Reference** - Generated from docstrings with [pdoc](https://pdoc.dev): run `./scripts/build_api_docs.sh` and open `docs/api/index.html`
|
|
@@ -234,4 +235,4 @@ This project is licensed under the **EUPL v1.2**. See the [license](https://join
|
|
|
234
235
|
|
|
235
236
|
*hypercadaster_ES - Built with ❤️ for the Spanish urban analysis and building research community*
|
|
236
237
|
|
|
237
|
-
*Last updated:
|
|
238
|
+
*Last updated: December 2026 | Version 1.4.4*
|
|
@@ -4,7 +4,7 @@ A comprehensive Python library for downloading, processing, and analyzing Spanis
|
|
|
4
4
|
|
|
5
5
|
[](https://python.org)
|
|
6
6
|
[](https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12)
|
|
7
|
-
[](https://github.com/BeeGroup-cimne/hypercadaster_ES)
|
|
8
8
|
|
|
9
9
|
## 🎯 Overview
|
|
10
10
|
|
|
@@ -31,6 +31,7 @@ A comprehensive Python library for downloading, processing, and analyzing Spanis
|
|
|
31
31
|
### Library Reference
|
|
32
32
|
- [**Energy Model & Scenarios**](docs/energy-model.md) - How the EnergyPlus model is built, the occupant-behaviour model, and the scenarios
|
|
33
33
|
- [**Library Structure**](docs/library-structure.md) - Module overview and key entry points
|
|
34
|
+
- [**Visualisation**](docs/visualisation.md) - Every plot the library draws, with figures: maps, terrain, wall types, thermal zones, shadows, the 3-D views and the scenario report
|
|
34
35
|
- [**Data Sources & Coverage**](docs/data-sources-coverage.md) - Available datasets and geographic coverage
|
|
35
36
|
- [**Output Data Schema**](docs/output-schema.md) - Complete data structure and column reference
|
|
36
37
|
- **API Reference** - Generated from docstrings with [pdoc](https://pdoc.dev): run `./scripts/build_api_docs.sh` and open `docs/api/index.html`
|
|
@@ -131,4 +132,4 @@ This project is licensed under the **EUPL v1.2**. See the [license](https://join
|
|
|
131
132
|
|
|
132
133
|
*hypercadaster_ES - Built with ❤️ for the Spanish urban analysis and building research community*
|
|
133
134
|
|
|
134
|
-
*Last updated:
|
|
135
|
+
*Last updated: December 2026 | Version 1.4.4*
|
|
@@ -26,7 +26,7 @@ from ._db import ResultsHandle
|
|
|
26
26
|
from . import (mergers, utils, building_inference, downloaders, interoperability,
|
|
27
27
|
energy, weather, social, topology, reporting)
|
|
28
28
|
|
|
29
|
-
__version__ = "1.4.
|
|
29
|
+
__version__ = "1.4.4"
|
|
30
30
|
__author__ = "Jose Manuel Broto Vispe"
|
|
31
31
|
__email__ = "jmbrotovispe@gmail.com"
|
|
32
32
|
|
|
@@ -421,6 +421,30 @@ def completed_zones(con: duckdb.DuckDBPyConnection, cadaster_code: str) -> set:
|
|
|
421
421
|
return {r[0] for r in rows}
|
|
422
422
|
|
|
423
423
|
|
|
424
|
+
def prune_stale_zone_status(con: duckdb.DuckDBPyConnection, cadaster_code: str) -> int:
|
|
425
|
+
"""Delete ``'ok'`` marks for zones of a municipality that have no
|
|
426
|
+
``br_results`` rows, so they are re-inferred and re-ingested instead of
|
|
427
|
+
skipped. Heals DBs where the result tables were wiped (pre-1.4.3
|
|
428
|
+
``force_update`` dropped them for every code) but ``zone_status`` kept its
|
|
429
|
+
marks. Returns the number of marks removed."""
|
|
430
|
+
if not _table_exists(con, "zone_status"):
|
|
431
|
+
return 0
|
|
432
|
+
if _table_exists(con, "br_results"):
|
|
433
|
+
stale_sql = (
|
|
434
|
+
"cadaster_code = ? AND state = 'ok' AND zone_reference NOT IN ("
|
|
435
|
+
' SELECT DISTINCT zone_reference FROM "main"."br_results"'
|
|
436
|
+
" WHERE cadaster_code = ?)"
|
|
437
|
+
)
|
|
438
|
+
params = [cadaster_code, cadaster_code]
|
|
439
|
+
else:
|
|
440
|
+
stale_sql = "cadaster_code = ? AND state = 'ok'"
|
|
441
|
+
params = [cadaster_code]
|
|
442
|
+
n = fetch_first(con, f"SELECT count(*) FROM zone_status WHERE {stale_sql}", params)[0]
|
|
443
|
+
if n:
|
|
444
|
+
con.execute(f"DELETE FROM zone_status WHERE {stale_sql}", params)
|
|
445
|
+
return int(n)
|
|
446
|
+
|
|
447
|
+
|
|
424
448
|
# ---------------------------------------------------------------------------
|
|
425
449
|
# (Geo)DataFrame ↔ DuckDB
|
|
426
450
|
# ---------------------------------------------------------------------------
|
|
@@ -517,11 +541,28 @@ def write_gdf(con: duckdb.DuckDBPyConnection, table: str, gdf: gpd.GeoDataFrame,
|
|
|
517
541
|
A column created from an all-None frame column gets DuckDB's "NULL"
|
|
518
542
|
type, which nothing can be cast into; once a frame carries a real type
|
|
519
543
|
for it, the table column is retyped to that type.
|
|
544
|
+
|
|
545
|
+
A table column already stored as pickled BLOB (e.g. ``br__detached``
|
|
546
|
+
in DBs written before nullable bools were kept BOOLEAN) can't receive
|
|
547
|
+
BOOLEAN / numeric values — DuckDB has no such cast — so the frame
|
|
548
|
+
column is pickled to match; `read_gdf` unpickles it either way.
|
|
520
549
|
"""
|
|
550
|
+
nonlocal df
|
|
521
551
|
existing = {r[0]: str(r[1])
|
|
522
552
|
for r in con.execute(f'DESCRIBE "{table}"').fetchall()}
|
|
523
553
|
tmp_types = {r[0]: str(r[1])
|
|
524
554
|
for r in con.execute('DESCRIBE _tmp_write_gdf').fetchall()}
|
|
555
|
+
to_blob = [c for c in df.columns
|
|
556
|
+
if c not in geom_set and existing.get(c) == "BLOB"
|
|
557
|
+
and tmp_types.get(c) not in ("BLOB", "VARCHAR")
|
|
558
|
+
and not _is_null_type(tmp_types.get(c, "NULL"))]
|
|
559
|
+
if to_blob:
|
|
560
|
+
df = df.assign(**{
|
|
561
|
+
c: [None if _is_null(v) else _to_pickle_bytes(v) for v in df[c]]
|
|
562
|
+
for c in to_blob})
|
|
563
|
+
con.unregister("_tmp_write_gdf")
|
|
564
|
+
con.register("_tmp_write_gdf", df)
|
|
565
|
+
tmp_types.update({c: "BLOB" for c in to_blob})
|
|
525
566
|
for c in df.columns:
|
|
526
567
|
_ty = 'GEOMETRY' if c in geom_set else tmp_types.get(c, 'VARCHAR')
|
|
527
568
|
if c not in existing:
|
|
@@ -135,6 +135,22 @@ def _floor_index_at_elevation(ground_elev, elev, ground_floor_height, floor_heig
|
|
|
135
135
|
return 1 + int((rel - ground_floor_height) // floor_height)
|
|
136
136
|
|
|
137
137
|
|
|
138
|
+
def _neighbour_footprint_behind(per_floor_fp, ground_elev, elev,
|
|
139
|
+
ground_floor_height, floor_height):
|
|
140
|
+
"""Footprint of the neighbour storey behind a wall at absolute elevation
|
|
141
|
+
``elev``, from the neighbour's ``{floor: footprint}`` and ground elevation;
|
|
142
|
+
None when the neighbour does not reach that height. Below the neighbour's
|
|
143
|
+
ground (a sloping street: it stands higher than us) the wall is backed by
|
|
144
|
+
its lowest storey and the ground under it, not by open air."""
|
|
145
|
+
if not per_floor_fp:
|
|
146
|
+
return None
|
|
147
|
+
fn = _floor_index_at_elevation(ground_elev, elev, ground_floor_height,
|
|
148
|
+
floor_height)
|
|
149
|
+
if fn < 0 and fn not in per_floor_fp:
|
|
150
|
+
fn = min(per_floor_fp)
|
|
151
|
+
return per_floor_fp.get(fn)
|
|
152
|
+
|
|
153
|
+
|
|
138
154
|
def _buffer_polygon_to_area(poly, target_area):
|
|
139
155
|
"""Buffer `poly` in or out until its area ≈ `target_area` (binary search on
|
|
140
156
|
the buffer distance; area grows monotonically with the distance). Used to
|
|
@@ -301,13 +317,23 @@ def _force_reset_code(results_dir, code, _db_mod):
|
|
|
301
317
|
pass
|
|
302
318
|
except Exception:
|
|
303
319
|
pass
|
|
320
|
+
# Delete only this code's rows: DROPping the tables wiped every
|
|
321
|
+
# other municipality's results while their zone_status stayed
|
|
322
|
+
# 'ok', so their next run skipped inference and returned nothing.
|
|
323
|
+
# Schema growth is handled by ingest_shard_table's ADD COLUMN.
|
|
304
324
|
for tbl in ("sbr_results", "br_results",
|
|
305
|
-
"aux_building_parts", "aux_footprints"
|
|
306
|
-
"_br_merged"):
|
|
325
|
+
"aux_building_parts", "aux_footprints"):
|
|
307
326
|
try:
|
|
308
|
-
con.execute(
|
|
327
|
+
con.execute(
|
|
328
|
+
f'DELETE FROM "main"."{tbl}" WHERE cadaster_code = ?',
|
|
329
|
+
[code],
|
|
330
|
+
)
|
|
309
331
|
except Exception:
|
|
310
|
-
pass
|
|
332
|
+
pass # table may not exist yet
|
|
333
|
+
try:
|
|
334
|
+
con.execute('DROP TABLE IF EXISTS "main"."_br_merged"')
|
|
335
|
+
except Exception:
|
|
336
|
+
pass
|
|
311
337
|
try:
|
|
312
338
|
con.execute(
|
|
313
339
|
"DELETE FROM zone_status WHERE cadaster_code = ?", [code]
|
|
@@ -361,6 +387,99 @@ def _effective_ground_floor_height(n_floors_above_ground, ground_floor_height,
|
|
|
361
387
|
return floor_height
|
|
362
388
|
|
|
363
389
|
|
|
390
|
+
def _building_floors_above_ground(parts):
|
|
391
|
+
"""Floors above ground of a building given its building-part rows: the TALLEST
|
|
392
|
+
part's count. The first row may be a one-storey annex, and reading it would
|
|
393
|
+
drop the building's 5 m ground floor to 3 m — burying its ground-floor
|
|
394
|
+
façades in the terrain-contact test. 0 when unknown."""
|
|
395
|
+
if 'n_floors_above_ground' not in parts.columns or len(parts) == 0:
|
|
396
|
+
return 0
|
|
397
|
+
n = pd.to_numeric(parts['n_floors_above_ground'], errors='coerce').max()
|
|
398
|
+
return 0 if pd.isna(n) else n
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def _facade_ground_elevation(parts, dem_sampler, geometry_column="building_part_geometry",
|
|
402
|
+
step=1.0, shared_tol=0.5, close=0.25, chunk=1_000_000):
|
|
403
|
+
"""Ground elevation of each building as the LOWEST terrain along its façades.
|
|
404
|
+
|
|
405
|
+
The street-level storey is floor 0, and on a slope the street that floor opens
|
|
406
|
+
onto is the low side; the walls standing in higher ground are the buried ones.
|
|
407
|
+
The DEM sampled at a part's centroid says neither — and on a coarse DEM it
|
|
408
|
+
differs between the parts of one building by metres, so the building's floor
|
|
409
|
+
heights depended on which part came first.
|
|
410
|
+
|
|
411
|
+
A building here is a connected group of one reference's parts (parts closer
|
|
412
|
+
than ``2·close`` join). Its exterior ring is sampled every ``step`` metres with
|
|
413
|
+
the same bilinear ``dem_sampler`` as the terrain-contact test, leaving out the
|
|
414
|
+
stretches within ``shared_tol`` of another building (party walls are not
|
|
415
|
+
façades); a building with no free stretch uses its whole ring. Returns a
|
|
416
|
+
Series aligned with ``parts`` holding the elevation of the part's building —
|
|
417
|
+
the existing ``elevation`` where the DEM gives nothing.
|
|
418
|
+
"""
|
|
419
|
+
import shapely
|
|
420
|
+
if "elevation" in parts.columns:
|
|
421
|
+
out = pd.to_numeric(parts["elevation"], errors="coerce").astype(float)
|
|
422
|
+
else:
|
|
423
|
+
out = pd.Series(np.nan, index=parts.index, dtype=float)
|
|
424
|
+
if dem_sampler is None or parts.empty:
|
|
425
|
+
return out
|
|
426
|
+
geoms = gpd.GeoSeries(parts[geometry_column].values, index=parts.index)
|
|
427
|
+
ok = geoms.notna() & ~geoms.is_empty
|
|
428
|
+
if not ok.any():
|
|
429
|
+
return out
|
|
430
|
+
|
|
431
|
+
# Buildings: dissolve each reference's (slightly grown) parts, split into
|
|
432
|
+
# connected pieces, shrink back.
|
|
433
|
+
grown = gpd.GeoDataFrame({"building_reference": parts.loc[ok, "building_reference"].values},
|
|
434
|
+
geometry=shapely.buffer(geoms[ok].values, close))
|
|
435
|
+
comps = grown.dissolve("building_reference").reset_index()
|
|
436
|
+
comps = comps.set_geometry(comps.buffer(-close)).explode(index_parts=False)
|
|
437
|
+
comps = comps[~comps.is_empty & (comps.area > 0.5)].reset_index(drop=True)
|
|
438
|
+
if comps.empty:
|
|
439
|
+
return out
|
|
440
|
+
comp_polys = comps.geometry.values
|
|
441
|
+
tree = shapely.STRtree(comp_polys)
|
|
442
|
+
|
|
443
|
+
# Each part → the building holding its representative point (else the nearest).
|
|
444
|
+
rep = shapely.point_on_surface(geoms[ok].values)
|
|
445
|
+
part_comp = np.full(len(rep), -1)
|
|
446
|
+
pi, ci = tree.query(rep, predicate="within")
|
|
447
|
+
part_comp[pi] = ci
|
|
448
|
+
miss = np.flatnonzero(part_comp < 0)
|
|
449
|
+
if len(miss):
|
|
450
|
+
_p, _c = tree.query_nearest(rep[miss], return_distance=False)
|
|
451
|
+
part_comp[miss[_p]] = _c
|
|
452
|
+
|
|
453
|
+
# Sample every building's exterior ring.
|
|
454
|
+
rings = shapely.segmentize(shapely.get_exterior_ring(comp_polys), step)
|
|
455
|
+
pts, owner = shapely.get_coordinates(rings, return_index=True)
|
|
456
|
+
if len(pts) == 0:
|
|
457
|
+
return out
|
|
458
|
+
pp = shapely.points(pts)
|
|
459
|
+
qi, qc = tree.query(pp, predicate="dwithin", distance=shared_tol)
|
|
460
|
+
shared = np.zeros(len(pts), dtype=bool)
|
|
461
|
+
shared[qi[qc != owner[qi]]] = True
|
|
462
|
+
|
|
463
|
+
elev = np.full(len(pts), np.nan)
|
|
464
|
+
for s in range(0, len(pts), chunk):
|
|
465
|
+
try:
|
|
466
|
+
elev[s:s + chunk] = np.asarray(
|
|
467
|
+
dem_sampler(pts[s:s + chunk, 0], pts[s:s + chunk, 1]), dtype=float)
|
|
468
|
+
except Exception:
|
|
469
|
+
pass
|
|
470
|
+
df = pd.DataFrame({"comp": owner, "elev": elev, "free": ~shared}).dropna(subset=["elev"])
|
|
471
|
+
if df.empty:
|
|
472
|
+
return out
|
|
473
|
+
low_free = df[df["free"]].groupby("comp")["elev"].min()
|
|
474
|
+
low_all = df.groupby("comp")["elev"].min()
|
|
475
|
+
comp_elev = low_all.copy()
|
|
476
|
+
comp_elev.loc[low_free.index] = low_free
|
|
477
|
+
|
|
478
|
+
new = pd.Series(comp_elev.reindex(part_comp).values, index=geoms[ok].index)
|
|
479
|
+
out.loc[new.index] = new.where(new.notna(), out.loc[new.index])
|
|
480
|
+
return out
|
|
481
|
+
|
|
482
|
+
|
|
364
483
|
def _wall_buried_area_fraction(segment, dem_sampler, floor_base_elev, floor_top_elev):
|
|
365
484
|
"""Fraction of a wall segment's AREA (length × storey height) that sits below
|
|
366
485
|
the terrain surface. The DEM is sampled along the segment; at each sample the
|
|
@@ -830,6 +949,17 @@ def process_building_parts(code, building_part_gdf_, buildings_CAT, parcels_gdf,
|
|
|
830
949
|
gdf_parcels_global[["building_reference","nearby_parcels"]],
|
|
831
950
|
on="building_reference", how="left")
|
|
832
951
|
gdf_global = gdf_global.set_geometry("building_part_geometry")
|
|
952
|
+
# One ground elevation per building — its lowest façade ground —
|
|
953
|
+
# in place of each part's centroid sample, so the building, its
|
|
954
|
+
# neighbours and the footprints all stand on the same level.
|
|
955
|
+
if DEM_raster_dir is not None:
|
|
956
|
+
try:
|
|
957
|
+
gdf_global["elevation"] = _facade_ground_elevation(
|
|
958
|
+
gdf_global,
|
|
959
|
+
utils.make_dem_sampler(DEM_raster_dir, gdf_global.crs))
|
|
960
|
+
except Exception as _e:
|
|
961
|
+
sys.stderr.write(f"Façade ground elevation skipped ({_e}); "
|
|
962
|
+
f"keeping the centroid DEM samples\n")
|
|
833
963
|
_aux_write("aux_building_parts", gdf_global)
|
|
834
964
|
else:
|
|
835
965
|
gdf_global = _aux_read("aux_building_parts", "building_part_geometry")
|
|
@@ -892,6 +1022,12 @@ def process_building_parts(code, building_part_gdf_, buildings_CAT, parcels_gdf,
|
|
|
892
1022
|
from hypercadaster_ES import _db as _db_mod_pre
|
|
893
1023
|
_pre_con = _db_mod_pre.open_db(results_dir)
|
|
894
1024
|
try:
|
|
1025
|
+
n_stale = _db_mod_pre.prune_stale_zone_status(_pre_con, code)
|
|
1026
|
+
if n_stale:
|
|
1027
|
+
sys.stderr.write(
|
|
1028
|
+
f"Discarded {n_stale} 'ok' zone marks with no results in "
|
|
1029
|
+
f"the central DB; those zones will be re-inferred\n"
|
|
1030
|
+
)
|
|
895
1031
|
already_in_central = _db_mod_pre.completed_zones(_pre_con, code)
|
|
896
1032
|
finally:
|
|
897
1033
|
_pre_con.close()
|
|
@@ -1730,8 +1866,7 @@ def process_zone(gdf_zone, zone_reference, gdf_footprints_global, parcels_gdf, s
|
|
|
1730
1866
|
# industrial/agricultural buildings (the same rule as the EnergyPlus
|
|
1731
1867
|
# model); used for this building's shadow eye levels and wall-typing
|
|
1732
1868
|
# floor elevations.
|
|
1733
|
-
_n_ag_bld = (building_gdf_item
|
|
1734
|
-
if 'n_floors_above_ground' in building_gdf_item.columns else 0)
|
|
1869
|
+
_n_ag_bld = _building_floors_above_ground(building_gdf_item)
|
|
1735
1870
|
_bld_use = (building_gdf_item['building_use'].iloc[0]
|
|
1736
1871
|
if 'building_use' in building_gdf_item.columns
|
|
1737
1872
|
and len(building_gdf_item) else None)
|
|
@@ -2040,12 +2175,12 @@ def process_zone(gdf_zone, zone_reference, gdf_footprints_global, parcels_gdf, s
|
|
|
2040
2175
|
for adj_sbr, _per_floor_fp in adj_floor_footprints.items():
|
|
2041
2176
|
# Which neighbour floor (by its own ground
|
|
2042
2177
|
# elevation) spans our floor's mid-height?
|
|
2178
|
+
# Below its ground: its lowest floor.
|
|
2043
2179
|
_g_n = adj_ground_elev.get(
|
|
2044
2180
|
adj_sbr, current_building_elevation)
|
|
2045
|
-
|
|
2046
|
-
_g_n, _floor_mid_elev,
|
|
2181
|
+
_nb_fp = _neighbour_footprint_behind(
|
|
2182
|
+
_per_floor_fp, _g_n, _floor_mid_elev,
|
|
2047
2183
|
ground_floor_height, floor_height)
|
|
2048
|
-
_nb_fp = _per_floor_fp.get(_fn)
|
|
2049
2184
|
if _nb_fp is None:
|
|
2050
2185
|
# Neighbour has no floor at this height.
|
|
2051
2186
|
continue
|