模式管理

 

本节将阐述如何创建和使用模式,并将解释一些模式管理相关的问题,例如如何使用FDO要素模式来描述空间要素。

1.1.1        模式概述

FDO要素模式提供了一种对空间要素的逻辑描述机制,而FDO Provider负责将要素模式映射为底层的物理数据结构。要素模式是空间要素数据的逻辑视图,它完全独立于数据存储,一切FDO中的数据操作都是针对逻辑要素模式中定义的类以及关系。FDO要素模式在某种程度上是基于OpenGISISO要素模型的子集的,它既可以描述非空间要素,也可以描述空间要素。

1)  基本属性(Base Properties

基本属性是在FDO API或某个FDO Provider中预定义的属性,要素模式中的所有类都支持基本属性,例如模式中所有的类都有“ClassName”和“SchemaName”两个基本属性。92列出了FDO API中预定义的基本属性。

 

属性名

是否必须

描述

SchemaName

类实例所属的模式名,只读字符串属性。

ClassName

实例的类名,只读字符串属性。

RevisionNumber

实例的修订号,只读64位整型属性。有些Provider用该属性来支持乐观锁。

92 FDO API预定义的基本属性

 

2)  模式间的交叉引用(Cross-Schema References

一些FDO Provider支持多个模式,于是就引出了模式间交叉引用的概念,对于这些Provider一个模式中的类可以是从另一个模式中的类继承而来的,关联于另一个模式中的类,或者包含了一个基于另一个模式中的类的对象属性。

3)  模式类导航(Parenting in the Schema Classes

FDO API定义的要素模式对象模型支持完全导航,也就是说,从任何一个FdoFeatureSchema对象的模式元素都就可以向上导航到该对象的根节点,而从根节点也可以向下导航到任何要素模式元素。这个功能是在FdoSchemaElement抽象基类中定义的。要实现完全导航,就要求子元素在插入到父元素时记录父元素的ID

4)  物理映射(Physical Mappings

每个要素Provider都要负责逻辑要素模式和物理存储之间的物理映射,其中一些Provider甚至要对映射提供多级别的控制,例如基于RDBMS的要素Provider可能会允许用户为类和属性指定表名和列名。由于各个Provider的映射差别很大,于是FDO API提供了一些接口,由每个Provider分别实现这些接口。这些类有FdoPhysicalSchemaMappingFdoPhysicalClassMappingFdoPhysicalPropertyMappingFdoPhysicalElementMapping

1.1.2        模式的组成

FDO使用类FdoFeatureSchema表示一个模式,FdoClass表示一个类,FdoFeatureClass表示一个要素类。每个模式由一个或多个类或要素类组成,类用于表示非空间数据,要素类用于表示空间数据。每个类和要素类由一个或多个属性组成,要素类必须有一个几何属性。

对于大部分Provider说来,每个类和要素类需要有一个关键属性(Identity Property)来加以标识每一个要素,关键属性可以由一个属性或多个属性组成。如果一个类和要素类是从某个类或要素类继承而来,关键属性只能在基类中定义,子类的关键属性只能从基类中继承而来。也就是说,任何一个有父类的类或要素类都不能设置关键属性

 FDO Schema Element Class Diagram

93 FDO模式元素类图

1.1.3        模式的使用

模式管理主要包括模式的创建、模式的描述和模式的修改三种操作。

1)  创建模式

以下是创建模式所需的基本步骤(其中一些步骤可以省略,也有一些步骤之间可以交换顺序):

l  调用FdoFeatureSchema::Create("SchemaName", "FeatureSchemaDescription")方法创建一个模式。

l  调用FdoFeatureSchema::GetClasses()方法得到一个类的集合。

l  调用FdoClass::Create("className","classDescription")或者FdoFeatureClass::Create(

"className","classDescription")方法得到FdoClassFdoFeatureClass类的实例。

l  调用FdoClassCollection::Add(class)方法将FdoClassFdoFeatureClass类的实例加入到GetClasses()得到的类的集合中。

