GMLAS - Mapping examples

This page gives a few examples of how XML constructs are mapped to OGR layers and fields by the GMLAS driver.

SchemaDocumentOGR layersComments
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="MyFeature">
  <complexType>
    <sequence>
        <element name="name" type="string"/>
    </sequence>
    <attribute name="id" type="ID" use="required"/>
    <attribute name="attr" type="string"/>
  </complexType>
</element>
</schema>
<MyFeature id="my_id" attr="attr_value">
    <name>my_name</name>
</MyFeature>
Layer name: MyFeature
Geometry: None
id: String (0.0) NOT NULL
attr: String (0.0)
name: String (0.0) NOT NULL
OGRFeature(MyFeature):1
  id (String) = my_id
  attr (String) = attr_value
  name (String) = my_name
Element with attributes and sub-elements of simple type and maximum cardinality of 1.
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="MyFeature">
  <complexType>
    <sequence>
        <element name="str_array" type="string"
                 maxOccurs="2"/>
        <element name="dt_array" type="dateTime"
                 maxOccurs="unbounded"/>
    </sequence>
    <attribute name="id" type="ID" use="required"/>
  </complexType>
</element>
</schema>
<MyFeature id="my_id">
    <str_array>first string</str_array>
    <str_array>second string</str_array>
    <dt_array>2016-09-24T15:31:00Z</dt_array>
    <dt_array>2016-09-24T15:32:00Z</dt_array>
</MyFeature>
Layer name: MyFeature
Geometry: None
id: String (0.0) NOT NULL
str_array: StringList (0.0) NOT NULL
OGRFeature(MyFeature):1
  id (String) = my_id
  str_array (StringList) = 
    (2:first string,second string)

Layer name: MyFeature_dt_array
Geometry: None
ogr_pkid: String (0.0) NOT NULL
parent_id: String (0.0) NOT NULL
value: DateTime (0.0)
OGRFeature(MyFeature_dt_array):1
  ogr_pkid (String) = my_id_dt_array_1
  parent_id (String) = my_id
  value (DateTime) = 2016/09/24 15:31:00+00

OGRFeature(MyFeature_dt_array):2
  ogr_pkid (String) = my_id_dt_array_2
  parent_id (String) = my_id
  value (DateTime) = 2016/09/24 15:32:00+00
Case of array and child layer
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<element name="MyFeature">
  <complexType>
    <sequence>
      <element name="identifier">
        <complexType>
          <sequence>
            <element name="name">
              <complexType>
                <simpleContent>
                  <extension base="string">
                    <attribute name="lang"
                               type="string"/>
                  </extension>
                </simpleContent>
              </complexType>
            </element>
            <element name="namespace" type="string"
                     minOccurs="0"/>
          </sequence>
        </complexType>
      </element>
    </sequence>
    <attribute name="id" type="ID" use="required"/>
  </complexType>
</element>
</schema>
<MyFeature id="my_id">
    <identifier>
        <name lang="en">my_name</name>
        <namespace>baz</namespace>
    </identifier>
</MyFeature>
Layer name: MyFeature
Geometry: None
id: String (0.0) NOT NULL
identifier_name_lang: String (0.0)
identifier_name: String (0.0)
identifier_namespace: String (0.0)
OGRFeature(MyFeature):1
  id (String) = my_id
  identifier_name_lang (String) = en
  identifier_name (String) = my_name
  identifier_namespace (String) = baz
Case of nested element, that can be folded into main layer. Use of an attribute on a sub-element.
<schema xmlns:myns="http://myns"
        targetNamespace="http://myns"
        elementFormDefault="qualified"
        xmlns="http://www.w3.org/2001/XMLSchema">

<element name="AbstractFeature" abstract="true"/>

<element name="FeatureCollection">
  <complexType><sequence>
      <element ref="myns:AbstractFeature" maxOccurs="unbounded"/>
  </sequence></complexType>
</element>

<complexType name="namesType">
  <sequence>
    <element ref="myns:name" maxOccurs="unbounded"/>
  </sequence>
</complexType>

<element name="MyFeature" substitutionGroup="myns:AbstractFeature">
  <complexType><sequence>
      <element name="names" type="myns:namesType"/>
    </sequence>
    <attribute name="id" type="ID" use="required"/>
  </complexType>
</element>

<element name="MyFeature2" substitutionGroup="myns:AbstractFeature">
  <complexType><sequence>
      <element name="names" type="myns:namesType"/>
    </sequence>
    <attribute name="id" type="ID" use="required"/>
  </complexType>
</element>

<element name="name">
  <complexType><sequence>
      <element name="name" type="string"/>
      <element name="lang" type="string"/>
  </sequence></complexType>
</element>

</schema>
<FeatureCollection xmlns="http://myns">
  <MyFeature id="my_id">
    <names>
        <name>
          <name>name</name>
          <lang>en</lang>
        </name>
        <name>
          <name>nom</name>
          <lang>fr</lang>
        </name>
    </names>
  </MyFeature>
  <MyFeature2 id="my_id2">
    <names>
        <name>
          <name>nom2</name>
          <lang>fr</lang>
        </name>
    </names>
  </MyFeature2>
</FeatureCollection>
Layer name: name
OGRFeature(name):1
  ogr_pkid (String) = _name_1
  name (String) = name
  lang (String) = en

OGRFeature(name):2
  ogr_pkid (String) = _name_2
  name (String) = nom
  lang (String) = fr

OGRFeature(name):3
  ogr_pkid (String) = _name_3
  name (String) = nom2
  lang (String) = fr


Layer name: MyFeature
OGRFeature(MyFeature):1
  id (String) = my_id

Layer name: MyFeature2
OGRFeature(MyFeature2):1
  id (String) = my_id2


Layer name: MyFeature_names_name_name
OGRFeature(MyFeature_names_name_name):1
  occurrence (Integer) = 1
  parent_pkid (String) = my_id
  child_pkid (String) = _name_1

OGRFeature(MyFeature_names_name_name):2
  occurrence (Integer) = 2
  parent_pkid (String) = my_id
  child_pkid (String) = _name_2


Layer name: MyFeature2_names_name_name
OGRFeature(MyFeature2_names_name_name):1
  occurrence (Integer) = 1
  parent_pkid (String) = my_id2
  child_pkid (String) = _name_3

Case of a common element "name" referenced by 2 layers "MyFeature" and "MyFeature1". The links are established through the junction layers "MyFeature_names_name_name" and "MyFeature2_names_name_name".

See Also