2.3. GML-地理标记语言¶
2.3.1. 概述¶
GML(OpenGIS® Geography Markup Language Encoding Standard) 当前版本是 3.2.1。 它是一种基于 XML 的地理要素描述语言标准,用以在不同的软件或系统间交换空间数据,比如后面会介绍的 WFS 标准就使用 GML 作为输入和输出格式。GML 同时也是 ISO 标准 [2] 。
2.3.2. GML Schema¶
GML标准其实就是通过 XML Schema(XSD [1] )来定义了GML文档的结构, 这些定义都可以访问在线的地址:http://schemas.opengis.net/gml/ 得到。
目前 3.2.1 版本的 GML 中 包括 7 个顶级 XSD (其中一个是废弃类型,为了向前兼容), 这些 XSD 下还有其它子 XSD,它们组合成为如图 10 的结构。
图 10 GML XSD 依赖关系
2.3.3. GML 示例¶
下面是一个 包括点、线、面数据的 GML 的简单的例子,通过这个例子可以
看到 GML 的组织情况:
<?xml version="1.0" encoding="UTF-8"?>
<gml:FeatureCollection xmlns:gml="http://www.opengis.net/gml"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:fme="http://www.safe.com/gml/fme"
xsi:schemaLocation="http://www.safe.com/gml/fme MyGML.xsd">
<gml:boundedBy>
<gml:Envelope srsName="EPSG:4326" srsDimension="2">
<gml:lowerCorner>-0.012611143330844 -0.050087654172727</gml:lowerCorner>
<gml:upperCorner>0.051158411625351 0.019154661096934</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<fme:point gml:id="id9e2fb700-bbdb-48a5-8d99-f68b89886f4a">
<fme:Id>0</fme:Id>
<gml:pointProperty>
<gml:Point srsName="EPSG:4326" srsDimension="2">
<gml:pos>0.027363801567048 -0.028672505120255</gml:pos>
</gml:Point>
</gml:pointProperty>
</fme:point>
</gml:featureMember>
<gml:featureMember>
<fme:line gml:id="id4e0efc7b-d652-4d3c-8466-1a2419bca6d2">
<fme:Id>0</fme:Id>
<gml:curveProperty>
<gml:LineString srsName="EPSG:4326" srsDimension="2">
<gml:posList>0.051158411625351 0.019154661096934 0.039736998797366 -0.050087654172727</gml:posList>
</gml:LineString>
</gml:curveProperty>
</fme:line>
</gml:featureMember>
<gml:featureMember>
<fme:polygon gml:id="idf9b78df6-c402-4bc9-afd4-22762401c565">
<fme:Name>0</fme:Name>
<gml:surfaceProperty>
<gml:Surface srsName="EPSG:4326" srsDimension="2">
<gml:patches>
<gml:PolygonPatch>
<gml:exterior>
<gml:LinearRing>
<gml:posList>0.016656227040926 -0.024151529209121 0.003569191508859 0.005829679464227 -0.012611143330844 -0.01177833197886 -0.004283029810438 -0.042473378954071 0.018321849744836 -0.049373815870979 0.016656227040926 -0.024151529209121</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:PolygonPatch>
</gml:patches>
</gml:Surface>
</gml:surfaceProperty>
</fme:polygon>
</gml:featureMember>
</gml:FeatureCollection>
在这个例子中描述了一个 GML 的 FeatureCollection,由于这是由 FME 导出的数据,
因此其中还 包括“fme”的命名空间和 fme:point
、 fme:line
、 fme:polygon
类型,
这些类型在这个 XML 包括的 XSD 中进行了描述,实际对应的类型为基于 GML 标准的点、线、面:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:fme="http://www.safe.com/gml/fme"
targetNamespace="http://www.safe.com/gml/fme"
elementFormDefault="qualified">
<import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"/>
<element name="point" type="fme:pointType" substitutionGroup="gml:_Feature"/>
<complexType name="pointType">
<complexContent>
<extension base="gml:AbstractFeatureType">
<sequence>
<element name="Id" minOccurs="0" type="integer"/>
<element ref="gml:pointProperty" minOccurs="0"/>
<element ref="gml:multiPointProperty" minOccurs="0"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="line" type="fme:lineType" substitutionGroup="gml:_Feature"/>
<complexType name="lineType">
<complexContent>
<extension base="gml:AbstractFeatureType">
<sequence>
<element name="Id" minOccurs="0" type="integer"/>
<element ref="gml:curveProperty" minOccurs="0"/>
<element ref="gml:multiCurveProperty" minOccurs="0"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="polygon" type="fme:polygonType" substitutionGroup="gml:_Feature"/>
<complexType name="polygonType">
<complexContent>
<extension base="gml:AbstractFeatureType">
<sequence>
<element name="Name" minOccurs="0">
<simpleType>
<restriction base="string">
<maxLength value="30"/>
</restriction>
</simpleType>
</element>
<element ref="gml:surfaceProperty" minOccurs="0"/>
<element ref="gml:multiSurfaceProperty" minOccurs="0"/>
</sequence>
</extension>
</complexContent>
</complexType>
</schema>
而描述数据范围的 gml:boundedBy
属性则直接由 gml:Envelope
类型的对象来描述;
另外,数据的坐标节点、空间参考等属性则直接由 GML 的类型进行描述。
更简单一点,如果我们需要自己写一个 GML 来描述一个地理数据,写出来的文件内容可能是这样的:
<City><!--描述某城市的数据-->
<gml:boundedBy>
<gml:Envelope>
<gml:pos>100 200</gml:pos>
<gml:pos>230 250</gml:pos>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<Bridge gml:id="bridge 1"><!--某桥对象-->
<span>100</span><!--属性信息:该桥的跨度-->
<height>200</height><!--属性信息:该桥的高度-->
<gml:curveProperty><!--几何信息-->
<gml:LineString gml:id="line 24">
<gml:pos>100 200</gml:pos>
<gml:pos>200 200</gml:pos>
</gml:LineString>
</gml:curveProperty>
</Bridge>
</gml:featureMember>
</City>
Footnotes