feature/Druck #12

Open
opened 2026-03-18 15:28:02 +01:00 by Daniel · 0 comments
Member
  1. Feste Variable: dict DIN={"A0":(x-Wert,y-Wert),"A1":...}
  2. extrahiere die BBox des Verfahrensgebietes
  • Auswahlfeld Verfahrensgebietslayer?=var(Verfahrensgebietslayer)
  • Auswahlfeld/Textfeld Maßstab?=var(zielmassstab)
  • Auswahlfeld Blattgröße?=var(zielgroesse)
  • Auswahlfeld Blattlänge Variabel oder DIN=var(formfaktor)
  • Auswahlfeld View oder aktuelle Ansicht=var(view)
  1. berechne die Ausdehnung des Kartenbildes bei gewähltem Maßstab
  2. Berechne die benötigte Kartengröße (Kartenbild inkl. Rahmen und Kartenschild)
  3. entscheide, welche Blattgröße
  • prüfe gegen die DIN-Größen (kleinste Größe, auf die die Kartengröße passt)=Plotgröße
  • Wenn Auswahl Blattgröße kleiner Plotgröße: Teile BBox in 2 Hälften (Hochwert) und durchlaufe Schleife für beide Hälften.
  1. baue Kartenvorlage anhand der Plotgröße , view, wenn Hälften, Übersichtskarte, Seite...von... einfügen (muss ein Atlas aufgebaut werden)
  2. speichere die Kartenvorlage im Projekt
    from dataclasses import dataclass
    from typing import Tuple, List, Dict

@dataclass(frozen=True)
class BBox:
xmin: float
ymin: float
xmax: float
ymax: float

def width(self) -> float:
    return self.xmax - self.xmin

def height(self) -> float:
    return self.ymax - self.ymin

class PlotLayoutCalculator:
"""
Berechnet, ob eine BBox auf ein Druckformat passt und erzeugt
bei Bedarf Atlas-Kacheln gleicher Größe.
"""

def __init__(self,
             scale: int,
             max_format: str,
             din_sizes: Dict[str, Tuple[int, int]]):
    self.scale = scale
    self.max_format = max_format
    self.din_sizes = din_sizes

    if max_format not in din_sizes:
        raise ValueError(f"Unbekanntes Format: {max_format}")

    # Seitengröße in mm
    self.page_width_mm, self.page_height_mm = din_sizes[max_format]

# ---------------------------------------------------------
# 1) Kartengröße im Maßstab berechnen
# ---------------------------------------------------------
def map_size_mm(self, bbox: BBox) -> Tuple[float, float]:
    """
    Berechnet die reale Kartengröße in mm basierend auf Maßstab und BBox.
    """
    # 1 m = 1000 mm
    mm_per_map_unit = 1000 / self.scale

    width_mm = bbox.width() * mm_per_map_unit
    height_mm = bbox.height() * mm_per_map_unit

    return width_mm, height_mm

# ---------------------------------------------------------
# 2) Prüfen, ob Karte auf das Format passt
# ---------------------------------------------------------
def fits_on_page(self, bbox: BBox) -> bool:
    width_mm, height_mm = self.map_size_mm(bbox)
    return width_mm <= self.page_width_mm and height_mm <= self.page_height_mm

