Creating and Editing a GML Schema File

FDO API

 
Creating and Editing a GML Schema File
 
 
 

The sample in this section illustrates the creation of a GML schema file containing the definition of an FDO feature schema that contains one feature. The name of this file will have the standard XML schema extension name, .xsd. This means that it contains only one schema and that the root element is xs:schema. The ReadXml() method will take a filename argument whose extension is either .xsd or .xml. In the latter case, the file could contain many schema definitions. If it does, each schema is contained in an xs:schema element, and all xs:schema elements are contained in the fdo:DataStore element. If there is only one schema in the .xml file, then the fdo:DataStore element is not used, and the root element is xs:schema.

You may want to validate the schema that you create. To do so, you must include the optional xs:import line specified in the GML schema fragment for FeatureSchema.

The sample feature implements a table definition for the Buildings feature in the Open GIS Consortium document 98-046r1. This table definition is expressed in an XML format on page 14 of the document and is reproduced as follows:

<ogc-sfsql-table>
  <table-definition>
    <name>buildings</name>
    <column-definition>
      <name>fid</name>
      <type>INTEGER</type>
      <constraint>NOT NULL</constraint>
      <constraint>PRIMARY KEY</constraint>
    </column-definition>
    <column-definition>
      <name>address</name>
      <type>VARCHAR(64)</type>
    </column-definition>
    <column-definition>
      <name>position</name>
      <type>POINT</type>
    </column-definition>
    <column-definition>
      <name>footprint</name>
      <type>POLYGON</type>
    <column-definition>
  </table-definition>

Add GML for the FDO Feature Schema

Start with the skeleton GML for an FDO Feature Schema with the <MetaData> reference replaced by the valid pattern:

<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”
  targetNamespace=”http://<customer_url>/<FeatureSchemaName>”
  xmlns:fdo=”http://fdo.osgeo.org/schema”
  xmlns:gml=”http://www.opengis.net/gml”
  xmlns:<FeatureSchemaName>=”http://<customer_url>/<FeatureSchemaName>”
  elementFormDefault=”qualified”
  attributeFormDefault=”unqualified”
>
  <xs:annotation>
    <xs:documentation>
      {description arg to static FdoFeatureSchema::Create()}
    </xs:documentation>
  </xs:annotation>
  { <one xs:element and/or xs:complexType per class> }
</xs:schema>

For <customer_url> substitute “fdo_customer”. For <FeatureSchemaName> substitute “OGC980461FS”, and for {description arg ... } substitute “OGC Simple Features Specification for SQL.”

Add GML for an FDO Feature Class

Start with the GML that is already written and add the skeleton for an FDO Feature Class, which includes the skeleton for a class definition with identity properties. The <MetaData> is replaced with the valid pattern.

<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”
  targetNamespace=”http://fdo_customer/OGC980461FS”
  xmlns:fdo=”http://fdo.osgeo.org/schema”
  xmlns:gml=”http://www.opengis.net/gml”
  xmlns:OGC980461FS=”http://fdo_customer/OGC980461FS”
  elementFormDefault=”qualified”
  attributeFormDefault=”unqualified”
>
  <xs:annotation>
    <xs:documentation>OGC Simple Features Specification for
      SQL</xs:documentation>
  </xs:annotation>
  <xs:element name=”<className>”
    type=”<className>Type”
    abstract=”<true | false>”
    substitutionGroup=”gml:_Feature”
  >
    <xs:key name=”<className>Key”>
      <xs:selector xpath=”.//<className>”/>
      <xs:field xpath=”<identityProperty1Name>”/>
    </xs:key>
  </xs:element>
  <xs:complexType name=”<className>Type”
    abstract=”<true | false>”/>
    fdo:geometryName=”<geometryPropertyName>”
    fdo:geometricTypes=”<list of FdoGeometricTypes>”
    fdo:geometryReadOnly=”<true | false>”
    fdo:hasMeasure=”<true | false>”
    fdo:hasElevation=”<true | false>”
    fdo:srsName=”<spatialContextName>”/>
  >
    <xs:annotation>
      <xs:documentation>{description arg to static
        FdoFeatureClass::Create()}</xs:documentation>
      <xs:appinfo source=”<uri>”/>
      <xs:documentation>{description arg to static
        FdoGeometricPropertyDefinition::Create()}
      </xs:documentation>
    </xs:annotation>
    <xs:complexContent>
    <xs:extension base=”{baseClass} ?
      {baseClass.schema.name}:{baseClass.name} :
      ‘gml:AbstractFeatureType’ “
    >
        <xs:sequence>
          { list of properties; see DataProperty, GeometricProperty }
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>