l  调用FdoGeometricPropertyDefinition::Create("name","Description")方法来创建FdoGeometryProperty的实例。

l  调用FdoDataPropertyDefinition::Create("name","Description")方法来创建FdoDataProperty的实例。

l  调用FdoObjectPropertyDefinition::Create("name","Description")方法来创建FdoObjectProperty的实例。

l  调用FdoClassDefinition::GetProperties()Add(property)方法把以上的属性实例加入到类定义中。

l  调用FdoClassDefinition::GetIdentityProperties()Add(Property)方法来添加FdoClassFdoFeatureClassID

l  调用FdoIApplySchemaCommand::SetFeatureSchema(featureSchema)方法为IFdoApplySchemaCommand设置模式对象。

l  FdoAssociationPropertydefinition类描述两类之间的关系,当然,类已经在要素模式中定义并且不能是抽象类。

l  最后调用FdoIApplySchemaCommand::Execute()方法来应用对要素schema的改动。

2)  描述模式

为了得到现存模式的信息,可以调用FdoIDescribeSchema::Execute()方法得到一个FdoFeatureSchemaCollection实例,它包含了Data Store中的所有FdoFeatureSchema,并且可以通过它得到包括FdoFeatureSchemaFdoClassFdoFeatureClass在内的任何模式对象,以及它们各自的属性。以下方法返回能够得到模式对象信息的主要集合:

l  FdoFeatureSchema::GetClasses()方法得到FdoFeatureClasses

l  FdoClassDefinition::GetProperties()方法得到FdoPropertyDefinitionCollection

l  FdoClassDefinition::GetBaseProperties()方法得到从基类继承而来的FdoPropertyDefinitionCollection

3)  修改模式

在修改模式前,一般会通过描述模式先得到一个FdoFeatureSchemaCollection实例,然后再修改此实例,最后调用方法FdoIApplySchema::Execute()

插入操作非常简单,只需要把模式元素插入到相应的集合。删除操作可以通过如下任意一种办法:

l  调用方法FdoSchemaElement::Delete(),该方法只是把元素做一个删除标记,当该修改被接受(一般是通过FdoIApplySchema)时才真正删除掉。

l  调用FdoSchemaCollection::Remove()FdoSchemaCollection::RemoveAt()方法从相应的集合删除元素。

模式元素都有一个状态标记,该标记可以通过调用FdoSchemaElement::GetElementState()得到。状态不能直接设置,它只能随着以下的操作而改变:

l  Unchanged:当schema原型通过FdoIDescribeSchema得到时,所有的元素被初始化为Unchanged状态。

l  Detached:调用特有集合的删除元素操作,该元素将被标记为Detached

l  Deleted:调用元素的Delete()方法把该元素标记为Deleted

l  Added:把元素添加到一个集合,该元素将被标记为Added

l  Modified:当添加或删除一个元素的子元素,该元素将被标记为Modified。另外,一旦一个元素被标记为Modified,那么包含它的元素也要被标记为Modified。例如,SchemaAttributeDictionary中的“Class3”元素添加了一个新值,那么SchemaAttributeDictionary和“Class3”元素都将被标记为Modified

状态标记一直保留到改动被接受为止,也就是说,保留到执行了IApplySchema为止。此时,所有标记为Deleted的元素都将被清除,而所有其他元素都将被标记为Unchanged

FdoFeatureSchema的回滚机制可以让模式返回到上一次接受变动的状态。例如,一个原型通过FdoIDescribeSchema做了添加类,删除属性等操作,所有这些操作都将通过调用FdoFeatureSchema::RejectChanges()方法被拒绝,所有元素的状态又重新被标记为Unchanged。该方法的相反操作是FdoFeatureSchema::AcceptChanges(),一般情况下,该方法只有在FDO Provider在执行FdoIApplySchema::Execute()命令时才被调用到。

1.1.4        FDO XML格式

FDO支持使用GMLGeography Markup Language)格式的描述模式。GML(Geography Markup Language)即地理标识语言,是一种使用XML语法描述地理空间要素的标记语言,它由OGC1999年提出,它由OGC1999年提出,并得到了许多公司的大力支持。

