CSV-Export: Nachbarschaftserkennung ueber Bounding-Box-Ueberschneidung (STRtree/shapely)
Neue Spalte "Nachbarn" (kommaseparierte TeileId-Liste) in export_csv.py: zwei Elemente gelten als benachbart, wenn ihre Bounding-Boxes (x/y-Ebene) sich ueberschneiden. Toleranz konfigurierbar in mm ueber cfg/export.cfg [Nachbarschaft] -> toleranz_mm, siehe lib/export_neighbors.py. Nur EXPORTCSV betroffen, EXPORTSIVAS bleibt unveraendert. shapely als neue Abhaengigkeit in requirements.txt ergaenzt. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+18
-5
@@ -11,7 +11,7 @@ Aufruf:
|
||||
python export_csv.py <export_raw.json> <data_dir> <output.csv>
|
||||
|
||||
CSV-Format:
|
||||
Elementnummer;TeileArt;TeileId;Bezeichnung;Planquadrat;Anzahl;Position;Boundingbox;Merkmale
|
||||
Elementnummer;TeileArt;TeileId;Bezeichnung;Planquadrat;Anzahl;Position;Boundingbox;Nachbarn;Merkmale
|
||||
|
||||
Position und Boundingbox stammen aus der von export.lsp (csv:get-bbox, per
|
||||
vla-getboundingbox) ermittelten Bounding-Box je Block:
|
||||
@@ -19,8 +19,11 @@ vla-getboundingbox) ermittelten Bounding-Box je Block:
|
||||
Boundingbox = Ausdehnung (Laenge, Breite, Hoehe) in x, y, z
|
||||
Planquadrat wird aus der x/y-Koordinate des Blocks berechnet, siehe
|
||||
export_planquadrat.py ([Planquadrate] in cfg/export.cfg).
|
||||
Position, Boundingbox und Planquadrat sind nur fuer EXPORTCSV vorhanden
|
||||
(nicht EXPORTSIVAS) - siehe csv:run-export.
|
||||
Nachbarn = kommaseparierte TeileId-Liste ueberschneidender Elemente (Bounding-
|
||||
Box-Ueberschneidung in der x/y-Ebene per shapely-STRtree, Toleranz konfigurierbar
|
||||
ueber [Nachbarschaft] -> toleranz_mm in cfg/export.cfg), siehe export_neighbors.py.
|
||||
Position, Boundingbox, Planquadrat und Nachbarn sind nur fuer EXPORTCSV
|
||||
vorhanden (nicht EXPORTSIVAS) - siehe csv:run-export.
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -29,9 +32,11 @@ import os
|
||||
|
||||
from export_blockpatterns import load_patterns, matches_any
|
||||
from export_planquadrat import load_planquadrat_config, compute_planquadrat
|
||||
from export_neighbors import load_neighbor_tolerance_mm, compute_neighbor_ids
|
||||
|
||||
BLOCKPATTERNS = load_patterns()
|
||||
PLANQUADRAT_CFG = load_planquadrat_config()
|
||||
NEIGHBOR_TOLERANCE_MM = load_neighbor_tolerance_mm()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -240,13 +245,16 @@ def bbox_columns(block):
|
||||
Rueckgabe: dict mit "position" (Mittenkoordinate x,y,z) und "boundingbox"
|
||||
(Ausdehnung x,y,z) als Strings, oder leere Strings falls kein bbox-Feld
|
||||
vorhanden ist (z.B. EXPORTSIVAS oder die synthetische Omniflo-Sum-Zeile).
|
||||
"_bbox" enthaelt zusaetzlich die rohen Zahlenwerte fuer die Nachbarschafts-
|
||||
erkennung (siehe export_neighbors.py), wird nicht in die CSV geschrieben.
|
||||
"""
|
||||
bbox = block.get("bbox")
|
||||
if not bbox:
|
||||
return {"position": "", "boundingbox": ""}
|
||||
return {"position": "", "boundingbox": "", "_bbox": None}
|
||||
return {
|
||||
"position": f'{bbox.get("cx", 0):.2f}, {bbox.get("cy", 0):.2f}, {bbox.get("cz", 0):.2f}',
|
||||
"boundingbox": f'{bbox.get("dx", 0):.2f}, {bbox.get("dy", 0):.2f}, {bbox.get("dz", 0):.2f}',
|
||||
"_bbox": bbox,
|
||||
}
|
||||
|
||||
|
||||
@@ -452,6 +460,10 @@ def process_blocks(blocks, lookup):
|
||||
"boundingbox": "",
|
||||
})
|
||||
|
||||
neighbor_ids = compute_neighbor_ids(items, NEIGHBOR_TOLERANCE_MM)
|
||||
for item, nachbarn in zip(items, neighbor_ids):
|
||||
item["nachbarn"] = nachbarn
|
||||
|
||||
return items
|
||||
|
||||
|
||||
@@ -470,6 +482,7 @@ def format_csv_line(item):
|
||||
f';1'
|
||||
f';"{item["position"]}"'
|
||||
f';"{item["boundingbox"]}"'
|
||||
f';"{item["nachbarn"]}"'
|
||||
f';{merkmale_json}'
|
||||
)
|
||||
|
||||
@@ -501,7 +514,7 @@ def main():
|
||||
|
||||
items = process_blocks(blocks, lookup)
|
||||
|
||||
header = "Elementnummer;TeileArt;TeileId;Bezeichnung;Planquadrat;Anzahl;Position;Boundingbox;Merkmale"
|
||||
header = "Elementnummer;TeileArt;TeileId;Bezeichnung;Planquadrat;Anzahl;Position;Boundingbox;Nachbarn;Merkmale"
|
||||
with open(output_csv, "w", encoding="utf-8") as f:
|
||||
f.write(header + "\n")
|
||||
for item in items:
|
||||
|
||||
Reference in New Issue
Block a user