You can make the following changes:

  • For <className> substitute “buildings”.
  • Set the value of the xs:element abstract attribute to false.
  • For <identityPropertyName> substitute “fid”. A data property whose name is “fid” will be added.
  • Set the value of the xs:complexType abstract attribute to false.
  • For <geometryPropertyName> substitute “footprint”.
  • For <list of FdoGeometricTypes> substitute “surface”.
  • Set the values of fdo:geometryReadOnly, fdo:hasMeasure, and fdo:hasElevation to false.
  • For <spatialContextName> substitute “SC_0”.
  • For {description arg to FdoFeatureClass::Create()} substitute “OGC 98-046r1 buildings”.
  • For <uri> substitute “http://fdo.osgeo.org/schema”.
  • For {description arg to FdoGeometricPropertyDefinition::Create()} substitute “a polygon defines a building perimeter”.
  • This class has no base class so set the value of the xs:extension base attribute to ‘gml:AbstractFeatureType’.

Add GML for Property Definitions

An integer data property whose name is “fid” will be added. This property is already identified as an identity property in the xs:key element. A string data property whose name is “name” and a geometry property whose name is “position” will also be added.

<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”
  targetNamespace=”http://fdo_customer/OGC980461FS”
  xmlns:fdo=”http://fdo.osgeo.org/schema”
  xmlns:gml=”http://www.opengis.net/gml”
  xmlns:OGC980461FS=”http://fdo_customer/OGC980461FS”
  elementFormDefault=”qualified”
  attributeFormDefault=”unqualified”
>
  <xs:annotation>
    <xs:documentation>OGC Simple Features Specification for
    SQL</xs:documentation>
  </xs:annotation>
  <xs:element name=”buildings”
    type=”buildingsType”
    abstract=”false”
    substitutionGroup=”gml:_Feature”
  >
    <xs:key name=”buildingsKey”>
      <xs:selector xpath=”.//buildings”/>
      <xs:field xpath=”fid”/>
    </xs:key>
  </xs:element>
  <xs:complexType name=”buildingsType”
    abstract=”false”/>
    fdo:geometryName=”footprint”
    fdo:geometricTypes=”surface”
    fdo:geometryReadOnly=”false”
    fdo:hasMeasure=”false”
    fdo:hasElevation=”alse”
    fdo:srsName=”SC_0”/>
  >
    <xs:annotation>
      <xs:documentation>OGC 98-046r1 buildings
      </xs:documentation>
      <xs:appinfo source=”http://fdo.osgeo.org/schema”/>
      <xs:documentation>a polygon defines the perimeter of a
        building</xs:documentation>
    </xs:annotation>
    <xs:complexContent>
    <xs:extension base=”gml:AbstractFeatureType“
    >
        <xs:sequence>
          <xs:element name=”<propertyName>”
            type=”<datatype>”
            minOccurs=”{isNullable ? 0 : 1}”
            default=”<defaultValue>”
            fdo:readOnly=”<true | false>”
          >
            <xs:annotation>
              <xs:documentation>{description arg to static
                FdoDataPropertyDefinition::Create()}
                </xs:documentation>
            </xs:annotation>
          </xs:element>
          <xs:element name=”<propertyName>”
            minOccurs=”{isNullable ? 0 : 1}”
            default=”<defaultValue>”
            fdo:readOnly=”<true | false>”
          >
            <xs:annotation>
              <xs:documentation>{description arg to static
                FdoDataPropertyDefinition::Create()}
              </xs:documentation>
            </xs:annotation>
            <xs:simpleType>
              <xs:restriction base=”xs:string”>
                <xs:maxLength value=”<length>”/>
              </xs:restriction>
            </xs:simpleType>
          </xs:element>
          <xs:element name=”<propertyName>”
            ref=”gml:_Geometry”
            fdo:geometryName=”<propertyName>”
            fdo:geometricTypes=”<list of FdoGeometricTypes>”
            fdo:geometryReadOnly=”<true | false>”
            fdo:hasMeasure=”<true | false>”
            fdo:hasElevation=”<true | false>”
            fdo:srsName=”<spatialContextName>”/>
          >
            <xs:annotation>
              <xs:documentation>{description arg to static
                FdoGeometricPropertyDefinition::Create()}
              </xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>

