hypercadaster-ES 1.4.1__tar.gz → 1.4.2__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.
Files changed (50) hide show
  1. {hypercadaster_es-1.4.1/hypercadaster_es.egg-info → hypercadaster_es-1.4.2}/PKG-INFO +4 -4
  2. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/README.md +2 -2
  3. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/__init__.py +1 -1
  4. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/_db.py +6 -0
  5. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/energy.py +337 -62
  6. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/mergers.py +5 -0
  7. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2/hypercadaster_es.egg-info}/PKG-INFO +4 -4
  8. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_es.egg-info/requires.txt +1 -1
  9. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/setup.py +2 -2
  10. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/LICENSE +0 -0
  11. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/MANIFEST.in +0 -0
  12. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/_pretty.py +0 -0
  13. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/building_inference.py +0 -0
  14. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/cached_files/ine_inspire_codes.xlsx +0 -0
  15. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/downloaders.py +0 -0
  16. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/energy_config.yaml +0 -0
  17. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/functions.py +0 -0
  18. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/interoperability.py +0 -0
  19. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/reporting.py +0 -0
  20. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/social.py +0 -0
  21. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/topology.py +0 -0
  22. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/utils.py +0 -0
  23. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_ES/weather.py +0 -0
  24. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_es.egg-info/SOURCES.txt +0 -0
  25. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_es.egg-info/dependency_links.txt +0 -0
  26. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/hypercadaster_es.egg-info/top_level.txt +0 -0
  27. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/setup.cfg +0 -0
  28. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_aggregation.py +0 -0
  29. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_agricultural_archetype.py +0 -0
  30. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_cartociudad_api.py +0 -0
  31. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_cat_address.py +0 -0
  32. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_cat_cache.py +0 -0
  33. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_cat_empty_schema.py +0 -0
  34. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_census_tract_aggregations.py +0 -0
  35. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_code_normalisation.py +0 -0
  36. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_codes.py +0 -0
  37. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_db_layer.py +0 -0
  38. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_dem_tiles.py +0 -0
  39. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_energy_config.py +0 -0
  40. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_energy_scenarios.py +0 -0
  41. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_floorplan_partition.py +0 -0
  42. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_geometry.py +0 -0
  43. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_import_surface.py +0 -0
  44. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_live_smoke.py +0 -0
  45. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_shadow_rules.py +0 -0
  46. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_social.py +0 -0
  47. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_theoretical_cat_spaces.py +0 -0
  48. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_topology.py +0 -0
  49. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/tests/test_weather.py +0 -0
  50. {hypercadaster_es-1.4.1 → hypercadaster_es-1.4.2}/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.1
3
+ Version: 1.4.2
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
@@ -80,7 +80,7 @@ Requires-Dist: regex<2027.0,>=2023.12
80
80
  Requires-Dist: tqdm>=4.66
81
81
  Requires-Dist: six>=1.16
82
82
  Requires-Dist: PyYAML>=6.0
83
- Requires-Dist: social_ES>=1.0.3
83
+ Requires-Dist: social_ES>=1.0.4
84
84
  Provides-Extra: dev
85
85
  Requires-Dist: black>=24.0; extra == "dev"
86
86
  Requires-Dist: ruff>=0.4; extra == "dev"
@@ -107,7 +107,7 @@ A comprehensive Python library for downloading, processing, and analyzing Spanis
107
107
 
