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.
New geometry needs an explicit CRS
Section titled “New geometry needs an explicit CRS”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.
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(())}import cadkit
CRS = "urn:ogc:def:crs:EPSG::32635" # the CRS your coordinates are in; cadkit never guesses one
doc = cadkit.read("surfaces.dxf") # 3D faces or polygons; text and curves need a mappingxml, report = doc.to_citygml_with_report(CRS, lod=1)print(report["geometry_entities"], "of", report["entities"], "entities written as geometry")with open("model.gml", "wb") as f: f.write(xml)
with open("model.gml", "rb") as f: native = cadkit.read_citygml(f.read())print(native.validate()) # structural and geometric checks; returns counters
preflight = native.preflight_tkgm("city-model-tender") # local structural checks onlyprint("acceptance_verified:", preflight["acceptance_verified"]) # always Falsefor issue in preflight["issues"]: print(issue["severity"], issue["code"], issue["field"])import { readFileSync, writeFileSync } from "node:fs";import { read, readCityGml } from "cadkit-wasm/node";
const CRS = "urn:ogc:def:crs:EPSG::32635"; // the CRS your coordinates are in; cadkit never guesses one
const doc = read(readFileSync("surfaces.dxf")); // 3D faces or polygonsconst { xml, report } = JSON.parse(doc.toCityGmlWithReport(CRS, 1, false));doc.free();console.log(report.geometry_entities, "of", report.entities, "entities written as geometry");writeFileSync("model.gml", xml);
const native = readCityGml(readFileSync("model.gml"));console.log(native.validate()); // structural and geometric checks; returns countersconst preflight = native.preflightTkgm("city-model-tender"); // local structural checks onlyconsole.log("acceptance_verified:", preflight.acceptance_verified); // always falsefor (const issue of preflight.issues) console.log(issue.severity, issue.code, issue.field);native.free();#include <stdio.h>#include <string.h>#include "cadkit.h"
/* The CRS your coordinates are in; cadkit never guesses or transforms one. */#define CRS "urn:ogc:def:crs:EPSG::32635"
int main(void) { cadkit_document *doc = NULL; char *xml = NULL, *native = NULL, *preflight = NULL; int rc = 1; if (cadkit_read_file("surfaces.dxf", NULL, &doc) != CADKIT_OK || cadkit_document_to_citygml(doc, CRS, 1, &xml) != CADKIT_OK) { fprintf(stderr, "%s\n", cadkit_last_error_message()); goto done; } FILE *out = fopen("model.gml", "wb"); if (out) { fputs(xml, out); fclose(out); } /* Native CityGML as editable JSON, then the local structural TKGM preflight. */ if (cadkit_citygml_read_json((const uint8_t *)xml, strlen(xml), NULL, &native) == CADKIT_OK && cadkit_citygml_preflight_tkgm(native, "city-model-tender", &preflight) == CADKIT_OK) { printf("%s\n", preflight); /* "acceptance_verified": false, issues, unchecked rules */ rc = 0; } else { fprintf(stderr, "%s\n", cadkit_last_error_message()); }done: cadkit_string_free(preflight); cadkit_string_free(native); cadkit_string_free(xml); cadkit_document_free(doc); return rc;}The example CRS identifier is a placeholder: use the one your survey or model is in.
From the shell
Section titled “From the shell”cadkit convert surfaces.dxf model.gml --crs urn:ogc:def:crs:EPSG::32635 --lod 1cadkit validate-gml model.gml > validation.jsoncadkit validate-gml model.gml --tkgm-profile city-model-tender > preflight.json \ || echo "preflight reported issues; see preflight.json"The TKGM preflight
Section titled “The TKGM preflight”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.