NiVO / BY TECHNOGISGermany · Indonesia
Attribute handoff tutorial

KML SchemaData: Resolve Field Declarations Before Importing a Drone Inventory

Trace a same-document schema reference, pair SimpleData text with its declared field type, and preserve identifier strings before a receiving GIS conversion.

KML SchemaData: Resolve Field Declarations Before Importing a Drone Inventory

Identify the declaration behind a readable attribute

A KML review map can display a familiar asset code while a receiving GIS creates a different-looking attribute table. Before changing the code or re-exporting the map, inspect the relationship between the stored value and its field declaration. KML supports typed custom data through Schema and SchemaData, so the visible text is only part of the handoff. A useful review retains the field name, the schema reference, the declared type, and the original text together. Those details give the receiving team a reproducible starting point for investigating an import difference.

This tutorial uses a constructed attribute-only KML document with a fictional code 007 and a teaching count of 2. It is not a NiVO inspection register, a customer asset, or the output of a real receiving application. The Python exercise resolves a deliberately narrow same-document schema relationship and returns the declaration beside the text. It does not convert the text into the declared numeric type or validate an entire map. Geometry, feature identity, observation meaning, and the behavior of an actual GIS importer remain separate review questions.

Follow SchemaData to the named SimpleField

Google’s KML reference describes Schema as a child of Document that declares custom field names and types using SimpleField elements. SchemaData supplies instances through SimpleData elements and identifies the schema using schemaUrl. A reference beginning with a fragment such as #inspection can identify a schema in the same document; the format also allows references to other KML files or full URLs. The example supports only the same-document form. It never fetches a remote schema or assumes that a missing external dependency has already been resolved.

The SimpleData name identifies the field whose declaration supplies its type. A friendly displayName is optional presentation information and should not replace that machine-facing name in a diagnostic mapping. Keep the declared type separate from the XML text exposed by the parser. A declaration of int does not mean that every parser automatically returns a Python integer, nor does it prove that the supplied text conforms to the declared type. The function below reports the relationship first so that any later lexical validation or conversion can be deliberate and documented.

NiVO VTOL V5 product image showing the fixed wing and vertical-lift rotors
NiVO VTOL V5 product image showing the fixed wing and vertical-lift rotors.Source: NiVO / TechnoGIS catalogue materials supplied by the site owner · Catalogue photo
Product context only; this photograph does not depict the constructed examples in this article.

Inspect a small local schema without coercing its values

The recipe uses ElementTree with an explicit KML namespace mapping. It expects one direct Document, one direct Schema, and one SchemaData group on the demonstrated Placemark path. These are local teaching restrictions, not a claim that all valid KML has this structure. It checks that the fragment reference matches the schema identifier, rejects repeated or incomplete field declarations, and supports string and int declarations for this example. Each SimpleData name must resolve to a declared field, and nested value markup is outside the supported plain-text profile.

Run the constructed document below with Python. The two output rows should identify asset_code as string with text 007, and inspection_count as int with text 2. The quotation marks in Python’s printed representation help show that both values remain text. In particular, the leading zeros in the fictional asset code are preserved. The int declaration is reported rather than enforced: a value such as two would still be returned as text by this resolver and would require a separate type-validation finding. No source file is opened, no GIS import runs, and no derivative is written.

import xml.etree.ElementTree as ET

NS = {"k": "http://www.opengis.net/kml/2.2"}

def declared_values(text):
    root = ET.fromstring(text)
    docs = root.findall("k:Document", NS)
    if root.tag != "{" + NS["k"] + "}kml" or len(docs) != 1:
        raise ValueError("Expected one direct KML Document")
    doc = docs[0]
    schemas = doc.findall("k:Schema", NS)
    groups = doc.findall("k:Placemark/k:ExtendedData/k:SchemaData", NS)
    if len(schemas) != 1 or len(groups) != 1:
        raise ValueError("This profile expects one schema and one data group")
    schema, group = schemas[0], groups[0]
    sid = schema.get("id")
    if not sid or group.get("schemaUrl") != "#" + sid:
        raise ValueError("Unresolved or nonlocal schema reference")
    fields = {}
    for field in schema.findall("k:SimpleField", NS):
        name, kind = field.get("name"), field.get("type")
        if not name or kind not in ("string", "int") or name in fields:
            raise ValueError("Unsupported, incomplete or repeated declaration")
        fields[name] = kind
    rows = []
    for value in group.findall("k:SimpleData", NS):
        name = value.get("name")
        if name not in fields or len(value):
            raise ValueError("Unresolved field or unsupported nested value")
        rows.append((name, fields[name], value.text or ""))
    return rows