108
108
  [![Python Version](https://img.shields.io/badge/python-3.12+-blue.svg)](https://python.org)
109
109
  [![License](https://img.shields.io/badge/license-EUPL%20v1.2-blue.svg)](https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12)
110
- [![Version](https://img.shields.io/badge/version-1.4.1-green.svg)](https://github.com/BeeGroup-cimne/hypercadaster_ES)
110
+ [![Version](https://img.shields.io/badge/version-1.4.2-green.svg)](https://github.com/BeeGroup-cimne/hypercadaster_ES)
111
111
 
112
112
  ## 🎯 Overview
113
113
 
@@ -234,4 +234,4 @@ This project is licensed under the **EUPL v1.2**. See the [license](https://join
234
234
 
235
235
  *hypercadaster_ES - Built with ❤️ for the Spanish urban analysis and building research community*
236
236
 
237
- *Last updated: November 2026 | Version 1.4.1*
237
+ *Last updated: November 2026 | Version 1.4.2*
@@ -4,7 +4,7 @@ A comprehensive Python library for downloading, processing, and analyzing Spanis
4
4
 
5
5
  [![Python Version](https://img.shields.io/badge/python-3.12+-blue.svg)](https://python.org)
6
6
  [![License](https://img.shields.io/badge/license-EUPL%20v1.2-blue.svg)](https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12)
7
- [![Version](https://img.shields.io/badge/version-1.4.1-green.svg)](https://github.com/BeeGroup-cimne/hypercadaster_ES)
7
+ [![Version](https://img.shields.io/badge/version-1.4.2-green.svg)](https://github.com/BeeGroup-cimne/hypercadaster_ES)
8
8
 
9
9
  ## 🎯 Overview
10
10
 
@@ -131,4 +131,4 @@ This project is licensed under the **EUPL v1.2**. See the [license](https://join
131
131
 
132
132
  *hypercadaster_ES - Built with ❤️ for the Spanish urban analysis and building research community*
133
133
 
134
- *Last updated: November 2026 | Version 1.4.1*
134
+ *Last updated: November 2026 | Version 1.4.2*
@@ -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.1"
29
+ __version__ = "1.4.2"
30
30
  __author__ = "Jose Manuel Broto Vispe"
31
31
  __email__ = "jmbrotovispe@gmail.com"
32
32
 
@@ -446,6 +446,12 @@ def _df_with_wkb(gdf: gpd.GeoDataFrame, geom_cols: Iterable[str]) -> pd.DataFram
446
446
  for col in df.columns:
447
447
  if col in geom_set or df[col].dtype != object:
448
448
  continue
449
+ # A bool column with nulls (e.g. br__detached once the CAT undeveloped
450
+ # parcels are appended) turns object; keep it BOOLEAN, not a pickled
451
+ # BLOB, so it still matches a table created from an all-bool frame.
452
+ if pd.api.types.infer_dtype(df[col], skipna=True) == "boolean":
453
+ df[col] = df[col].astype("boolean")
454
+ continue
449
455
  if _object_kind(df[col]) in ("null", "str", "bytes"):
450
456
  continue
451
457
  df[col] = [None if _is_null(v) else _to_pickle_bytes(v) for v in df[col]]
@@ -227,10 +227,28 @@ def _default_idd_path():
227
227
  env = os.environ.get("HC_ENERGYPLUS_IDD")
228
228
  if env and os.path.exists(env):
229
229
  return env
230
- for p in ("/usr/local/EnergyPlus*/Energy+.idd", "/opt/EnergyPlus*/Energy+.idd"):
231
- hits = sorted(glob.glob(p))
232
- if hits:
233
- return hits[-1]
230
+ # The IDD must come from the engine that will run the IDF: eppy derives the
231
+ # executable path from the IDF Version, so a bundled-9.2 IDD sends it to a
232
+ # non-existent EnergyPlus-9-2-0 install. Prefer the engine on PATH.
233
+ import shutil
234
+ exe = shutil.which("energyplus")
235
+ if exe:
236
+ idd = os.path.join(os.path.dirname(os.path.realpath(exe)), "Energy+.idd")
237
+ if os.path.exists(idd):
238
+ return idd
239
+
240
+ def _version_key(path):
241
+ nums = re.findall(r"\d+", os.path.basename(os.path.dirname(path)))
242
+ return tuple(int(n) for n in nums)
243
+
244
+ hits = []
245
+ for p in ("/Applications/EnergyPlus*/Energy+.idd", # macOS
246
+ "/usr/local/EnergyPlus*/Energy+.idd", # Linux
247
+ "/opt/EnergyPlus*/Energy+.idd",
248
+ "C:/EnergyPlusV*/Energy+.idd"): # Windows
249
+ hits.extend(glob.glob(p))
250
+ if hits:
251
+ return max(hits, key=_version_key)
234
252
  import eppy
235
253
  idds = glob.glob(os.path.join(os.path.dirname(eppy.__file__),
236
254
  "resources", "iddfiles", "Energy+V9_2_0.idd"))
@@ -2905,6 +2923,9 @@ def build_energy_model(gdf, building_reference, wd=None, output_path=None,
2905
2923
  residential_behavior=residential_behavior,
2906
2924
  residential_period=residential_period,
2907
2925
  behavior_seed=behavior_seed, wd=wd)
2926
+ # Start the RunPeriod on the weather year's real weekday (blank means
2927
+ # Sunday), so a plain idf.run() keeps weekend schedules on the weekend.
2928
+ _set_run_period(idf, None)
2908
2929
 
2909
2930
  # Neighbour-shading filter + cap, BEFORE the model is written or returned, so
2910
2931
  # the .idf on disk, the 3-D plot and the simulated context are the same panels.
@@ -5350,7 +5371,8 @@ _IDF_VIEW_COLORS = {
5350
5371
  "Window": "cornflowerblue",
5351
5372
  "Door: main": "saddlebrown",
5352
5373
  "Door: parking": "sienna",
5353
- "Shading": "darkolivegreen",
5374
+ "Shading: building": "olivedrab",
5375
+ "Shading: neighbours": "darkolivegreen",
5354
5376
  }
5355
5377
 
5356
5378
 
@@ -5361,8 +5383,12 @@ def _surface_category(s):
5361
5383
  main/parking). Drives the per-category legend groups in ``plot_idf_geometry``
5362
5384
  so every type and subtype can be toggled independently."""
5363
5385
  st = getattr(s, "Surface_Type", None)
5364
- if st is None:
5365
- return "Shading" # Shading:*:Detailed has no type
5386
+ if st is None: # Shading:*:Detailed has no type
5387
+ # Neighbour (context) panels vs the building's own reveals, balconies,
5388
+ # awnings and footprint remainders.
5389
+ name = str(getattr(s, "Name", ""))
5390
+ return ("Shading: neighbours" if name.startswith(_NEIGHBOUR_SHADE_PREFIX)
5391
+ else "Shading: building")
5366
5392
  st = st.lower()
5367
5393
  bc = (getattr(s, "Outside_Boundary_Condition", "") or "").lower()
5368
5394
  if st == "wall":
@@ -5398,7 +5424,7 @@ def _idf_surfaces_by_category(idf, include_shading=True):
5398
5424
  out = OrderedDict()
5399
5425
  for s in vg._get_surfaces(idf):
5400
5426
  cat = _surface_category(s)
5401
- if cat == "Shading" and not include_shading:
5427
+ if cat.startswith("Shading") and not include_shading:
5402
5428
  continue
5403
5429
  coords = vg.getcoords(s)
5404
5430
  if coords and len(coords) >= 3:
@@ -5407,35 +5433,294 @@ def _idf_surfaces_by_category(idf, include_shading=True):
5407
5433
  return out
5408
5434
 
5409
5435
 
5436
+ # Standalone three.js page for plot_idf_geometry. three.js is loaded from the
5437
+ # jsDelivr CDN (pinned), so viewing the page needs an internet connection.
5438
+ _THREEJS_VERSION = "0.160.0"
5439
+ _IDF_VIEW_HTML = """<!doctype html>
5440
+ <html lang="en">
5441
+ <head>
5442
+ <meta charset="utf-8">
5443
+ <meta name="viewport" content="width=device-width, initial-scale=1">
5444
+ <title>__TITLE__</title>
5445
+ <style>
5446
+ html, body { margin: 0; height: 100%; overflow: hidden; background: #ffffff;
5447
+ font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; color: #222; }
5448
+ #view { position: absolute; inset: 0; }
5449
+ #panel { position: absolute; top: 10px; left: 10px; max-height: calc(100% - 20px); overflow: auto;
5450
+ background: rgba(255,255,255,0.92); border: 1px solid #ddd; border-radius: 6px;
5451
+ padding: 8px 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
5452
+ #panel h1 { font-size: 14px; margin: 0 0 6px; }
5453
+ #panel .hint { color: #777; font-size: 11px; margin-top: 6px; }
5454
+ .row { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; padding: 1px 0; }
5455
+ .sw { width: 14px; height: 14px; border: 1px solid rgba(0,0,0,0.35); border-radius: 2px; flex: none; }
5456
+ .row.off { opacity: 0.4; }
5457
+ #tip { position: absolute; pointer-events: none; display: none; background: rgba(30,30,30,0.85);
5458
+ color: #fff; padding: 3px 6px; border-radius: 3px; font-size: 12px; white-space: nowrap; }
5459
+ </style>
5460
+ </head>
5461
+ <body>
5462
+ <div id="view"></div>
5463
+ <div id="panel">
5464
+ <h1 id="ttl"></h1>
5465
+ <div id="legend"></div>
5466
+ <div class="hint">Drag: rotate · Right-drag: pan · Wheel: zoom<br>Click a category to toggle it<br>
5467
+ Grid cell: <span id="cell"></span> m</div>
5468
+ </div>
5469
+ <div id="tip"></div>
5470
+ <script type="application/json" id="hc-data">__DATA__</script>
5471
+ <script>
5472
+ // Surface load failures (no internet for the CDN, no WebGL) in the panel.
5473
+ function hcFail(msg) {
5474
+ const d = document.createElement("div");
5475
+ d.style.cssText = "color:#b00020;margin-top:6px;max-width:320px";
5476
+ d.textContent = "Viewer error: " + msg;
5477
+ document.getElementById("panel").appendChild(d);
5478
+ }
5479
+ window.addEventListener("error", (e) => hcFail(e.message || "could not load three.js (offline?)"), true);
5480
+ window.addEventListener("unhandledrejection", (e) => hcFail(String(e.reason)));
5481
+ </script>
5482
+ <script type="importmap">
5483
+ {"imports": {"three": "https://cdn.jsdelivr.net/npm/three@__V__/build/three.module.js",
5484
+ "three/addons/": "https://cdn.jsdelivr.net/npm/three@__V__/examples/jsm/"}}
5485
+ </script>
5486
+ <script type="module">
5487
+ import * as THREE from "three";
5488
+ import { OrbitControls } from "three/addons/controls/OrbitControls.js";
5489
+
5490
+ const DATA = JSON.parse(document.getElementById("hc-data").textContent);
5491
+ const ttl = document.getElementById("ttl");
5492
+ if (DATA.title) ttl.textContent = DATA.title; else ttl.remove();
5493
+
5494
+ const view = document.getElementById("view");
5495
+ const renderer = new THREE.WebGLRenderer({ antialias: true, preserveDrawingBuffer: true });
5496
+ renderer.setPixelRatio(window.devicePixelRatio);
5497
+ renderer.setSize(view.clientWidth, view.clientHeight);
5498
+ view.appendChild(renderer.domElement);
5499
+
5500
+ const scene = new THREE.Scene();
5501
+ scene.background = new THREE.Color(0xffffff);
5502
+ scene.add(new THREE.AmbientLight(0xffffff, 1.6));
5503
+ const sun = new THREE.DirectionalLight(0xffffff, 1.4);
5504
+ sun.position.set(1, -1.5, 2);
5505
+ scene.add(sun);
5506
+
5507
+ const box = new THREE.Box3(); // everything (sizes the grid)
5508
+ const focus = new THREE.Box3(); // the building itself (frames the camera)
5509
+ const meshes = [];
5510
+ const legend = document.getElementById("legend");
5511
+
5512
+ for (const cat of DATA.categories) {
5513
+ const group = new THREE.Group();
5514
+ // Filled faces: flat-shaded, double-sided, see-through like the plotly view.
5515
+ const g = new THREE.BufferGeometry();
5516
+ g.setAttribute("position", new THREE.Float32BufferAttribute(cat.positions, 3));
5517
+ g.setIndex(cat.indices);
5518
+ const flat = g.toNonIndexed();
5519
+ flat.computeVertexNormals();
5520
+ // Windows and doors lie in their wall's plane. Pulled towards the camera and
5521
+ // drawn FIRST with depth writes, so their own wall can't cover them, while
5522
+ // any roof or wall in front still blends over them and dims them.
5523
+ const inset = cat.name === "Window" || cat.name.startsWith("Door");
5524
+ const mat = new THREE.MeshLambertMaterial({
5525
+ color: new THREE.Color(cat.color), side: THREE.DoubleSide,
5526
+ transparent: cat.opacity < 1, opacity: cat.opacity, depthWrite: inset || cat.opacity >= 1,
5527
+ polygonOffset: true, polygonOffsetFactor: inset ? -2 : 1, polygonOffsetUnits: inset ? -4 : 1,
5528
+ });
5529
+ const mesh = new THREE.Mesh(flat, mat);
5530
+ // The roof is blended last, over everything it covers (walls, shading, the
5531
+ // windows and doors under it); the rest follows three.js' depth sorting.
5532
+ mesh.renderOrder = inset ? -1 : (cat.name === "Roof" ? 2 : 0);
5533
+ mesh.userData.name = cat.name;
5534
+ group.add(mesh);
5535
+ meshes.push(mesh);
5536
+ // Crisp polygon outlines.
5537
+ const eg = new THREE.BufferGeometry();
5538
+ eg.setAttribute("position", new THREE.Float32BufferAttribute(cat.edges, 3));
5539
+ group.add(new THREE.LineSegments(eg, new THREE.LineBasicMaterial({
5540
+ color: 0x282828, transparent: true, opacity: cat.edge_opacity })));
5541
+ scene.add(group);
5542
+ flat.computeBoundingBox();
5543
+ box.union(flat.boundingBox);
5544
+ if (!cat.context) focus.union(flat.boundingBox);
5545
+
5546
+ const row = document.createElement("div");
5547
+ row.className = "row";
5548
+ const sw = document.createElement("span");
5549
+ sw.className = "sw";
5550
+ sw.style.background = cat.color;
5551
+ const label = document.createElement("span");
5552
+ label.textContent = `${cat.name} (${cat.count})`;
5553
+ row.append(sw, label);
5554
+ row.addEventListener("click", () => {
5555
+ group.visible = !group.visible;
5556
+ row.classList.toggle("off", !group.visible);
5557
+ });
5558
+ legend.appendChild(row);
5559
+ }
5560
+
5561
+ // True 1:1:1 metre scale, z up. The camera frames the building; the ground
5562
+ // grid (at the model's lowest point) spans the neighbour shading too.
5563
+ if (focus.isEmpty()) focus.copy(box);
5564
+ const size = focus.getSize(new THREE.Vector3());
5565
+ const center = focus.getCenter(new THREE.Vector3());
5566
+ const span = Math.max(size.x, size.y, size.z, 1);
5567
+ const all = box.getSize(new THREE.Vector3());
5568
+ const allCenter = box.getCenter(new THREE.Vector3());
5569
+ const cell = Math.pow(10, Math.floor(Math.log10(Math.max(all.x, all.y, 1) / 2)));
5570
+ const cells = Math.ceil((Math.max(all.x, all.y) * 1.2) / cell / 2) * 2;
5571
+ const grid = new THREE.GridHelper(cells * cell, cells, 0xbbbbbb, 0xe3e3e3);
5572
+ grid.rotation.x = Math.PI / 2;
5573
+ grid.position.set(allCenter.x, allCenter.y, box.min.z);
5574
+ scene.add(grid);
5575
+ document.getElementById("cell").textContent = cell;
5576
+
5577
+ const camera = new THREE.PerspectiveCamera(40, view.clientWidth / view.clientHeight, span / 1000, Math.max(span, all.x, all.y) * 100);
5578
+ camera.up.set(0, 0, 1);
5579
+ const eye = new THREE.Vector3(1.5, -1.5, 1.0).normalize().multiplyScalar(span * 1.8);
5580
+ camera.position.copy(center).add(eye);
5581
+ const controls = new OrbitControls(camera, renderer.domElement);
5582
+ controls.target.copy(center);
5583
+ controls.enableDamping = true;
5584
+ controls.update();
5585
+
5586
+ // Hover: name of the surface category under the cursor.
5587
+ const tip = document.getElementById("tip");
5588
+ const ray = new THREE.Raycaster();
5589
+ const ndc = new THREE.Vector2();
5590
+ renderer.domElement.addEventListener("pointermove", (ev) => {
5591
+ const r = renderer.domElement.getBoundingClientRect();
5592
+ ndc.set(((ev.clientX - r.left) / r.width) * 2 - 1, -((ev.clientY - r.top) / r.height) * 2 + 1);
5593
+ ray.setFromCamera(ndc, camera);
5594
+ const hit = ray.intersectObjects(meshes.filter((m) => m.parent.visible), false)[0];
5595
+ if (hit) {
5596
+ tip.textContent = hit.object.userData.name;
5597
+ tip.style.left = `${ev.clientX + 12}px`;
5598
+ tip.style.top = `${ev.clientY + 12}px`;
5599
+ tip.style.display = "block";
5600
+ } else {
5601
+ tip.style.display = "none";
5602
+ }
5603
+ });
5604
+ renderer.domElement.addEventListener("pointerleave", () => { tip.style.display = "none"; });
5605
+
5606
+ window.addEventListener("resize", () => {
5607
+ camera.aspect = view.clientWidth / view.clientHeight;
5608
+ camera.updateProjectionMatrix();
5609
+ renderer.setSize(view.clientWidth, view.clientHeight);
5610
+ });
5611
+ renderer.setAnimationLoop(() => { controls.update(); renderer.render(scene, camera); });
5612
+ </script>
5613
+ </body>
5614
+ </html>
5615
+ """
5616
+
5617
+
5618
+ def _open_html_in_browser(page, timeout=120):
5619
+ """Open ``page`` in the web browser from a one-shot local HTTP server.
5620
+
5621
+ A ``file://`` URL is not enough: PyCharm's remote-dev ``BROWSER`` hook only
5622
+ forwards ``http(s)`` links to the client machine (as plotly's ``fig.show``
5623
+ does). The server answers the first request for the page, in a daemon
5624
+ thread, and gives up after ``timeout`` seconds."""
5625
+ import threading
5626
+ import time
5627
+ import webbrowser
5628
+ from http.server import BaseHTTPRequestHandler, HTTPServer
5629
+
5630
+ body = page.encode("utf-8")
5631
+ served = threading.Event()
5632
+
5633
+ class _Handler(BaseHTTPRequestHandler):
5634
+ def do_GET(self):
5635
+ if self.path.split("?")[0] != "/":
5636
+ self.send_response(404)
5637
+ self.end_headers()
5638
+ return
5639
+ self.send_response(200)
5640
+ self.send_header("Content-Type", "text/html; charset=utf-8")
5641
+ self.send_header("Content-Length", str(len(body)))
5642
+ self.end_headers()
5643
+ self.wfile.write(body)
5644
+ served.set()
5645
+
5646
+ def log_message(self, *args):
5647
+ pass
5648
+
5649
+ server = HTTPServer(("127.0.0.1", 0), _Handler)
5650
+ server.timeout = 1
5651
+
5652
+ def _serve():
5653
+ deadline = time.time() + timeout
5654
+ while not served.is_set() and time.time() < deadline:
5655
+ server.handle_request()
5656
+ server.server_close()
5657
+
5658
+ threading.Thread(target=_serve, daemon=True).start()
5659
+ webbrowser.open(f"http://127.0.0.1:{server.server_port}/")
5660
+
5661
+
5662
+ class IDFGeometryView:
5663
+ """The three.js page returned by :func:`plot_idf_geometry`.
5664
+
5665
+ ``html`` holds the standalone page and ``path`` the file it was saved to
5666
+ (or ``None``). ``show()`` opens it in the web browser; in Jupyter it renders
5667
+ inline. Its repr is one line, so the page isn't dumped into the console."""
5668
+
5669
+ def __init__(self, html, path=None):
5670
+ self.html = html
5671
+ self.path = path
5672
+
5673
+ def show(self):
5674
+ _open_html_in_browser(self.html)
5675
+
5676
+ def __repr__(self):
5677
+ where = f", saved to {self.path}" if self.path else ""
5678
+ return f"<IDFGeometryView: {len(self.html) // 1024} KB{where}>"
5679
+
5680
+ def _repr_html_(self):
5681
+ import html as _html
5682
+ return (f'<iframe srcdoc="{_html.escape(self.html, quote=True)}" '
5683
+ 'style="width:100%;height:600px;border:0"></iframe>')
5684
+
5685
+
5410
5686
  def plot_idf_geometry(idf, output_path=None, show=False, opacity=0.8,
5411
5687
  include_shading=True, title=None, shading_opacity=0.2,
5412
5688
  **_ignored):
5413
5689
  """Render the 3-D geometry of an EnergyPlus IDF — zone walls/roofs/floors,
5414
- windows and neighbour shadings — as an INTERACTIVE plotly scene (rotate /
5415
- zoom / toggle layers), mirroring ``utils.plot_building_3d_geometry``.
5690
+ windows and neighbour shadings — as an INTERACTIVE three.js page (rotate /
5691
+ pan / zoom, toggle surface categories, hover for the category name).
5416
5692
 
5417
5693
  Parameters
5418
5694
  ----------
5419
5695
  idf : a ``geomeppy``/``eppy`` IDF object, or a path to an ``.idf`` file.
5420
- output_path : optional path to save the figure; written as interactive
5696
+ output_path : optional path to save the viewer; written as a standalone
5421
5697
  ``.html`` (any other extension is coerced to ``.html``).
5422
- show : if True and no ``output_path``, open the figure (``fig.show``).
5423
- include_shading : draw ``Shading:*:Detailed`` neighbour obstructions.
5698
+ show : if True and no ``output_path``, open the viewer in the default web
5699
+ browser (served from a one-shot local HTTP server).
5700
+ include_shading : draw the ``Shading:*:Detailed`` surfaces: the neighbour
5701
+ obstructions (``Shading: neighbours``) and the building's own reveals,
5702
+ balconies and awnings (``Shading: building``).
5424
5703
  opacity : fill opacity of the building surfaces (default 0.8, so a surface
5425
5704
  seen through one or more others reads as clearly blurred/dimmed).
5426
- shading_opacity : fill opacity of the neighbour ``Shading`` panels (default
5705
+ shading_opacity : fill opacity of the neighbour shading panels (default
5427
5706
  0.2) — kept well below ``opacity`` so the context obstructions don't
5428
- compete with the building itself.
5429
- title : figure title.
5707
+ compete with the building itself. The building's own shading uses
5708
+ ``opacity``.
5709
+ title : page title.
5430
5710
 
5431
- Returns the plotly ``Figure``.
5711
+ Returns an :class:`IDFGeometryView` (``.html`` is the page, ``.show()``
5712
+ opens it, and it renders inline in Jupyter).
5713
+
5714
+ The geometry is embedded in the page; three.js itself is loaded from the
5715
+ jsDelivr CDN, so opening the page needs an internet connection.
5432
5716
 
5433
5717
  Party walls (``Wall: party``) and adiabatic partitions (``Wall: adiabatic``)
5434
5718
  are separate legend groups/colours: both share the Adiabatic boundary
5435
5719
  condition, but a party wall abuts the neighbour building (its outer face sees
5436
5720
  outdoor air) whereas an adiabatic wall is a purely internal partition.
5437
5721
  """
5438
- import plotly.graph_objects as go
5722
+ import html as _html
5723
+ import json
5439
5724
 
5440
5725
  if isinstance(idf, str):
5441
5726
  IDF = _ensure_idd()
@@ -5446,53 +5731,41 @@ def plot_idf_geometry(idf, output_path=None, show=False, opacity=0.8,
5446
5731
  # Stable fallback palette for categories not in _IDF_VIEW_COLORS.
5447
5732
  _fallback = ["#8dd3c7", "#fb8072", "#80b1d3", "#fdb462", "#b3de69",
5448
5733
  "#bc80bd", "#ffed6f", "#fccde5", "#d9d9d9"]
5449
- traces = []
5734
+ categories = []
5450
5735
  for ci, (cat, polys) in enumerate(polys_by_cat.items()):
5451
5736
  if not polys:
5452
5737
  continue
5453
- color = _IDF_VIEW_COLORS.get(cat, _fallback[ci % len(_fallback)])
5454
- # ---- filled surfaces: one Mesh3d per category (fan-triangulated) ----
5455
- xs, ys, zs, i, j, k = [], [], [], [], [], []
5456
- ex, ey, ez = [], [], [] # edge polylines (None-separated)
5738
+ # One fan-triangulated mesh + one outline set per category.
5739
+ positions, indices, edges = [], [], []
5457
5740
  for poly in polys:
5458
- base = len(xs)
5741
+ base = len(positions) // 3
5459
5742
  for (x, y, z) in poly:
5460
- xs.append(x); ys.append(y); zs.append(z)
5743
+ positions += [round(x, 3), round(y, 3), round(z, 3)]
5461
5744
  for t in range(1, len(poly) - 1):
5462
- i.append(base); j.append(base + t); k.append(base + t + 1)
5463
- for (x, y, z) in poly + [poly[0]]:
5464
- ex.append(x); ey.append(y); ez.append(z)
5465
- ex.append(None); ey.append(None); ez.append(None)
5745
+ indices += [base, base + t, base + t + 1]
5746
+ for a, b in zip(poly, poly[1:] + poly[:1]):
5747
+ edges += [round(v, 3) for v in (*a, *b)]
5466
5748
  # Neighbour shading is context — render it much more transparent than the
5467
- # building surfaces so it never competes with them.
5468
- is_shading = cat == "Shading"
5469
- cat_opacity = shading_opacity if is_shading else opacity
5470
- traces.append(go.Mesh3d(
5471
- x=xs, y=ys, z=zs, i=i, j=j, k=k,
5472
- color=color, opacity=cat_opacity, flatshading=True,
5473
- name=cat, legendgroup=cat, showlegend=True,
5474
- hoverinfo="name"))
5475
- # ---- crisp edges: one Scatter3d per category, shares its legend group -
5476
- edge_col = "rgba(80,80,80,0.25)" if is_shading else "rgba(40,40,40,0.6)"
5477
- traces.append(go.Scatter3d(
5478
- x=ex, y=ey, z=ez, mode="lines",
5479
- line=dict(color=edge_col, width=1 if is_shading else 2),
5480
- legendgroup=cat, showlegend=False, hoverinfo="skip"))
5481
-
5482
- fig = go.Figure(data=traces)
5483
- # True 1:1:1 metre scale (aspectmode='data') like plot_building_3d_geometry.
5484
- fig.update_layout(
5485
- title=title,
5486
- scene=dict(
5487
- xaxis=dict(title="x (m)"),
5488
- yaxis=dict(title="y (m)"),
5489
- zaxis=dict(title="Height (m)"),
5490
- aspectmode="data",
5491
- camera=dict(eye=dict(x=1.5, y=-1.5, z=1.0)),
5492
- ),
5493
- legend=dict(title="Surface", x=0.01, y=0.99),
5494
- margin=dict(l=0, r=0, b=40, t=40),
5495
- )
5749
+ # building surfaces so it never competes with them. The building's own
5750
+ # shading (reveals, balconies, awnings) is drawn like the building.
5751
+ is_shading = cat == "Shading: neighbours"
5752
+ categories.append({
5753
+ "name": cat,
5754
+ "color": _IDF_VIEW_COLORS.get(cat, _fallback[ci % len(_fallback)]),
5755
+ "opacity": float(shading_opacity if is_shading else opacity),
5756
+ "edge_opacity": 0.25 if is_shading else 0.6,
5757
+ "context": is_shading,
5758
+ "count": len(polys),
5759
+ "positions": positions, "indices": indices, "edges": edges,
5760
+ })
5761
+
5762
+ # "</" is escaped so the JSON can't close its <script> block early.
5763
+ data = json.dumps({"title": title, "categories": categories},
5764
+ separators=(",", ":")).replace("</", "<\\/")
5765
+ page = (_IDF_VIEW_HTML
5766
+ .replace("__TITLE__", _html.escape(title or "IDF geometry"))
5767
+ .replace("__V__", _THREEJS_VERSION)
5768
+ .replace("__DATA__", data))
5496
5769
 
5497
5770
  if output_path:
5498
5771
  ext = output_path.rsplit(".", 1)[-1].lower() if "." in output_path else ""
@@ -5500,11 +5773,13 @@ def plot_idf_geometry(idf, output_path=None, show=False, opacity=0.8,
5500
5773
  output_path = (output_path.rsplit(".", 1)[0] + ".html"
5501
5774
  if "." in output_path else output_path + ".html")
5502
5775
  os.makedirs(os.path.dirname(output_path) or ".", exist_ok=True)
5503
- fig.write_html(output_path)
5776
+ with open(output_path, "w", encoding="utf-8") as fh:
5777
+ fh.write(page)
5504
5778
  print(f"IDF geometry plot saved to {output_path}")
5505
- elif show:
5506
- fig.show()
5507
- return fig
5779
+ view = IDFGeometryView(page, output_path or None)
5780
+ if show and not output_path:
5781
+ view.show()
5782
+ return view
5508
5783
 
5509
5784
 
5510
5785
  # =========================================================================== #
@@ -1552,10 +1552,15 @@ def join_cadaster_building(gdf, cadaster_dir, census_tracts_dir, DEM_raster_dir,
1552
1552
  # like br__building_spaces_*); other GEOMETRY columns
1553
1553
  # stay as raw WKB bytes so write_gdf downstream doesn't
1554
1554
  # see unexpected geopandas 'geometry' dtype columns.
1555
+ # _br_merged is built by raw SQL, so _meta holds no CRS for it
1556
+ # and read_gdf would return crs=None; carry the source CRS over.
1555
1557
  with utils.stage_timer("merge: read _br_merged into GeoDataFrame"):
1558
+ _src_crs = building_gdf_.crs
1556
1559
  building_gdf_ = _db_mod.read_gdf(
1557
1560
  central_con, "_br_merged", geom_col="building_geometry"
1558
1561
  )
1562
+ if building_gdf_.crs is None and _src_crs is not None:
1563
+ building_gdf_ = building_gdf_.set_crs(_src_crs)
1559
1564
 
1560
1565
  # Also keep br_results for building_part_gdf downstream
1561
1566
  with utils.stage_timer("merge: br_results -> pandas (building_part_gdf)"):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hypercadaster_es
3
- Version: 1.4.1
3
+ Version: 1.4.2
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
@@ -80,7 +80,7 @@ Requires-Dist: regex<2027.0,>=2023.12
80
80
  Requires-Dist: tqdm>=4.66
81
81
  Requires-Dist: six>=1.16
82
82
  Requires-Dist: PyYAML>=6.0
83
- Requires-Dist: social_ES>=1.0.3
83
+ Requires-Dist: social_ES>=1.0.4
84
84
  Provides-Extra: dev
85
85
  Requires-Dist: black>=24.0; extra == "dev"
86
86
  Requires-Dist: ruff>=0.4; extra == "dev"
@@ -107,7 +107,7 @@ A comprehensive Python library for downloading, processing, and analyzing Spanis
107
107
 
108
108
  [![Python Version](https://img.shields.io/badge/python-3.12+-blue.svg)](https://python.org)
109
109
  [![License](https://img.shields.io/badge/license-EUPL%20v1.2-blue.svg)](https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12)
110
- [![Version](https://img.shields.io/badge/version-1.4.1-green.svg)](https://github.com/BeeGroup-cimne/hypercadaster_ES)
110
+ [![Version](https://img.shields.io/badge/version-1.4.2-green.svg)](https://github.com/BeeGroup-cimne/hypercadaster_ES)
111
111
 
112
112
  ## 🎯 Overview
113
113
 
@@ -234,4 +234,4 @@ This project is licensed under the **EUPL v1.2**. See the [license](https://join
234
234
 
235
235
  *hypercadaster_ES - Built with ❤️ for the Spanish urban analysis and building research community*
236
236
 
237
- *Last updated: November 2026 | Version 1.4.1*
237
+ *Last updated: November 2026 | Version 1.4.2*
@@ -60,7 +60,7 @@ regex<2027.0,>=2023.12
60
60
  tqdm>=4.66
61
61
  six>=1.16
62
62
  PyYAML>=6.0
63
- social_ES>=1.0.3
63
+ social_ES>=1.0.4
64
64
 
65
65
  [dev]
66
66
  black>=24.0
@@ -3,7 +3,7 @@ from setuptools import find_packages, setup
3
3
 
4
4
  HERE = pathlib.Path(__file__).parent
5
5
 
6
- VERSION = "1.4.1"
6
+ VERSION = "1.4.2"
7
7
  PACKAGE_NAME = "hypercadaster_es"
8
8
  AUTHOR = "Jose Manuel Broto Vispe"
9
9
  AUTHOR_EMAIL = "jmbrotovispe@gmail.com"
@@ -104,7 +104,7 @@ INSTALL_REQUIRES = [
104
104
  # --- Socioeconomic INE datasets (EUPL-1.2) ---
105
105
  # 1.0.3 emits the Essential-Characteristics variables already translated to
106
106
  # English snake_case and adds the dwellings / empty-and-secondary censuses.
107
- "social_ES>=1.0.3",
107
+ "social_ES>=1.0.4",
108
108
  ]
109
109
 
110
110