[207] Situation: Kataster-Gebäude/Gewässer als Flächen, Innenhöfe als Löcher, Kataster-Layer auf Klassen, Zahlen-Layer benannt

This commit is contained in:
Claude committed 2026-11-13 17:14:25 +00:00
1 parent 118d06010c
commit dddcfa5d87
11 files changed
+652 -10

No files matched your search

+1
View File
@@ -1827,6 +1827,7 @@ fn domains_before(c: &Ctx, out: &mut DomainPrims, bounds: &mut Bounds) -> Result
}
// [207] Situationsplan: das eigene Gebäude als gefüllter Umriss statt der Bauteile (nur Bäume bleiben).
if let Some(s) = super::situation::opts(c) {
super::situation::cadastre_prims(c, &s, &mut out.roofs);
super::situation::own_prims(c, &s, &mut out.roofs, bounds);
super::trees::plan_trees(c, &mut out.columns);
return Ok(());
+34
View File
@@ -1921,6 +1921,40 @@ pub fn plan_drawings(c: &Ctx, sink: &mut Sink, bounds: &mut Bounds) -> Result<()
Ok(())
}
/// [207] Geschlossene Ringe der gezeichneten Zeichnungen des Geschosses (geschlossene Polylinie samt Inseln, Rechteck)
/// auf Klassen, die `pred` (Klassen-Code) wählt und die der Plan zeigt; je Klasse in Projekt-Reihenfolge. Quelle der
/// gefüllten Kataster-Gebäude und -Gewässer im Situationsplan (`situation.rs`).
pub fn closed_rings_by_class(c: &Ctx, pred: impl Fn(&str) -> bool) -> Vec<(String, Vec<Vec<[f64; 2]>>)> {
let mut memo = Memo::default();
let mut out: Vec<(String, Vec<Vec<[f64; 2]>>)> = Vec::new();
for d in &c.p.drawings2d {
if !matches!(d.geom, Drawing2DGeom::Polyline { closed: true, .. } | Drawing2DGeom::Rect { .. }) || !pred(&d.category_code) || !on_floor(c, d) {
continue;
}
if !memo.get(c, d).shown {
continue;
}
let mut rings: Vec<Vec<[f64; 2]>> = Vec::new();
match &d.geom {
Drawing2DGeom::Rect { min, max } => rings.push(vec![[min.x, min.y], [max.x, min.y], [max.x, max.y], [min.x, max.y]]),
Drawing2DGeom::Polyline { pts, bulge, holes, .. } if pts.len() > 2 => {
rings.push(bulge_polyline_points(pts, bulge.as_deref(), true).iter().map(|q| [q.x, q.y]).collect());
rings.extend(holes.iter().flatten().filter(|h| h.len() >= 3).map(|h| h.iter().map(|q| [q.x, q.y]).collect::<Vec<_>>()));
}
_ => continue,
}
rings.retain(|r| r.iter().all(|q| q[0].is_finite() && q[1].is_finite()));
if rings.is_empty() {
continue;
}
match out.iter_mut().find(|(k, _)| *k == d.category_code) {
Some((_, v)) => v.extend(rings),
None => out.push((d.category_code.clone(), rings)),
}
}
out
}
/// [140] Zeichnungsarten, denen Raumstempel ausweichen (Bemassung, Koten, Texte, Symbole/Möbel als Blöcke,
/// Detailverweise, Punktmarken). Linien, Flächen, Raster und Bilder nicht: sie laufen oft durch ganze Räume.
pub fn is_stamp_obstacle(g: &Drawing2DGeom) -> bool {
+54 -5
View File
@@ -12,7 +12,11 @@
//! Wände, Treppen, Räume, Stützen, Körper, Bodenbeläge und Schnittmarken entfallen (`domains.rs`); Parzelle,
//! Strassen, Höhenlinien und Beschriftungen sind gewöhnliche Zeichnungen/Kontext auf ihren Klassen und
//! bleiben, solange die Klasse sichtbar ist (Ansichtsvorlage „Situation WBW", `standards.rs`).
//! Löcher (Innenhöfe) der Umrisse füllt eine weisse Fläche darüber.
//! - **Kataster-Zeichnungen** (2D, aus dem DXF-Import): geschlossene Polylinien/Rechtecke der Klasse „Gebäude"
//! werden wie Kontextgebäude gefüllt, die der Klasse „Gewässer" hellblau. Liegt ein Ring ganz in einem anderen
//! derselben Klasse, ist er ein Loch (Innenhof; gerade/ungerade, `polygon_bool::nest_even_odd`).
//! Löcher (Innenhöfe) der Umrisse sind echte Löcher: ein Ring mit Brücken (`polygon_holes`, Brückenkanten ohne
//! Strich), Füllung und Strich bleiben korrekt, nichts liegt weiss darüber.
use super::domains::{Bounds, Ctx};
use super::drawings::mm_to_model;
@@ -28,6 +32,8 @@ pub const SYMBOL_CATEGORY: &str = crate::standards::SYMBOL_CATEGORY;
const BLACK: (&str, &str) = ("#000000", "#000000");
const GREY: (&str, &str) = ("#b8b8b8", "#7c7c7c");
/// Gewässer aus dem Kataster: hellblau gefüllt.
const WATER: (&str, &str) = ("#cfe3f1", "#7fa8c7");
const OUTLINE_MM: f64 = 0.1;
/// Eine Dreiecksfläche unter 1 cm² trägt nichts zur Aufsicht bei (senkrechte Wände, Splitter).
const MIN_TRI_AREA: f64 = 1e-4;
@@ -182,14 +188,54 @@ pub fn mesh_polygons(positions: &[f64], indices: &[f64]) -> Vec<Polygon> {
crate::polygon_bool::union(&tris)
}
/// Gefüllte Flächen: Aussenring in der Füllung, jedes Loch als weisse Fläche darüber.
/// Gefüllte Flächen: ein Polygon je Fläche; Löcher sind über Brücken eingebunden (Brückenkanten ohne Strich).
fn fill_polygons(polys: &[Polygon], f: (&str, &str), context_id: Option<&str>, greyed: bool, out: &mut Vec<Primitive>) {
for poly in polys {
let Some(outer) = poly.first().filter(|r| r.len() >= 3) else { continue };
out.push(polygon(outer.iter().map(|q| v2(*q)).collect(), f.0, f.1, OUTLINE_MM, context_id, greyed));
for hole in poly.iter().skip(1).filter(|r| r.len() >= 3) {
out.push(polygon(hole.iter().map(|q| v2(*q)).collect(), "#ffffff", f.1, OUTLINE_MM, None, greyed));
let holes: Vec<Ring> = poly.iter().skip(1).filter(|r| r.len() >= 3).cloned().collect();
if holes.is_empty() {
out.push(polygon(outer.iter().map(|q| v2(*q)).collect(), f.0, f.1, OUTLINE_MM, context_id, greyed));
continue;
}
let merged = crate::polygon_holes::merge_holes(outer, &holes, 1e-4);
let mut prim = polygon(merged.ring.iter().map(|q| v2(*q)).collect(), f.0, f.1, OUTLINE_MM, context_id, greyed);
if let Primitive::Polygon { no_stroke_edges, .. } = &mut prim {
*no_stroke_edges = (!merged.bridge_edges.is_empty()).then(|| merged.bridge_edges.iter().map(|&k| k as f64).collect());
}
out.push(prim);
}
}
/// Klasse „Gebäude" des Katasters: Code „12" oder ein Name mit „Gebäude"/„Building" (ohne die abgeleitete Klasse
/// „83 Situation Gebäude").
fn is_building_class(c: &Ctx, code: &str) -> bool {
code != OWN_CATEGORY && (code == "12" || name_has(c, code, &["gebäude", "gebaeude", "building"]))
}
/// Klasse „Gewässer": Code „17" oder ein Name mit „Gewässer"/„Water".
fn is_water_class(c: &Ctx, code: &str) -> bool {
code == "17" || name_has(c, code, &["gewässer", "gewaesser", "water"])
}
fn name_has(c: &Ctx, code: &str, words: &[&str]) -> bool {
c.cat(code).is_some_and(|k| {
let n = k.name.to_lowercase();
words.iter().any(|w| n.contains(w))
})
}
/// Kataster-Flächen aus 2D-Zeichnungen: Gebäude (Kontextfüllung, grau bzw. schwarz) und Gewässer (hellblau), auf
/// der Klasse der Zeichnung (die Klasse bestimmt über [`super::drawings::closed_rings_by_class`], ob sie erscheinen).
/// Innenhöfe sind Löcher. Unterhalb der Zeichnungen; deren Linien bleiben darüber.
pub fn cadastre_prims(c: &Ctx, s: &Opts, out: &mut Vec<Primitive>) {
let fills = |kind: fn(&Ctx, &str) -> bool| super::drawings::closed_rings_by_class(c, |code| kind(c, code));
if let Some(f) = colors(s.context) {
for (code, rings) in fills(is_building_class) {
fill_polygons(&crate::polygon_bool::nest_even_odd(&rings), f, None, c.greyed(&code), out);
}
}
for (code, rings) in fills(is_water_class) {
fill_polygons(&crate::polygon_bool::nest_even_odd(&rings), WATER, None, c.greyed(&code), out);
}
}
@@ -252,6 +298,9 @@ pub fn symbol_prims(c: &Ctx, s: &Opts, out: &mut Vec<Primitive>, bounds: &mut Bo
for m in imported_meshes(c) {
acc_polys(&mesh_polygons(&m.positions, &m.indices), &mut bb);
}
for (_, rings) in super::drawings::closed_rings_by_class(c, |code| is_building_class(c, code)) {
rings.iter().flatten().for_each(|q| bb.acc(q[0], q[1]));
}
if let Some(r) = c.p.site_rules.as_ref().map(|r| &r.parcel) {
for q in r {
bb.acc(q.x, q.y);
@@ -147,3 +147,60 @@ fn baurecht_nur_parzellengrenze() {
let normal = plan(&p, &all, "mittel");
assert!(normal.iter().filter(|q| matches!(q, Primitive::Line { cls, .. } if cls == "site-allowed")).count() > 0, "im gewöhnlichen Grundriss schon");
}
fn poly2d(id: &str, code: &str, pts: &[(f64, f64)]) -> Value {
json!({"id": id, "type": "drawing2d", "levelId": "eg", "categoryCode": code, "geom": {"shape": "polyline", "closed": true, "pts": pts.iter().map(|(x, y)| json!({"x": x, "y": y})).collect::<Vec<_>>()}})
}
fn rect_pts(x0: f64, y0: f64, x1: f64, y1: f64) -> [(f64, f64); 4] {
[(x0, y0), (x1, y0), (x1, y1), (x0, y1)]
}
/// Kataster: Haus mit Innenhof (zwei geschlossene Polylinien), Nachbarhaus, Gewässer auf Klasse „17".
fn cadastre_project() -> Project {
let p = project();
let mut v = serde_json::to_value(&p).unwrap();
v["context"] = json!([]);
v["layers"].as_array_mut().unwrap().push(json!({"code": "17", "name": "Gewässer", "color": "#909090", "lw": 0.13, "visible": true, "locked": false}));
let d = v["drawings2d"].as_array_mut().unwrap();
d.push(poly2d("k-haus", "12", &rect_pts(30.0, -20.0, 60.0, 0.0)));
d.push(poly2d("k-hof", "12", &rect_pts(40.0, -14.0, 50.0, -6.0)));
d.push(poly2d("k-nachbar", "12", &rect_pts(70.0, -20.0, 80.0, -10.0)));
d.push(poly2d("k-see", "17", &rect_pts(30.0, 10.0, 60.0, 30.0)));
serde_json::from_value(v).unwrap()
}
#[test]
fn kataster_gebaeude_gefuellt_hof_als_loch() {
let p = cadastre_project();
let ps = plan(&p, &codes(&p), "std-mv-situation-wbw");
let grey: Vec<&Primitive> = fills(&ps, "#b8b8b8").into_iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: None, .. })).collect();
assert_eq!(grey.len(), 2, "Haus mit Hof und Nachbar, je eine Fläche");
// Haus: 30 x 20 minus Hof 10 x 8 = 520 m2; der Hof ist ein Loch (Brückenring).
let areas: Vec<f64> = grey.iter().map(|q| if let Primitive::Polygon { pts, .. } = q { ring_area(pts) } else { 0.0 }).collect();
assert!(areas.iter().any(|a| (a - 520.0).abs() < 0.5), "Haus abzüglich Hof: {areas:?}");
assert!(areas.iter().any(|a| (a - 100.0).abs() < 1e-6), "Nachbarhaus: {areas:?}");
// Brückenkanten ohne Strich, kein weisser Hof darüber.
assert!(grey.iter().any(|q| matches!(q, Primitive::Polygon { no_stroke_edges: Some(e), .. } if !e.is_empty())), "Brücke zum Hof");
assert!(fills(&ps, "#ffffff").iter().all(|q| matches!(q, Primitive::Polygon { stroke_width_mm, .. } if *stroke_width_mm != 0.1)), "keine weisse Fläche über dem Hof");
// Gewässer hellblau.
let water = fills(&ps, "#cfe3f1");
assert_eq!(water.len(), 1);
let Primitive::Polygon { pts, .. } = water[0] else { unreachable!() };
assert!((ring_area(pts) - 600.0).abs() < 1e-6);
}
#[test]
fn kataster_schwarzplan_und_klassen() {
let p = cadastre_project();
let all = codes(&p);
let sp = plan(&p, &all, "std-mv-schwarzplan");
let black = sp.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: None, fill, stroke_width_mm, .. } if fill == "#000000" && *stroke_width_mm == 0.1)).count();
assert_eq!(black, 3, "eigenes Gebäude + Haus + Nachbar schwarz");
let no12 = plan(&p, &without(&all, "12"), "std-mv-situation-wbw");
assert!(fills(&no12, "#b8b8b8").is_empty(), "Klasse Gebäude schaltet die Kataster-Flächen");
let no17 = plan(&p, &without(&all, "17"), "std-mv-situation-wbw");
assert!(fills(&no17, "#cfe3f1").is_empty(), "Klasse Gewässer schaltet das Gewässer");
let normal = plan(&p, &all, "mittel");
assert!(fills(&normal, "#b8b8b8").is_empty() && fills(&normal, "#cfe3f1").is_empty());
}