# Trusted constructed attributes only, not a complete inspection map.
toy = '''<kml xmlns="http://www.opengis.net/kml/2.2"><Document>
<Schema id="inspection">
  <SimpleField name="asset_code" type="string"/>
  <SimpleField name="inspection_count" type="int"/>
</Schema><Placemark><ExtendedData><SchemaData schemaUrl="#inspection">
  <SimpleData name="asset_code">007</SimpleData>
  <SimpleData name="inspection_count">2</SimpleData>
</SchemaData></ExtendedData></Placemark></Document></kml>'''
for row in declared_values(toy):
    print(row)

Treat unsupported references as unresolved dependencies

If the received SchemaData points to another file or an online URL, do not remove the prefix merely to make it match a local identifier. Identify the actual dependency and the agreed package boundary. Preserve the original reference and obtain the required schema through the project’s authorized receiving process. This small resolver stops outside its same-document profile rather than guessing. A reference that it rejects can still be valid KML; the rejection describes the scope of this exercise. That distinction is useful when communicating an investigation result to the producer.

Likewise, a KML document with several schemas, nested folders, or multiple features needs a reader that handles its actual structure. Do not keep only the first matching element and claim to have checked the complete inventory. Retain feature and schema identity in any expanded review workflow. The recipe deliberately makes its single-group assumption visible so that the demonstration remains inspectable. For actual untrusted or large XML inputs, use the project’s appropriate parsing and resource controls; this in-memory teaching snippet is not offered as a general-purpose ingestion service.

Check the receiving conversion separately from declaration resolution

Once the relationship is resolved, assess the receiving application’s actual field mapping. Record the tool version, import path, chosen layer, and any warnings. Compare the accepted source field names, declared types, and text with the imported representation. A display label may differ from a stored field name, and an importer may apply its own type handling. Do not infer that behavior from this Python result. A successful local reference lookup establishes which declaration belongs to the selected text; it does not establish how another program will represent or validate that text.

Keep lexical type checks, missing values, repeated instance names, required project fields, and asset-identifier uniqueness as separate findings. The resolver preserves ordered rows and does not enforce a complete application schema. It also does not inspect geometry or validate whether the fictional count corresponds to any observation. If a conversion strips zeros from an identifier, investigate that specific mapping against the actual source and intended data contract. Avoid fixing the appearance by silently padding every imported number, because that can create identifiers that were never present in the accepted exchange.

Deliver a field mapping that another reviewer can reproduce

A useful handoff record identifies the unchanged KML, the selected feature or group, the schema identifier and reference, and each field name with its declared type and original text. Attach the actual receiving-side comparison if one was performed. State clearly whether the finding concerns an unresolved dependency, an unsupported teaching profile, a type-value discrepancy, or an importer conversion. Those are different problems with different evidence. Preserve the source and any checked replacement as related revisions instead of rewriting a reference or a field value simply to make a local diagnostic succeed.

For a drone inventory review, this method makes attribute interpretation traceable before the team reconciles records with photographs or spatial features. The same visible text can be described precisely without assuming that a preview balloon is the authoritative data schema. Resolve the declaration, preserve the original text, and test the intended conversion with its own evidence. The result is a more useful question for the producer or receiving analyst, while keeping unsupported claims about real assets, inspection status, and survey acceptance out of a small technical demonstration.

Technical references

  1. Google KML reference: ExtendedData, SchemaData and SimpleData ↗
  2. Google KML reference: Schema field declarations ↗
  3. Python ElementTree: namespace-aware parsing and limited XPath ↗
← All articles

Related articles

All articles ↗
LET’S TAKE FLIGHT

Your next mission
starts with a conversation.

Talk to our team