13.1. 超越地图¶
我们专注于书中的地图,在我们的例子中几乎总是使用WMS协议。正如你在书中学到的第一章, 地理信息系统基础,映射是数据的表示。 地图可以包含矢量或栅格数据,但它始终将它们表示为栅格输出, 即图像。虽然地图是显示数据的一种简单而有用的方式,但在其他情况下,用户不需要使用表示, 而需要使用原始数据(例如,在客户端任务上处理数据)。 在这里,另外两个OGC 协议开始使用:WFS和WCS。
13.1.1. 传送 矢量数据¶
如果用户需要获取您的矢量数据,例如,美国铁路, 他可以使用 Web Feature Service (WFS) 协议。 这是OGC 定义的标准协议,是指通过 HTTP 发送和接收地理空间数据。
传递数据时,最重要的定义是数据格式。 矢量数据通常以二进制格式存储(例如shapefile或 PostGIS 表),但是 出于实际目的,我们需要一种更标准的方法。 确实, WFS 基于XML以 地理标记语言(GML) 编码和传输信息。
有几个版本的WFS和GML。当前GeoServer 版本支持1.0.0、1.1.0和2.0.0 WFS版本。
您可以在OGC 存储库中找到WFS和GML的完整参考 http://www.opengeospatial.org/standards/is ;寻找:
OpenGIS地理标记语言(GML)编码标准
OpenGIS Web特性服务(WFS)实现规范
WFS 定义了一组用户可以对数据执行的操作。您在中使用了事务操作第十章,生产前保护地理服务器 , 用于数据编辑。我们现在将集中精力检索数据。
13.1.2. 行动时间-检索 矢量数据¶
我们将使用WFS获得GML编码的矢量数据。万一你把它弄坏了,就像我们在
第十一章,在生产环境中调整GeoServer ,则需要在GeoServer 中启用WFS。 打开命令行控制台;我们将使用 curl 发送请求:
1.我们将使用的第一个操作是 GetCapabilities . 它描述了服务器上可用的功能类型和操作:
>>> !curl -v -u admin:geoserver -XGET "http://118.190.135.194:8080/geoserver/wfs?service=wfs&version=1.0.0&request=GetCapabilities" -o getCapabilities.xml
Note: Unnecessary use of -X or --request, GET is already inferred. * Expire in 0 ms for 6 (transfer 0x55c6d5766f50) * Trying 118.190.135.194... * TCP_NODELAY set * Expire in 200 ms for 4 (transfer 0x55c6d5766f50) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 118.190.135.194 (118.190.135.194) port 8080 (#0) * Server auth using Basic with user 'admin' > GET /geoserver/wfs?service=wfs&version=1.0.0&request=GetCapabilities HTTP/1.1 > Host: 118.190.135.194:8080 > Authorization: Basic YWRtaW46Z2Vvc2VydmVy > User-Agent: curl/7.64.0 > Accept: / > 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0< HTTP/1.1 200 < Set-Cookie: JSESSIONID=85628397968FFCDEFEAB12DB6596B66E; Path=/geoserver; HttpOnly < Set-Cookie: GS_FLOW_CONTROL=GS_CFLOW_-30f1ffb6:171b0987f54:-692d < X-Control-flow-delay-ms: 0 < Cache-Control: max-age=0, must-revalidate < Content-Disposition: inline; filename=geoserver-GetCapabilities.application < Content-Type: application/xml < Transfer-Encoding: chunked < Date: Mon, 27 Apr 2020 01:36:10 GMT < { [13573 bytes data] 100 25266 0 25266 0 0 110k 0 --:--:-- --:--:-- --:--:-- 110k * Connection #0 to host 118.190.135.194 left intact
2.返回的XML相当大;下面几行显示了 特征类型 元素:
<FeatureType>
<Name>NaturalEarth:10m_railroads</Name>
<Title>10m_railroads</Title>
<Abstract/>
<Keywords>10m_railroads, features</Keywords>
<SRS>EPSG:4326</SRS>
<LatLongBoundingBox minx="-150.08159339101002" miny="8.329046942181577" maxx="-59.94810950429127" maxy="64.93097565311908"/>
</FeatureType>
3.如果你需要使用 featuretype 元素,例如railroads,您可能需要完整的描述。 你可以用 DescribeFeatureType 操作,返回包含 featuretype 您请求的元素。 注意,您可以省略 TypeName 参数;在本例中,您将获得 featuretype 元素,按工作区排序:
>>> !curl -v -u admin:geoserver -XGET "http://118.190.135.194:8080/geoserver/wfs?service=wfs&version=1.0.0&request=DescribeFeatureType&TypeName=Natural+Earth+Countries:ne_10m_admin_0_countries" -o railroads.xml
Note: Unnecessary use of -X or --request, GET is already inferred. * Expire in 0 ms for 6 (transfer 0x5655558d2f50) * Trying 118.190.135.194... * TCP_NODELAY set * Expire in 200 ms for 4 (transfer 0x5655558d2f50) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 118.190.135.194 (118.190.135.194) port 8080 (#0) * Server auth using Basic with user 'admin' > GET /geoserver/wfs?service=wfs&version=1.0.0&request=DescribeFeatureType&TypeName=Natural+Earth+Countries:ne_10m_admin_0_countries HTTP/1.1 > Host: 118.190.135.194:8080 > Authorization: Basic YWRtaW46Z2Vvc2VydmVy > User-Agent: curl/7.64.0 > Accept: / > < HTTP/1.1 200 < Set-Cookie: JSESSIONID=547BECCB0CFFC3090A56F94FB067A52B; Path=/geoserver; HttpOnly < Set-Cookie: GS_FLOW_CONTROL=GS_CFLOW_-30f1ffb6:171b0987f54:-692a < X-Control-flow-delay-ms: 0 < Content-Disposition: inline; filename=geoserver-DescribeFeatureType.text < Content-Type: text/xml < Transfer-Encoding: chunked < Date: Mon, 27 Apr 2020 01:44:34 GMT < { [10485 bytes data] 100 10470 0 10470 0 0 101k 0 --:--:-- --:--:-- --:--:-- 101k * Connection #0 to host 118.190.135.194 left intact
4.响应包含该功能类型的详细描述。你可以找到 name 和 type 每个属性:
<?xml version="1.0" encoding="UTF-8"?>
…
<xsd:complexType name="ne_10m_admin_0_countries"> <xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType"> <xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:MultiLineStringPropertyType"/>
<xsd:element maxOccurs="1" minOccurs="0" name="ScaleRank" nillable="true" type="xsd:int"/>
<xsd:element maxOccurs="1" minOccurs="0" name="FeatureCla" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="SOV_A3" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="UIDENT" nillable="true" type="xsd:int"/>
</xsd:sequence> </xsd:extension>
</xsd:complexContent>
</xsd:complexType> …
5.现在我们将检索这些特性。这个 GetFeature 操作从地理服务器检索它们。 为了避免获得大量特性,可以限制 最大特性 参数:
>>> !curl -u admin:geoserver -XGET -H 'Content-Type: text/html;charset=utf-8' "http://118.190.135.194:8080/geoserver/wfs?service=wfs& version=1.1.0&request=GetFeature&TypeName=geonode:ne_10m_admin_0_countries&maxFeatures=1" -o getFeature.xml
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2131 100 2131 0 0 62676 0 --:--:-- --:--:-- --:--:-- 62676
6.返回的XML代码包含我们指定的单个功能的GML。 在这种情况下我们只有一个 lineString 元素中列出了许多顶点 gml:坐标 元素:
<gml:boundedBy>
<gml:null>unknown</gml:null>
</gml:boundedBy>
<gml:featureMember>
<NaturalEarth:10m_railroads fid="10m_railroads.1">
<NaturalEarth:the_geom>
<gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:lineStringMember>
<gml:LineString>
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">-147.67979896,64.81824372 -147.69432532,64.83020661-147.70750892,64.83808015
…
-148.96648109,60.85010407 -148.9647721,60.83167145</ gml:coordinates>
</gml:LineString>
</gml:lineStringMember>
</gml:MultiLineString>
</NaturalEarth:the_geom>
<NaturalEarth:ScaleRank>8</NaturalEarth:ScaleRank>
<NaturalEarth:FeatureCla>Railroad</NaturalEarth:FeatureCla>
<NaturalEarth:SOV_A3>USA</NaturalEarth:SOV_A3>
<NaturalEarth:UIDENT>1506</NaturalEarth:UIDENT>
</NaturalEarth:10m_railroads>
</gml:featureMember>
7.限制返回的元素 最大特性 对于示例请求是可以的。通常, 您希望对要提取的功能的数量和类型有更多的控制。实际上, 可以使用空间运算符或对属性使用字母数字过滤来过滤它们。 在下面的示例中,我们使用 bbox 操作员过滤与区段相交的铁路要素:
>>> !curl -u admin:geoserver -XGET "http://118.190.135.194:8080/geoserver/wfs?service=wfs&version=1.0.0&request=GetFeature&TypeName=geonode:citiesx0200&bbox=-116.68,36.29,-111.36,39.90" -o getBboxFeature.xml
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 139k 0 139k 0 0 977k 0 --:--:-- --:--:-- --:--:-- 977k
8.请求再次返回单个功能,但根元素是 FeatureCollection . 如果你试图扩展 bbox ,其中将列出更多功能:
<wfs:FeatureCollection xsi:schemaLocation="http://www.geonode.org/ http://118.190.135.194:8080/geoserver/wfs?service=WFS&version=1.0.0&request=DescribeFeatureType&typeName=geonode%3Acitiesx0200 http://www.opengis.net/wfs http://118.190.135.194:8080/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd">
<gml:boundedBy>
<gml:null>unknown</gml:null>
</gml:boundedBy>
<gml:featureMember>
<geonode:citiesx0200 fid="citiesx0200.16560">
<geonode:the_geom>
<gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:coordinates decimal="." cs="," ts=" ">-114.35137939,39.86821365</gml:coordinates>
</gml:Point>
</geonode:the_geom>
<geonode:CITIESX020>16560</geonode:CITIESX020>
<geonode:FEATURE>Populated Place</geonode:FEATURE>
<geonode:NAME>Tippett</geonode:NAME>
<geonode:POP_RANGE>Undetermined</geonode:POP_RANGE>
<geonode:POP_2000>-99999</geonode:POP_2000>
<geonode:FIPS55>73200</geonode:FIPS55>
<geonode:COUNTY>White Pine County</geonode:COUNTY>
<geonode:FIPS>32033</geonode:FIPS>
<geonode:STATE>NV</geonode:STATE>
<geonode:STATE_FIPS>32</geonode:STATE_FIPS>
<geonode:DISPLAY>1</geonode:DISPLAY>
</geonode:citiesx0200>
</gml:featureMember>
<gml:featureMember>
刚刚发生了什么?¶
您学习了如何使用WFS检索包含所有几何和字母数字细节的数据。 将检索与插入或更新数据(WFS-T)功能结合起来,可以构建矢量数据的在线编辑系统。
13.1.3. 传送 栅格数据¶
当涉及栅格数据时, Web Coverage Service(WCS) 与WFS等效,用于传递原始数据。 像矢量数据一样,栅格数据可能会以适当的方式呈现在地图上,您将通过WMS和 GetMap 请求获得结果。 WCS 旨在以原始形式获取栅格数据集或其子集,而无需任何渲染或其他处理。
使用WCS,您没有用于数据传递的标准格式;它取决于数据的原始格式。
GeoServer 的当前版本支持1.0.0和1.1.0 WCS版本。
与WFS一样,您可以在OGC 存储库中找到WCS的完整参考, http://www.opengeospatial.org/standards/is ;寻找:
OpenGIS Web Coverage Service(WCS)实现规范
13.1.4. 行动时间-检索 栅格数据¶
我们将使用WCS获取栅格数据,使用GeoServer 附带的示例数据。万一你把它弄坏了, 就像我们在 第十一章 , 在生产环境中调整 GeoServer ,则需要在GeoServer 中启用WCS。 像WFS示例一样,我们将使用 cUrl 发送请求:
1.我们要做的第一个操作是 GetCapabilities . 与WFS一样, 它返回可用的列表 featuretype 和操作:
>>> !curl -u admin:geoserver -XGET "http://118.190.135.194:8080/geoserver/wcs?service=wcs&version=1.0.0&request=GetCapabilities" -o getCapabilities.xml
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2290 0 2290 0 0 23608 0 --:--:-- --:--:-- --:--:-- 23608
2.以下几行显示了从返回的列表中提取的覆盖范围的简要说明:
<wcs:WCS_Capabilities version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wcs http://118.190.135.194:8080/geoserver/schemas/wcs/1.0.0/wcsCapabilities.xsd" updateSequence="147">
<wcs:Service>
<wcs:metadataLink about="http://geoserver.sourceforge.net/html/index.php" xlink:type="simple" metadataType="other"/>
<wcs:description>This is a description of your Web Coverage Server.</wcs:description>
<wcs:name>My GeoServer WCS</wcs:name>
<wcs:label>My GeoServer WCS</wcs:label>
<wcs:keywords>
<wcs:keyword>WCS</wcs:keyword>
<wcs:keyword>WMS</wcs:keyword>
<wcs:keyword>GEOSERVER</wcs:keyword>
</wcs:keywords>
<wcs:responsibleParty>
<wcs:individualName/>
<wcs:contactInfo>
<wcs:phone/>
<wcs:address/>
</wcs:contactInfo>
</wcs:responsibleParty>
<wcs:fees>NONE</wcs:fees>
<wcs:accessConstraints>NONE</wcs:accessConstraints>
</wcs:Service>
3.这个 DescribeCoverage 操作可让您获得对它的完整描述:
>>> !curl -v -u admin:geoserver -XGET "http://118.190.135.194:8080/geoserver/wcs?service=wcs&version=1.0.0&request=DescribeCoverage&Coverage=geonode:hydrogp0200" -o describeCoverage.xml
Note: Unnecessary use of -X or --request, GET is already inferred. * Expire in 0 ms for 6 (transfer 0x55ab646e4f50) * Trying 118.190.135.194... * TCP_NODELAY set * Expire in 200 ms for 4 (transfer 0x55ab646e4f50) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 118.190.135.194 (118.190.135.194) port 8080 (#0) * Server auth using Basic with user 'admin' > GET /geoserver/wcs?service=wcs&version=1.0.0&request=DescribeCoverage&Coverage=geonode:hydrogp0200 HTTP/1.1 > Host: 118.190.135.194:8080 > Authorization: Basic YWRtaW46Z2Vvc2VydmVy > User-Agent: curl/7.64.0 > Accept: / > < HTTP/1.1 200 < Set-Cookie: JSESSIONID=792309E2A16043CD08D04A82D2FEA51E; Path=/geoserver; HttpOnly < Content-Type: application/vnd.ogc.se_xml;charset=UTF-8 < Transfer-Encoding: chunked < Date: Mon, 27 Apr 2020 02:38:37 GMT < { [261 bytes data] 100 255 0 255 0 0 2833 0 --:--:-- --:--:-- --:--:-- 2833 * Connection #0 to host 118.190.135.194 left intact
4.在说明中,返回的代码包含输出支持的数据格式列表:
<wcs:supportedFormats nativeFormat="WorldImage">
<wcs:formats>GeoTIFF</wcs:formats>
<wcs:formats>GIF</wcs:formats>
<wcs:formats>PNG</wcs:formats>
<wcs:formats>TIFF</wcs:formats>
</wcs:supportedFormats>
5.现在我们要找回 coverage . 这个 GetCoverage 操作从GeoServer 检索它。 不像 GetFeatures 在WFS中,一些参数是必需的。 必须指定边界框( bbox ) 宽度 和 高度 参数。 这个 bbox 运算符定义要提取的几何范围,而 宽度 和 高度 定义图像大小:
>>> !curl -v -u admin:geoserver -XGET "http://118.190.135.194:8080/geoserver/wcs?service=wcs&version=1.0.0&request=GetCoverage&coverage=geonode:hydrogp0200&crs=EPSG:4326&bbox=-130.85168,20.7052,-62.0054,54.1141&width=982&height=597&format=geotiff&bands=1" -o coverage.tiff
Note: Unnecessary use of -X or --request, GET is already inferred. * Expire in 0 ms for 6 (transfer 0x55c3b9864f50) * Trying 118.190.135.194... * TCP_NODELAY set * Expire in 200 ms for 4 (transfer 0x55c3b9864f50) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 118.190.135.194 (118.190.135.194) port 8080 (#0) * Server auth using Basic with user 'admin' > GET /geoserver/wcs?service=wcs&version=1.0.0&request=GetCoverage&coverage=geonode:hydrogp0200&crs=EPSG:4326&bbox=-130.85168,20.7052,-62.0054,54.1141&width=982&height=597&format=geotiff&bands=1 HTTP/1.1 > Host: 118.190.135.194:8080 > Authorization: Basic YWRtaW46Z2Vvc2VydmVy > User-Agent: curl/7.64.0 > Accept: / > < HTTP/1.1 200 < Set-Cookie: JSESSIONID=6BD58A61DB850C6DAE1EEC21D4D9EC85; Path=/geoserver; HttpOnly < Content-Type: application/vnd.ogc.se_xml;charset=UTF-8 < Transfer-Encoding: chunked < Date: Thu, 07 May 2020 03:25:30 GMT < { [261 bytes data] 100 255 0 255 0 0 2897 0 --:--:-- --:--:-- --:--:-- 2897 * Connection #0 to host 118.190.135.194 left intact
6.如果你打开 coverage.tiff 使用图片查看器的文件, 您将看到它包含与原始覆盖范围相同的数据:

图 13.1 image282¶
刚刚发生了什么?¶
您学习了检索栅格数据的基础知识。如果您的项目需要在客户端处理栅格数据, 则非常重要的一点是,它们不能像WMS那样由地图服务器进行转换。