# ---------------------------------------------------------
# 3) Atlas-Kacheln erzeugen
# ---------------------------------------------------------
def build_atlas(self, bbox: BBox) -> List[BBox]:
    """
    Zerlegt die BBox in gleichmäßige Kacheln, sodass jede Kachel
    auf das Druckformat passt.
    """
    width_mm, height_mm = self.map_size_mm(bbox)

    # Wie viele Kacheln werden benötigt?
    tiles_x = max(1, int(width_mm // self.page_width_mm) + 1)
    tiles_y = max(1, int(height_mm // self.page_height_mm) + 1)

    tile_width = bbox.width() / tiles_x
    tile_height = bbox.height() / tiles_y

    tiles = []

    for ix in range(tiles_x):
        for iy in range(tiles_y):
            xmin = bbox.xmin + ix * tile_width
            xmax = xmin + tile_width
            ymin = bbox.ymin + iy * tile_height
            ymax = ymin + tile_height

            tiles.append(BBox(xmin, ymin, xmax, ymax))

    return tiles
1. Feste Variable: dict DIN={"A0":(x-Wert,y-Wert),"A1":...} 2. extrahiere die BBox des Verfahrensgebietes - Auswahlfeld Verfahrensgebietslayer?=var(Verfahrensgebietslayer) - Auswahlfeld/Textfeld Maßstab?=var(zielmassstab) - Auswahlfeld Blattgröße?=var(zielgroesse) - Auswahlfeld Blattlänge Variabel oder DIN=var(formfaktor) - Auswahlfeld View oder aktuelle Ansicht=var(view) 1. berechne die Ausdehnung des Kartenbildes bei gewähltem Maßstab 2. Berechne die benötigte Kartengröße (Kartenbild inkl. Rahmen und Kartenschild) 3. entscheide, welche Blattgröße - prüfe gegen die DIN-Größen (kleinste Größe, auf die die Kartengröße passt)=Plotgröße - Wenn Auswahl Blattgröße kleiner Plotgröße: Teile BBox in 2 Hälften (Hochwert) und durchlaufe Schleife für beide Hälften. 1. baue Kartenvorlage anhand der Plotgröße , view, wenn Hälften, Übersichtskarte, Seite...von... einfügen (muss ein Atlas aufgebaut werden) 2. speichere die Kartenvorlage im Projekt from dataclasses import dataclass from typing import Tuple, List, Dict @dataclass(frozen=True) class BBox: xmin: float ymin: float xmax: float ymax: float def width(self) -> float: return self.xmax - self.xmin def height(self) -> float: return self.ymax - self.ymin class PlotLayoutCalculator: """ Berechnet, ob eine BBox auf ein Druckformat passt und erzeugt bei Bedarf Atlas-Kacheln gleicher Größe. """ def __init__(self, scale: int, max_format: str, din_sizes: Dict[str, Tuple[int, int]]): self.scale = scale self.max_format = max_format self.din_sizes = din_sizes if max_format not in din_sizes: raise ValueError(f"Unbekanntes Format: {max_format}") # Seitengröße in mm self.page_width_mm, self.page_height_mm = din_sizes[max_format] # --------------------------------------------------------- # 1) Kartengröße im Maßstab berechnen # --------------------------------------------------------- def map_size_mm(self, bbox: BBox) -> Tuple[float, float]: """ Berechnet die reale Kartengröße in mm basierend auf Maßstab und BBox. """ # 1 m = 1000 mm mm_per_map_unit = 1000 / self.scale width_mm = bbox.width() * mm_per_map_unit height_mm = bbox.height() * mm_per_map_unit return width_mm, height_mm # --------------------------------------------------------- # 2) Prüfen, ob Karte auf das Format passt # --------------------------------------------------------- def fits_on_page(self, bbox: BBox) -> bool: width_mm, height_mm = self.map_size_mm(bbox) return width_mm <= self.page_width_mm and height_mm <= self.page_height_mm # --------------------------------------------------------- # 3) Atlas-Kacheln erzeugen # --------------------------------------------------------- def build_atlas(self, bbox: BBox) -> List[BBox]: """ Zerlegt die BBox in gleichmäßige Kacheln, sodass jede Kachel auf das Druckformat passt. """ width_mm, height_mm = self.map_size_mm(bbox) # Wie viele Kacheln werden benötigt? tiles_x = max(1, int(width_mm // self.page_width_mm) + 1) tiles_y = max(1, int(height_mm // self.page_height_mm) + 1) tile_width = bbox.width() / tiles_x tile_height = bbox.height() / tiles_y tiles = [] for ix in range(tiles_x): for iy in range(tiles_y): xmin = bbox.xmin + ix * tile_width xmax = xmin + tile_width ymin = bbox.ymin + iy * tile_height ymax = ymin + tile_height tiles.append(BBox(xmin, ymin, xmax, ymax)) return tiles
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: AG_QGIS/Plugin_SN_Plan41#12