You can make the following changes:

  • For the first data property <propertyName> substitute “fid”.
  • For the first data property <dataType> substitute “fdo:int32”.
  • Do not include the minOccurs or default attributes because the value of minOccurs is 0, which is the default, and there is no <defaultValue>.
  • Set the fdo:readOnly attribute for “fid” to false.
  • Set the content for xs:documentation for “fid” to “feature id”.
  • For the second data property <propertyName> substitute “address”.
  • Do not include the minOccurs or default attributes because the value of minOccurs is 0, which is the default, and there is no <defaultValue>.
  • Set the fdo:readOnly attribute for “name” to false.
  • Set the content for xs:documentation for “address” to “address of the building”.
  • For <length> substitute “64”.
  • For the geometry property <propertyName> substitute “position”.
  • For <list of FdoGeometricTypes> substitute “point”.
  • Set the values of fdo:geometryReadOnly, fdo:hasMeasure, and fdo:hasElevation to false.
  • For <spatialContextName> substitute “SC_0”.
  • For {description arg to FdoGeometricPropertyDefinition::Create()} substitute “position of the building”.

The Final Result

After all the required substitutions, the GML for the schema containing the Buildings feature is as follows:

<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”
  targetNamespace=”http://fdo_customer/OGC980461FS”
  xmlns:fdo=”http://fdo.osgeo.org/schema”
  xmlns:gml=”http://www.opengis.net/gml”
  xmlns:OGC980461FS=”http://fdo_customer/OGC980461FS”
  elementFormDefault=”qualified”
  attributeFormDefault=”unqualified”
>
  <xs:annotation>
    <xs:documentation>OGC Simple Features Specification for
      SQL</xs:documentation>
  </xs:annotation>
  <xs:element name=”buildings”
    type=”buildingsType”
    abstract=”false”
    substitutionGroup=”gml:_Feature”
  >
    <xs:key name=”buildingsKey”>
      <xs:selector xpath=”.//buildings”/>
      <xs:field xpath=”fid”/>
    </xs:key>
  </xs:element>
  <xs:complexType name=”buildingsType”
    abstract=”false”/>
    fdo:geometryName=”footprint”
    fdo:geometricTypes=”surface”
    fdo:geometryReadOnly=”false”
    fdo:hasMeasure=”false”
    fdo:hasElevation=”false”
    fdo:srsName=”SC_0”/>
  >
    <xs:annotation>
      <xs:documentation>OGC 98-046r1 buildings
      </xs:documentation>
      <xs:appinfo source=”http://fdo.osgeo.org/schema”/>
      <xs:documentation>a polygon defines the perimeter of a
        building</xs:documentation>
    </xs:annotation>
    <xs:complexContent>
    <xs:extension base=”gml:AbstractFeatureType“
    >
        <xs:sequence>
          <xs:element name=”fid”
            type=”fdo:int32”
            fdo:readOnly=”false”
          >
            <xs:annotation>
              <xs:documentation>feature id
              </xs:documentation>
            </xs:annotation>
          </xs:element>
          <xs:element name=”address”
            fdo:readOnly=”false”
          >
            <xs:annotation>
              <xs:documentation>address of the building
              </xs:documentation>
            </xs:annotation>
            <xs:simpleType>
              <xs:restriction base=”xs:string”>
                <xs:maxLength value=”64”/>
              </xs:restriction>
            </xs:simpleType>
          </xs:element>
          <xs:element name=”position”
            ref=”gml:_Geometry”
            fdo:geometryName=”position”
            fdo:geometricTypes=”point”
            fdo:geometryReadOnly=”false”
            fdo:hasMeasure=”false”
            fdo:hasElevation=”false”
            fdo:srsName=”SC_0”/>
          >
            <xs:annotation>
              <xs:documentation>position of the building</xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>