FdoFeatureSchemaFdoFeatureSchemaCollection两个类都实现了FdoXmlSerializable接口,这意味着FDO模式可以写入到一个GML格式XML文件;FdoFeatureSchemaCollection还实现了FdoXmlDeserializable接口,这意味着也可以从一个GML格式XML文件得到FDO模式。

在指定模式覆盖时,往往需要手工编写GML格式XML文件指定模式和模式覆盖,这时我们必须了解GML的语法。 93显示了FDO模式元素和GML元素之间的对应关系,其中使用双引号括起来的尖括号部分的内容和使用花括号括起来的内容代表需要用户替换的内容。

 

FDO模式元素

GML模式片段

FeatureSchema

<xs:schema xmlns:xs=“http://www.w3.org/2001/XMLSchema”

targetNamespace=“http://<customer_url>/<FeatureSchemaName>

xmlns:fdo=“http://fdo.osgeo.org/isd/schema”

xmlns:gml=“http://www.opengis.net/gml”

xmlns:<FeatureSchemaName>=“http://<customer_url>/<FeatureSchemaName>

elementFormDefault=“qualified”

attributeFormDefault=“unqualified”>

{ 可选元素 xs:import 元素用来使schema生效

<xs:import namespace=“http://fdo.osgeo.org/schema”

schemaLocation=“<FDO SDK安装位置>/docs/XmlSchema/FdoDocument.xsd”/> }

{<每个schema中只能有一个 xs:element / xs:complexType >}

</xs:schema>

ClassDefinition

(带有主键属性)

<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:field xpath=“...”/>

<xs:field xpath=“<identityProperty<n>Name>

</xs:key>

</xs:element>

FeatureClass

<xs:element ...请参考 ClassDefinition (带有主键属性)...

</xs:element>

<xs:complexType name=“<className>Type”

abstract=“<true | false>“/>

{ 请参考FeatureClass.GeometryProperty }

<xs:complexContent>

<xs:extension base=“{baseClass}?{baseClass.schema.name}:{baseClass.name} :

‘gml:AbstractFeatureType’ “

<xs:sequence>

{属性列表请参考DataPropertyGeometric属性}

</xs:sequence>

</xs:extension>

</xs:complexContent>

</xs:complexType>

FeatureClass. GeometryProperty

<!--这些是xs:complexType元素的属性-->

fdo:geometryName=“<geometryPropertyName>

fdo:geometricTypes=“<list of FdoGeometricTypes>

fdo:geometryReadOnly=“<true | false>

fdo:hasMeasure=“<true | false>

fdo:hasElevation=“<true | false>

fdo:srsName=“<spatialContextName>“/>

DataProperty

(decimalstring类型)

<!--minOccurs属性仅当值是1的时候才生成;Default属性仅当存在默认值时才生成;fdo:readOnly属性仅当值是1的时候才生成。-->

<xs:element name=“<propertyName>

minOccurs=“{isNullable ? 0 : 1}

default=“<defaultValue>

fdo:readOnly=“<true | false>“>

<xs:simpleType>

{请参考 DataType StringDataType Decimal }

</xs:simpleType>

</xs:element>

DataProperty (其他类型)

<xs:element name=“<propertyName>

type=“<datatype>

minOccurs=“{isNullable ? 0 : 1}

default=“<defaultValue>

fdo:readOnly=“<true | false>“>

</xs:element>

DataType String

<xs:restriction base=“xs:string”>

<xs:maxLength value=“<length>“/>

</xs:restriction>

DataType Decimal

<xs:restriction base=“xs:decimal”>

<xs:totalDigits value=“<precision>“/>

<xs:fractionDigits value=“<scale>“/>

</xs:restriction>

GeometricProperty

 

<xs:element name=“<propertyName>

type=“gml:AbstractGeometryType”

fdo:geometryName=“<propertyName>

fdo:geometricTypes=“<list of FdoGeometricTypes>

