Example: Creating a Feature Schema
The following sample code creates an FdoFeatureSchema object called “SampleFeatureSchema.” The schema contains one class, which has three properties. The class and its properties conform to the table definition for the Lakes feature in the Open GIS Consortium document 98-046r1. This table definition is expressed in an XML format on page 10 of the document and is reproduced as follows:
<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>
The table definition whose name is “lakes” is mapped to an FdoFeatureClass object called “SampleFeatureClass.” The column definition whose name is “fid” is mapped to an FdoDataPropertyDefinition object called “SampleIdentityDataProperty.” The column definition whose name is “name” is mapped to an FdoDataPropertyDefinition object called “SampleNameDataProperty.” The column definition whose name is “shore” is mapped to an FdoGeometricPropertyDefinition object called “SampleGeometricProperty.”
// Create the ApplySchema command
GisPtr<FdoIApplySchema> sampleApplySchema;
sampleApplySchema = (FdoIApplySchema *)
connection->CreateCommand(FdoCommandType_ApplySchema);
// Create the feature schema
GisPtr<FdoFeatureSchema> sampleFeatureSchema;
sampleFeatureSchema = FdoFeatureSchema::Create(L"SampleFeatureSchema", L"Sample Feature Schema Description");
// get a pointer to the feature schema's class collection
// this object is used to add classes to the schema
GisPtr<FdoClassCollection> sampleClassCollection;
sampleClassCollection = sampleFeatureSchema->GetClasses();
// create a feature class, i.e., a class containing a geometric
// property set some class level properties
GisPtr<FdoFeatureClass> sampleFeatureClass;
sampleFeatureClass = FdoFeatureClass::Create(L"SampleFeatureClass", L"Sample Feature Class Description");
sampleFeatureClass->SetIsAbstract(false);
// get a pointer to the feature class's property collection
// this pointer is used to add data and other properties to the class
GisPtr<FdoPropertyDefinitionCollection> sampleFeatureClassProperties;
sampleFeatureClassProperties = sampleFeatureClass->GetProperties();
// get a pointer to the feature schema's class collection
// this object is used to add classes to the schema
GisPtr<FdoClassCollection> sampleClassCollection;
sampleClassCollection = sampleFeatureSchema->GetClasses();
// get a pointer to the feature class's identity property collection
// this property is used to add identity properties to the feature
// class
GisPtr<FdoDataPropertyDefinitionCollection> sampleFeatureClassIdentityProperties;
sampleFeatureClassIdentityProperties = sampleFeatureClass->GetIdentityProperties();
// create a data property that is of type Int32 and identifies
// the feature uniquely
GisPtr<FdoDataPropertyDefinition> sampleIdentityDataProperty;
sampleIdentityDataProperty = FdoDataPropertyDefinition::Create(L"SampleIdentityDataProperty", L"Sample Identity Data Property Description");
sampleIdentityDataProperty->SetDataType(FdoDataType_Int32);
sampleIdentityDataProperty->SetReadOnly(false);
sampleIdentityDataProperty->SetNullable(false);
sampleIdentityDataProperty->SetIsAutoGenerated(false);
// add the identity property to the sampleFeatureClass
sampleFeatureClassProperties->Add(sampleIdentityDataProperty);
sampleFeatureClassIdentityProperties->Add(sampleIdentityDataProperty);
// create a data property that is of type String and names the
// feature
GisPtr<FdoDataPropertyDefinition> sampleNameDataProperty;
sampleNameDataProperty = FdoDataPropertyDefinition::Create(L"SampleNameDataProperty", L"Sample Name Data Property Description");
sampleNameDataProperty->SetDataType(FdoDataType_String);
sampleNameDataProperty->SetLength(64);
sampleNameDataProperty->SetReadOnly(false);
sampleNameDataProperty->SetNullable(false);
sampleNameDataProperty->SetIsAutoGenerated(false);
// add the name property to the sampleFeatureClass
sampleFeatureClassProperties->Add(sampleNameDataProperty);
// create a geometric property
GisPtr<FdoGeometricPropertyDefinition> sampleGeometricProperty;
sampleGeometricProperty = FdoGeometricPropertyDefinition::Create(L"SampleGeometricProperty", L"Sample Geometric Property Description");
sampleGeometricProperty->SetGeometryTypes(FdoGeometricType_Surface);
sampleGeometricProperty->SetReadOnly(false);
sampleGeometricProperty->SetHasMeasure(false);
sampleGeometricProperty->SetHasElevation(false);
// add the geometric property to the sampleFeatureClass
sampleFeatureClassProperties->Add(sampleGeometricProperty);
// identify it as a geometry property
sampleFeatureClass->SetGeometryProperty(sampleGeometricProperty);
// add the feature class to the schema
sampleClassCollection->Add(sampleFeatureClass);
// point the ApplySchema command at the newly created feature
// schema and execute
sampleApplySchema->SetFeatureSchema(sampleFeatureSchema);
sampleApplySchema->Execute();
Example: Describing a Schema and Writing It to an XML File
The following sample code demonstrates describing a schema and writing it to an XML file:
// create the DescribeSchema command
GisPtr<FdoIDescribeSchema> sampleDescribeSchema;
sampleDescribeSchema = (FdoIDescribeSchema *)
connection->CreateCommand(FdoCommandType_DescribeSchema);
// executing the DescribeSchema command returns a feature
// schema collection that is, the set of feature schema which
// reside in the DataStore
GisPtr<FdoFeatureSchemaCollection> sampleFeatureSchemaCollection;
sampleFeatureSchemaCollection = sampleDescribeSchema->Execute();
// find the target feature schema in the collection, write it
// to an xml file, and clear the collection
sampleFeatureSchema = sampleFeatureSchemaCollection->FindItem(L"SampleFeatureSchema");
sampleFeatureSchema->WriteXml(L"SampleFeatureSchema.xml");
sampleFeatureSchemaCollection->Clear();
The following sample code demonstrates destroying a schema:
// create the DestroySchema command
GisPtr<FdoIDestroySchema> sampleDestroySchema;
sampleDestroySchema = (FdoIDestroySchema *)
connection->CreateCommand(FdoCommandType_DestroySchema);
// destroy the schema
sampleDestroySchema->SetSchemaName(L"SampleFeatureSchema");
sampleDestroySchema->Execute();
Example: Creating a Schema Read In from an XML File
The following sample code demonstrates creating a schema read in from an XML file:
sampleFeatureSchemaCollection->ReadXml(L"SampleFeatureSchema.xml");
sampleFeatureSchema = sampleFeatureSchemaCollection->FindItem(L"SampleFeatureSchema");
sampleApplySchema->SetFeatureSchema(sampleFeatureSchema);
sampleApplySchema->Execute();
sampleFeatureSchemaCollection->Clear();
The following sample XML schema is the contents of the file written out by the WriteXml method belonging to the FdoFeatureSchema class object that was created in the preceding sample code:
<?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>