WFS架构映射¶
地理服务器WFS的功能之一是自动将数据集的内部模式映射到要素类型模式。此映射根据以下规则执行:
要素元素的名称映射到数据集的名称。
功能类型的名称映射到附加了字符串“type”的数据集名称。
数据集的每个属性的名称映射到要素类型中包含的元素粒子的名称。
数据集的每个属性的类型都映射到适当的XML模式类型 (
xsd:int
,xsd:double
等等)。
例如,数据集具有以下架构:
myDataset(intProperty:Integer, stringProperty:String, floatProperty:Float, geometry:Point)
此架构将映射到以下XML架构,可通过 DescribeFeatureType
请求 topp:myDataset
类型:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:gml="http://www.opengis.net/gml"
xmlns:topp="http://www.openplans.org/topp"
targetNamespace="http://www.openplans.org/topp"
elementFormDefault="qualified">
<xsd:import namespace="http://www.opengis.net/gml"
schemaLocation="http://localhost:8080/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>
<xsd:complexType name="myDatasetType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="intProperty" nillable="true" type="xsd:int"/>
<xsd:element maxOccurs="1" minOccurs="0" name="stringProperty" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="floatProperty" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:PointPropertyType"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="myDataset" substitutionGroup="gml:_Feature" type="topp:myDatasetType"/>
</xsd:schema>
架构自定义¶
地理服务器WFS支持有限数量的模式输出自定义。自定义架构可能对以下内容有用:
限制在功能类型架构中公开的属性
Changing 模式中的属性类型
更改架构的结构(例如,更改基本要素类型)
例如,限制上面描述的示例数据集中的公开属性可能很有用。首先检索默认输出作为完整模式的基准。使用上面列出的功能类型模式, GetFeature
请求如下:
<topp:myDataset gml:id="myDataset.1">
<topp:intProperty>1</topp:intProperty>
<topp:stringProperty>one</topp:stringProperty>
<topp:floatProperty>1.1</topp:floatProperty>
<topp:geometry>
<gml:Point srsName="urn:x-ogc:def:crs:EPSG:4326">
<gml:pos>1.0 1.0</gml:pos>
</gml:Point>
</topp:geometry>
</topp:myDataset>
删除 floatProperty
从属性列表中,需要执行以下步骤:
修改原始架构以删除
floatProperty
,导致以下类型定义:<xsd:complexType name="myDatasetType"> <xsd:complexContent> <xsd:extension base="gml:AbstractFeatureType"> <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="0" name="intProperty" nillable="true" type="xsd:int"/> <xsd:element maxOccurs="1" minOccurs="0" name="stringProperty" nillable="true" type="xsd:string"/> <!-- remove the floatProperty element <xsd:element maxOccurs="1" minOccurs="0" name="floatProperty" nillable="true" type="xsd:double"/> --> <xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:PointPropertyType"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType>
修改保存在名为
schema.xsd
.这个
schema.xsd
文件被复制到topp:myDataset
即:$GEOSERVER_DATA_DIR/workspaces/<workspace>/<datastore>/myDataset/
在哪里?
<workspace>
是包含数据存储和<datastore>
是包含myDataset
只有重新加载配置或重新启动geoserver时,修改后的架构才对geoserver可用。
后继的 DescribeFeatureType
请求 topp:myDataset
确认 floatProperty
元素不存在:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:gml="http://www.opengis.net/gml"
xmlns:topp="http://www.openplans.org/topp"
targetNamespace="http://www.openplans.org/topp"
elementFormDefault="qualified">
<xsd:import namespace="http://www.opengis.net/gml"
schemaLocation="http://localhost:8080/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>
<xsd:complexType name="myDatasetType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="intProperty" nillable="true" type="xsd:int"/>
<xsd:element maxOccurs="1" minOccurs="0" name="stringProperty" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:PointPropertyType"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="myDataset" substitutionGroup="gml:_Feature" type="topp:myDatasetType"/>
</xsd:schema>
A GetFeature
请求现在将返回不包括 floatProperty
属性:
<topp:myDataset gml:id="myDataset.1">
<topp:intProperty>1</topp:intProperty>
<topp:stringProperty>one</topp:stringProperty>
<topp:geometry>
<gml:Point srsName="urn:x-ogc:def:crs:EPSG:4326">
<gml:pos>1.0 1.0</gml:pos>
</gml:Point>
</topp:geometry>
</topp:myDataset>
类型更改¶
模式自定义可用于执行某些 类型更改 尽管这受到更改类型必须相同的事实的限制 域 作为原始类型。例如,整数类型必须更改为整数类型,时间类型必须更改为时间类型,等等。
最常见的更改类型要求是几何图形属性。在许多情况下,基础数据集没有必要的元数据来报告几何属性的特定几何类型。自动模式映射将导致类似以下内容的元素定义:
<xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:GeometryPropertyType"/>
但是,如果已知几何图形的特定类型,则可以更改上面的元素定义。对于点几何,可以将元素定义更改为:
<xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:PointPropertyType"/>