Skip to content
cadkithome

CityGML 2.0 and the TKGM preflight

cadkit reads and writes UTF-8 CityGML 2.0 (GML 3.1.1) in pure Rust, with no network requests, no schema downloads, no CRS transformation and no axis swapping. It has two models of a CityGML file:

  • the native model (read_citygml, readCityGml, gml::read_native), which keeps object IDs, building, room and surface relationships, shared references, typed attributes and XML extensions, and writes them back;
  • the neutral document that every other format uses, a geometric projection for viewing or converting to DXF, SVG or DGN.

Writing a drawing as CityGML (to_citygml) creates GenericCityObject instances, never inferred buildings or rooms. You must name the coordinate reference system the coordinates are already in, and a level of detail from 0 to 4; cadkit writes the coordinates unchanged and never guesses a CRS or reprojects.

Points, straight lines and polylines, exact circles, closed polygons, faces, meshes and groups are written. Closed polylines stay curves, so create polygon entities for surfaces. Bulges, widths, arcs, splines, text, images and other kinds fail by default; with metadata_only (an explicit opt-in) they are kept only as JSON metadata and listed in the report.

src/main.rs
use cadkit::gml::tkgm::{self, Profile};
use cadkit::gml::{self, ExportOptions, ValidationOptions};
use cadkit::{Limits, ReadOptions};
// The CRS your coordinates are in; cadkit never guesses or transforms one.
const CRS: &str = "urn:ogc:def:crs:EPSG::32635";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let doc = cadkit::open("surfaces.dxf")?; // 3D faces or polygons
let xml = cadkit::to_citygml(&doc, &ExportOptions::new(CRS, 1))?;
std::fs::write("model.gml", &xml)?;
let native = gml::read_native(&std::fs::read("model.gml")?, &ReadOptions::default())?;
let summary = gml::validate(&native, &ValidationOptions::new())?;
println!("{summary:?}");
// Local structural checks only; the receiving system remains the acceptance authority.
let preflight = tkgm::preflight(&native, Profile::CityModelTender, &Limits::default())?;
println!("acceptance verified: {}", preflight.acceptance_verified); // always false
for issue in &preflight.issues {
println!("{:?} {} {:?}", issue.severity, issue.code, issue.field);
}
Ok(())
}

The example CRS identifier is a placeholder: use the one your survey or model is in.

shell
cadkit convert surfaces.dxf model.gml --crs urn:ogc:def:crs:EPSG::32635 --lod 1
cadkit validate-gml model.gml > validation.json
cadkit validate-gml model.gml --tkgm-profile city-model-tender > preflight.json \
|| echo "preflight reported issues; see preflight.json"

preflight_tkgm (preflightTkgm, gml::tkgm::preflight, cadkit_citygml_preflight_tkgm, validate-gml --tkgm-profile) runs on the native model and needs an explicit profile; there is no default:

Profile Scope
city-model-tender Architectural common subset of the public 3D city-model tender production guide (CityGML 2.0, revision v2.50). Tender-year MAKS rules and sustainability extensions stay unchecked.
digital-building-registration The separate Digital Building registration guide (TKGMCityGML 3.0.3) rules that cadkit implements.

A TKGM delivery models buildings as Building, storeys as CityObjectGroup and independent sections as GenericCityObject with their classes, typed attributes and links. Generic geometry written from a drawing does not populate that model, which is why the example above reports tkgm.missing_class, tkgm.missing_building and tkgm.missing_envelope. The application that owns the meaning of its objects (which rectangle is a room, a floor or a roof) builds the native model; cadkit validates and writes it.