fdo:geometryReadOnly=“<true | false>

fdo:hasMeasure=“<true | false>

fdo:hasElevation=“<true | false>

fdo:srsName=“<spatialContextName>“/>

</xs:element>

MetaData

<!--xs:schema元素中为FeatureSchema引用的模式-->

<xs:annotation>

<xs:documentation>

{FdoFeatureSchema::Create()的描述}

</xs:documentation>

</xs:annotation>

<!--xs:schema元素中为DataProperty引用的样式-->

<xs:annotation>

<xs:documentation>

{FdoDataPropertyDefinition::Create()的描述}

</xs:documentation>

</xs:annotation>

<!--xs:element元素为非要素GeometricProperty引用的模式-->

<xs:annotation>

<xs:documentation>

{FdoGeometricPropertyDefinition::Create()的描述}

</xs:documentation>

</xs:annotation>

<!--xs:complexType元素为FeatureClass引用的样式-->

<xs:annotation>

<xs:documentation>

{FdoFeatureClass::Create()的描述}

</xs:documentation>

<xs:appinfo source=“<uri>“/>

<xs:documentation>

{FdoGeometricPropertyDefinition::Create()的描述}

</xs:documentation>

</xs:annotation>

93 FDO模式元素和GML模式片段的对应关系

 

94显示了Map FDO数据类型和GML数据类型对照关系。

 

FDO数据类型

GML数据类型

Boolean

xs:boolean

Byte

fdo:Byte

DateTime

xs:dateTime

Double

xs:double

Int16

fdo:Int16

Int32

fdo:Int32

Int64

fdo:Int64

Single

xs:float

BLOB

xs:base64Binary

CLOB

xs:string

94 FDO数据类型和GML数据类型对照表

1.1.5        GML 模式文件的创建

以下示例为“Buildings”要素定义了一个表格,这是Open GIS联盟的文档98-046r1中的一个示例。本节中,我们将通过为要素类“Buildings”创建GML模式文件来展示如何创建GML模式文件。

<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>

1.1.5.1  添加模式

让我们从一个基本的GML框架开始添加一个模式。

<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>{FdoFeatureSchema::Create()的描述}</xs:documentation>

  </xs:annotation>

  {<每个中只能有一个 xs:element / xs:complexType >}

</xs:schema>

通过如下的替换,可以设置要素模式的名称和描述。

l  fdo_customer代替“<customer_url>”。

l  OGC980461FS代替“<FeatureSchemaName>”,从而设置要素模式名称。

l  设置要素模式描述:用OGC Simple Features Specification for SQL 代替“{FdoFeatureSchema::Create()的描述}”,从而设置要素模式描述。

1.1.5.2  添加要素类

在以上GML模式的基础上,让我们接着添加一个要素类。

<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=“<identityPropertyName>“/>

    </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>

        {FdoFeatureClass::Create()的描述}

      </xs:documentation>

      <xs:appinfo source=“<uri>“/>

      <xs:documentation>

        {FdoGeometricPropertyDefinition::Create()的描述}

      </xs:documentation>

    </xs:annotation>

    <xs:complexContent>

      <xs:extension base=“{baseClass} ? {baseClass.schema.name}:{baseClass.name} : ‘gml:AbstractFeatureType’ “>

        <xs:sequence>

          {属性类表;请参考 DataProperty, GeometricProperty}

        </xs:sequence>

      </xs:extension>

    </xs:complexContent>

  </xs:complexType>

</xs:schema>

通过如下的替换,可以添加一个要素类,并且设置了这个要素类的几何属性和主键属性。

l  buildings代替“<className>”,从而设置要素类的名称:。

l  将“xs:element”元素的“abstract”属性置为“false”。

l  fid代替“<identityPropertyName>”,从而设置要素类的主键属性名称。

l  将“xs:complexType”元素的“abstract”属性置为false

l  footprint代替“<geometryPropertyName>”,从而设置要素类的几何属性名称。

l  surface代替“<list of FdoGeometricTypes>”,从而设置几何属性的类型。

