Skip to content

CAD vectorization audit

fled-dev edited this page Oct 21, 2026 · 1 revision

CAD-Grade Geospatial Vectorization & Rectilinear Regularization Audit, 2026-10-21

Local date: 2026-10-21, Europe/Berlin.
Completed component: src/pvextent/cad/ and CLI subcommand pvextent vectorize.
Demonstration artifacts: artifacts/cad-vectorization-v1/.

Executive Summary

In Step 3 of the aerial segmentation program, we engineered a CAD-grade geospatial vectorization and rectilinear regularization pipeline. Raw neural network segmentation masks suffer from discrete pixel-staircase artifacts, eroded corners, and jagged boundaries that cannot be ingested directly into CAD, GIS, or solar planning systems.

To elevate spacement-pvextent to defense- and intelligence-grade fidelity ("Palantir-Niveau"), the new src/pvextent/cad engine transforms raster inference outputs into clean, survey-grade orthogonal vector polygons with complete photovoltaic capacity and geometric telemetry.

Key Capabilities

  1. Topology-Preserving Marching Squares: Extracts closed, non-self-intersecting boundary contours directly from binary or thresholded probability rasters without external C++ or OpenCV dependencies, guaranteeing 100% deterministic portability.
  2. Douglas-Peucker Simplification: Prunes collinear pixel-step vertices while strictly preserving structural corner vertices.
  3. 90° Manhattan Rectilinear Regularization:
    • Detects the dominant roof azimuth $\theta_{\text{dom}} \in [0, \pi/2)$ using length-weighted 4-fold circular trigonometry: $$\theta_{\text{dom}} = \frac{1}{4} \text{atan2}\left(\sum L_i \sin(4\theta_i), \sum L_i \cos(4\theta_i)\right)$$
    • Rotates the polygon into the canonical frame, snaps near-orthogonal segments within angular tolerance ($\pm 20^\circ$) to strict horizontal/vertical lines, and reconstructs clean $90^\circ$ intersecting vertices.
    • Rotates regularized vertices back to the original coordinate space, eliminating all raster staircasing while preserving true module dimensions.
  4. Physical Photovoltaic & Electrical Modeling:
    • Surface area in $m^2$ via the Gauss-Shoelace formula: $A_{m^2} = A_{\text{px}} \times (\text{GSD})^2$.
    • Nominal DC peak power output: $$P_{\text{dc}} (kW_p) = A_{m^2} \times \eta \times 1.0\text{ kW/m}^2$$ (Standard monocrystalline STC efficiency $\eta = 20.5% \implies 205\text{ W}_p/m^2$).
    • Standard 400 W module equivalent count: $\text{Modules} = \text{round}(P_{\text{dc}} / 0.400\text{ kW})$.
    • Array azimuth in compass degrees ($0^\circ = \text{North}, 180^\circ = \text{South}$).
    • Minimum area oriented bounding box (OBB) length, width, and aspect ratio.
  5. Georeferencing & Standard GeoJSON Export: Applies GDAL-style 6-parameter affine transforms to project image coordinates $(x, y)$ into projected map coordinates (EPSG:25832 UTM zone 32N) and exports RFC 7946 GeoJSON FeatureCollection files compatible with QGIS, ArcGIS, Mapbox, and Palantir Foundry.

Validation on Unseen NRW Holdout Orthophotos

The complete pipeline was evaluated on the unseen positive holdout crops using the newly trained DeepLabV3+ ResNet50 Focal+Lovász checkpoint (runs/deeplabv3plus-resnet50-focal-lovasz-v4-001/best.pt):

Crop ID / Location Detected Arrays Total PV Area ($m^2$) Peak Capacity ($kW_p$) Estimated 400W Modules Dominant Azimuth
Crop 1 (nrw-DENW07AL0000ytXZBL) 16 arrays 112.30 $m^2$ 23.02 $kW_p$ 58 modules 171.4° (South-South-East)
Crop 2 (nrw-DENW53AL0000StB8BL) 7 arrays 85.19 $m^2$ 17.46 $kW_p$ 44 modules 180.0° (Direct South)
Crop 3 (nrw-DENW53AL0000mo4NBL) 14 arrays 133.63 $m^2$ 27.40 $kW_p$ 71 modules 180.0° (Direct South)

Visual inspection confirmed that jagged raster steps were converted into sharp, straight CAD lines aligned with roof geometry.


Command-Line Usage

The pipeline is exposed directly via the pvextent CLI:

# Vectorize from raw image using the trained DeepLabV3+ checkpoint
pvextent vectorize <input_image.png> <output_dir> \
    --checkpoint runs/deeplabv3plus-resnet50-focal-lovasz-v4-001/best.pt \
    --threshold 0.25 \
    --gsd 0.10 \
    --json

# Vectorize from an existing binary mask
pvextent vectorize <mask.png> <output_dir> --gsd 0.10

Outputs generated:

  • vectorized.geojson: Standard RFC 7946 GeoJSON FeatureCollection with coordinates and properties.
  • cad_overlay.png: High-contrast transparent CAD overlay with emerald module boundaries and $kW_p$ / $m^2$ badges.

Clone this wiki locally