l  将“fdo:geometryReadOnly”,“fdo:hasMeasure”和“fdo:hasElevation”都置为“false

l  SC_0代替“<spatialContextName>,从而设置要素相关联的空间上下文。

l  OGC 98-046r1 buildings代替“{FdoFeatureClass::Create()的描述},从而设置要素类的描述。

l  用“http://fdo.osgeo.org/schema代替“<uri>

l  a polygon defines a building perimeter代替“{FdoGeometricPropertyDefinition::Create()的描述}”,从而设置几何属性的描述。

l  该类不存在基类,因此将“xs:extension元素的“base属性置为‘gml:AbstractFeatureType’。

1.1.5.3  添加属性

在以上GML模式的基础上,我们再为要素类添加一个名为fid的整型数据属性,它已经作为关键属性加入到xs:key元素中了,还将添加名为name的数据属性,以及一个名为position的几何属性。

<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>

                {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>

                {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>

                {FdoGeometricPropertyDefinition::Create()的描述}

              </xs:documentation>

            </xs:annotation>

          </xs:element>

        </xs:sequence>

      </xs:extension>

    </xs:complexContent>

</xs:complexType>

</xs:schema>

l  fid代替第一个“<propertyName>”,从而设置数据属性fid

l  fdo:int32代替“<dataType>”,从而设置数据属性fid的数据类型。

l  不必添加“minOccurs”和“default”属性,因为“minOccurs”的值就是默认值0,也没有“<defaultValue>”。

l  fid属性的“fdo:readOnly”置为“false”。

l  fid属性的“xs:documentation”内容置为feature id

l  address代替第二个“<propertyName>”,从而设置数据属性address

l  不必添加“minOccurs”和“default”属性,因为“minOccurs”的值就是默认值0,也没有“<defaultValue>”。

l  address属性的“fdo:readOnly”置为“false”。

l  address属性的“xs:documentation”内容置为address of the building

l  64代替“<length>”,从而设置数据属性address最大长度。

l  position代替第三个“<propertyName>”,从而设置几何属性position

l  point代替“<list of FdoGeometricTypes>”,从而设置几何属性position的几何类型。

l  将“fdo:geometryReadOnly”,“fdo:hasMeasure”和“fdo:hasElevation”置为“false”。

l  SC_0代替“<spatialContextName>”,从而设置几何属性position关联的空间上下文。

l  position of the building代替“{FdoGeometricPropertyDefinition::Create()的描述}”,从而设置几何属性position的描述。

1.1.5.4  最终结果

最终得到的包含Buildings要素的模式为:

<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>

1.1.6        模式管理示例

1.1.6.1  创建要素模式

该示例创建一个名为“SampleFeatureSchema”的FdoFeatureSchema对象,该对象定义了一个包含三个属性的类。该类和属性源自Open GIS联盟的文档98-046r110页,它定义了一个“Lakes”(湖)要素类。

<ogc-sfsql-table>

  <table-definition>

    <name>lakes</name>

    <column-definition>

      <name>fid</name>

      <type>INTEGER</type>

      <constgraint>NOT NULL</constraint>

      <constraint>PRIMARY KEY<constraint>

    </column-definition>

    <column-definition>

      <name>name</name>

      <type>VARCHAR(64)</type>

    </column-definition>

    <column-definition>

      <name>shore</name>

      <type>POLYGON</type>

    </column-definition>

  </table-definition>

表“lakes”对应于名为“SampleFeatureClass”的FdoFeatureClass对象。列“fid”对应于名为“SampleIdentityDataProperty”的FdoDataPropertyDefinition对象;列“name”对应于名为“SampleNameDataProperty”的FdoDataPropertyDefinition对象;列“shore”对应于名为“SampleGeometricProperty”的FdoGeometricPropertyDefinition对象。

// 创建ApplySchema命令

FdoPtr<FdoIApplySchema> sampleApplySchema = (FdoIApplySchema *)

connection->CreateCommand(FdoCommandType_ApplySchema);

// 创建要素schema

FdoPtr<FdoFeatureSchema> sampleFeatureSchema =

FdoFeatureSchema::Create(L"SampleFeatureSchema", L"要素模式描述");

// 得到指向要素模式中类集合的指针,该指针用来向模式中加入类。

FdoPtr<FdoClassCollection> sampleClassCollection = sampleFeatureSchema->GetClasses();

// 创建一个要素类。例如,一个包含一个几何(geometric)属性的要素类

FdoPtr<FdoFeatureClass> sampleFeatureClass =

FdoFeatureClass::Create(L"SampleFeatureClass", L"要素类描述");

sampleFeatureClass->SetIsAbstract(false);

// 得到指向要素类中属性集合的指针,该指针用来向类中加入数据和其他属性。

FdoPtr<FdoPropertyDefinitionCollection> sampleFeatureClassProperties =

sampleFeatureClass->GetProperties();

// 得到指向要素模式中类集合的指针,该指针用来向模式中加入类。

FdoPtr<FdoClassCollection> sampleClassCollection = sampleFeatureSchema->GetClasses();

// 得到指向要素类关键属性集合的指针,该指针用来向要素类中加入主键属性。

FdoPtr<FdoDataPropertyDefinitionCollection> sampleFeatureClassIdentityProperties =

sampleFeatureClass->GetIdentityProperties();

// 创建一个Int32类型的数据属性,并将其设置为主键属性

FdoPtr<FdoDataPropertyDefinition> sampleIdentityDataProperty =

FdoDataPropertyDefinition::Create(L"SampleIdentityDataProperty",

L"关键数据属性描述");

sampleIdentityDataProperty->SetDataType(FdoDataType_Int32);

sampleIdentityDataProperty->SetReadOnly(false);

sampleIdentityDataProperty->SetNullable(false);

sampleIdentityDataProperty->SetIsAutoGenerated(false);

// sampleFeatureClass中加入关键属性

sampleFeatureClassProperties->Add(sampleIdentityDataProperty);

sampleFeatureClassIdentityProperties->Add(sampleIdentityDataProperty);

// 创建一个String类型的数据属性

FdoPtr<FdoDataPropertyDefinition> sampleNameDataProperty =

FdoDataPropertyDefinition::Create(L"SampleNameDataProperty", L"数据属性描述");

sampleNameDataProperty->SetDataType(FdoDataType_String);

sampleNameDataProperty->SetLength(64);

sampleNameDataProperty->SetReadOnly(false);

sampleNameDataProperty->SetNullable(false);

sampleNameDataProperty->SetIsAutoGenerated(false);

// 添加名称属性到sampleFeatureClass

sampleFeatureClassProperties->Add(sampleNameDataProperty);

// 创建一个几何属性

FdoPtr<FdoGeometricPropertyDefinition> sampleGeometricProperty =

FdoGeometricPropertyDefinition::Create(L"SampleGeometricProperty", L"几何属性描述");

sampleGeometricProperty->SetGeometryTypes(FdoGeometricType_Surface);

sampleGeometricProperty->SetReadOnly(false);

sampleGeometricProperty->SetHasMeasure(false);

sampleGeometricProperty->SetHasElevation(false);

// 添加几何属性到sampleFeatureClass

sampleFeatureClassProperties->Add(sampleGeometricProperty);

// 将其标记为几何属性

sampleFeatureClass->SetGeometryProperty(sampleGeometricProperty);

// 将要素类添加到schema

sampleClassCollection->Add(sampleFeatureClass);

// ApplySchema命令指定新建的模式,并且执行此命令

sampleApplySchema->SetFeatureSchema(sampleFeatureSchema);

sampleApplySchema->Execute();

1.1.6.2  描述和导出模式

以下示例代码展示了如何描述一个模式并把它导出到XML文件。

// 创建DescribeSchema命令

FdoPtr<FdoIDescribeSchema> sampleDescribeSchema = (FdoIDescribeSchema *)

connection->CreateCommand(FdoCommandType_DescribeSchema);

// 执行DescribeSchema命令将得到Data Store中所有要素模式的集合

FdoPtr<FdoFeatureSchemaCollection> sampleFeatureSchemaCollection =

sampleDescribeSchema->Execute();

// 从集合中找出想要导出的要素模式,然后将其写入XML文件,最后清空集合

sampleFeatureSchema =

sampleFeatureSchemaCollection->FindItem(LSampleFeatureSchema);

sampleFeatureSchema->WriteXml(L"SampleFeatureSchema.xml");

sampleFeatureSchemaCollection->Clear();

以下是在调用FdoFeatureSchema::WriteXml(...)方法后导出的XML文件的内容。

<?xml version="1.0" encoding="UTF-8" ?>

  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

    targetNamespace="http://fdo_customer/SampleFeatureSchema"

    xmlns:fdo="http://fdo.osgeo.org/schema"

    xmlns:gml="http://www.opengis.net/gml"

    xmlns:SampleFeatureSchema="http://fdo_customer/

      SampleFeatureSchema"

    elementFormDefault="qualified"

    attributeFormDefault="unqualified">

  <xs:annotation>

    <xs:documentation>Sample Feature Schema Description

      </xs:documentation>

    <xs:appinfo source="http://fdo.osgeo.org/schema" />

  </xs:annotation>

  <xs:element name="SampleFeatureClass"

    type="SampleFeatureSchema:SampleFeatureClassType"

    abstract="false" substitutionGroup="gml:_Feature">

    <xs:key name="SampleFeatureClassKey">

      <xs:selector xpath=".//SampleFeatureClass" />

      <xs:field xpath="SampleIdentityDataProperty" />

    </xs:key>

  </xs:element>

  <xs:complexType name="SampleFeatureClassType"

    abstract="false"

    fdo:geometryName="SampleGeometricProperty"

    fdo:hasMeasure="false"

    fdo:hasElevation="false"

    fdo:srsName="SC_0"

    fdo:geometricTypes="surface">

    <xs:annotation>

      <xs:documentation>Sample Feature Class Description

      </xs:documentation>

      <xs:appinfo source="http://fdo.osgeo.org/schema" />

      <xs:documentation>Sample Geometric Property Description</xs:documentation>

    </xs:annotation>

    <xs:complexContent>

      <xs:extension base="gml:AbstractFeatureType">

        <xs:sequence>

          <xs:element name="SampleIdentityDataProperty"

            default=""

            type="fdo:int32">

            <xs:annotation>

              <xs:documentation>

                Sample Identity Data Property Description

              </xs:documentation>

            </xs:annotation>

          </xs:element>

          <xs:element name="SampleNameDataProperty"

            default="">

            <xs:annotation>

              <xs:documentation>

                Sample Name Data Property Description

              </xs:documentation>

            </xs:annotation>

            <xs:simpleType>

              <xs:restriction base="xs:string">

                <xs:maxLength value="64" />

              </xs:restriction>

            </xs:simpleType>

          </xs:element>

        </xs:sequence>

      </xs:extension>

    </xs:complexContent>

  </xs:complexType>

</xs:schema>

1.1.6.3  销毁模式

以下示例代码展示了如何销毁一个模式。

// 创建DestroySchema命令

FdoPtr<FdoIDestroySchema> sampleDestroySchema = (FdoIDestroySchema *)

connection->CreateCommand(FdoCommandType_DestroySchema);

// 销毁模式

sampleDestroySchema->SetSchemaName(L"SampleFeatureSchema");

sampleDestroySchema->Execute();

1.1.6.4  XML中读入一个模式

以下示例代码展示了如何从一个XML中读入一个模式。

sampleFeatureSchemaCollection->ReadXml(L"SampleFeatureSchema.xml");

sampleFeatureSchema =

sampleFeatureSchemaCollection->FindItem(L"SampleFeatureSchema");

sampleApplySchema->SetFeatureSchema(sampleFeatureSchema);

sampleApplySchema->Execute();

sampleFeatureSchemaCollection->Clear();

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值