WFS-OGC WFS服务

司机简称

WFS

生成依赖项

利勃曲尔

此驱动程序可以连接到OGC WFS服务。它支持WFS 1.0、1.1和2.0协议。为了编译WFS驱动程序,必须使用Curl支持构建GDAL/OGR。通常WFS请求以GML格式返回结果,因此GML驱动程序通常应设置为读取支持(因此需要使用Xerces或Expat支持构建GDAL/OGR)。当服务器支持时,有时可以使用其他底层格式(例如OUTPUTFORMAT=json)。

驱动程序支持只读服务和事务性服务(WFS-T)。

驱动程序功能

Supports Georeferencing

This driver supports georeferencing

数据集名称语法

打开WFS数据源的最低语法是: WFS:http://path/to/WFS/servicehttp://path/to/WFS/service?SERVICE=WFS

Additional optional parameters can be specified such as TYPENAME, VERSION, MAXFEATURES (WFS < 2) or COUNT (WFS > 2) as specified in WFS specification.

提供给TYPENAME参数的名称必须与OGR报告的层名称完全相同,尤其是当其名称空间存在时,必须使用其名称空间前缀。注意:可以提供多个类型名,并用逗号分隔。

还可以指定内容与以下语法匹配的XML文件的名称(<OGRWFSDataSource>元素必须是文件的第一个字节):

<OGRWFSDataSource>
    <URL>http://path/to/WFS/service[?OPTIONAL_PARAMETER1=VALUE[&amp;OPTIONAL_PARAMETER2=VALUE]]</URL>
</OGRWFSDataSource>

注意:URL必须是XML转义的,例如 & 字符必须写为 &安培;

在第一次开放时,结果的内容 GetCapabilities 请求将附加到文件中,以便可以缓存它以供以后打开数据集时使用。同样适用于 DescribeFeatureType 为发现每个层的字段定义而发出的请求。

服务描述文件有以下附加元素作为 OGRWFSDataSource 可选择设置的元素。

  • 超时 :用于远程服务请求的超时。如果未提供,则使用libcurl默认值。

  • UserPwd :可提供 用户名:密码 将用户标识和密码传递给远程服务器。

  • HttpAuth :可以是BASIC、NTLM或ANY来控制要使用的身份验证方案。

  • 版本 :设置要使用的特定WFS版本(1.0.0或1.1.0)。

  • PagingAllowed :如果必须启用分页,则设置为“开”。请参阅“请求分页”部分。

  • PageSize :启用分页时的页大小。请参阅“请求分页”部分。

  • BaseStartIndex :启用分页时开始索引的基(0或1)。请参阅“请求分页”部分。

  • COOKIE: HTTP cookies that are passed in HTTP requests, formatted as COOKIE1=VALUE1; COOKIE2=VALUE2... Starting with GDAL 2.3, additional HTTP headers can be sent by setting the GDAL_HTTP_HEADER_FILE configuration option to point to a filename of a text file with “key: value” HTTP headers.

请求分页

The WFS driver will read the GML content as a stream instead as a whole file, which will improve interactivity and help when the content cannot fit into memory. This can be turned off by setting the OGR_WFS_USE_STREAMING configuration option to NO if this is not desirable (for example, when iterating several times on a layer that can fit into memory). When streaming is enabled, GZip compression is also requested. It has been observed that some WFS servers, that cannot do on-the-fly compression, will cache on their side the whole content to be sent before sending the first bytes on the wire. To avoid this, you can set the CPL_CURL_GZIP configuration option to NO.

Paging with WFS 2.0

The WFS driver will automatically detect if server supports paging, when requesting a WFS 2.0 server. The page size (number of features fetched in a single request) is limited to 100 by default when not declared by the server. It can be changed by setting the OGR_WFS_PAGE_SIZE configuration option, or by specifying COUNT as a query parameter in the URL of the connection string.

If only the N first features must be downloaded and paging through the whole layer is not desirable, the OGR_WFS_PAGING_ALLOWED configuration option should be set to OFF.

Paging with WFS 1.0 or 1.1

Some servers (such as MapServer >= 6.0) support the use of STARTINDEX that allows doing the requests per "page", and thus to avoid downloading the whole content of the layer in a single request. Paging was introduced in WFS 2.0.0 but servers may support it as an vendor specific option also with WFS 1.0.0 and 1.1.0. The OGR WFS client will use paging when the OGR_WFS_PAGING_ALLOWED configuration option is explicitly set to ON. The page size (number of features fetched in a single request) is limited to 100 by default when not declared by the server. It can be changed by setting the OGR_WFS_PAGE_SIZE configuration option.

WFS 2.0.2 specification has clarified that the first feature in paging is at index 0. But some server implementations of WFS paging have considered that it was at index 1 (including MapServer <= 6.2). The default base start index is 0, as mandated by the specification. The OGR_WFS_BASE_START_INDEX configuration option can however be set to 1 to be compatible with the server implementations that considered the first feature to be at index 1.

Paging options

Those 3 options (OGR_WFS_PAGING_ALLOWED, OGR_WFS_PAGE_SIZE, OGR_WFS_BASE_START_INDEX) can also be set in a WFS XML description file with the elements of similar names (PagingAllowed, PageSize, BaseStartIndex).

过滤

驱动程序将使用SetSpatialFilter()将任何空间筛选器集转发到服务器。它还尽最大努力在可能的情况下对使用SetAttributeFilter()设置的属性过滤器执行相同的操作(将OGR SQL语言转换为OGC过滤器描述)。当这不可能时,它将默认为仅客户端筛选,这可能是一个缓慢的操作,因为涉及从服务器获取所有功能。

可以使用以下空间功能:

  • 8空间二进制谓词: ST_Equals, ST_Disjoint, ST_Touches, ST_Contains, ST_Intersects, ST_Within, ST_Crosses and ST_Overlaps 有两个几何参数。通常是几何列名,以及一个常量几何体,如用ST_MakeEnvelope或ST_GeomFromText构建的。

  • ST_DWithin(geom1,geom2,distance_in_meters)

  • ST_Beyond(geom1,geom2,distance_in_meters)

  • [ST_MakeEnvelope(xmin,ymin,xmax,ymax[,srs])] :创建信封。srs可以是整数(EPSG代码),也可以是直接设置为gml:Envelope的srsName属性的字符串。GDAL将处理所需的轴交换,因此坐标应以“自然地理信息系统顺序”表示(例如,大地测量系统的长纬度)

  • [ST_GeomFromText(wkt,[srs])] :从WKT表示形式生成几何体。

请注意,这些空间函数仅支持作为服务器端过滤器。

层连接

对于支持联接的WFS2.0服务器,将在服务器端运行包含联接的SELECT语句。如果服务器支持空间连接,也可以通过使用上述空间功能来完成空间连接。

服务器可能会对连接的复杂性设置限制。OGR WFS驱动程序还将列选择限制为列名,可能带有别名和类型转换,但不包括表达式。ON和WHERE子句也必须在服务器端求值,因此不允许使用OGR特殊字段。支持ORDER BY子句,但字段必须属于主表。

有效语句示例:

SELECT t1.id, t1.val1, t1.geom, t2.val1 FROM my_table AS t1 JOIN another_table AS t2 ON t1.id = t2.t1id

SELECT * FROM my_table AS t1 JOIN another_table AS t2 ON ST_Intersects(t1.geom, t2.geom)

写支持/WFS-T

WFS-T协议只允许用户在功能级别操作。不可能创建数据源、层或字段。

只有在更新模式下打开数据源时才启用写支持。

WFS事务服务的操作与OGR概念之间的映射如下:

  • OGRFeature::CreateFeature()<==>WFS插入操作

  • OGRFeature::SetFeature()<==>WFS更新操作

  • OGRFeature::DeleteFeature()<==>WFS删除操作

锁定操作(锁定功能服务)此时不可用。

有几点需要记住。OGR feature ID(FID)是一个基于整数的值,而WFS/GML GML:ID属性是一个字符串。因此,并不总是能够同时匹配这两个值。WFS驱动程序随后将功能的gml:id属性公开为“gmlu id”字段。

使用CreateFeature()插入新功能时,如果命令成功,OGR将获取返回的gml:id并相应地设置该功能的“gmlu id”字段。如果gml:id的格式为layer_name.numeric_value,它还将尝试设置OGR FID。否则,FID将保留其未设置的默认值。

使用SetFeature()更新现有功能时,将忽略OGR FID字段。向驱动程序发出的请求将只考虑特性的gml:id字段的值。这同样适用于DeleteFeature()。

写支持和OGR事务

默认情况下,上述操作与OGR API调用同步发布到服务器。但是,当由于许多客户机/服务器交换而发出大量命令时,这可能会导致性能下降。

可以将这些操作包围在OGRLayer::StartTransaction()和OGRLayer::CommitTransaction()之间。这些操作将存储在内存中,并且仅在调用CommitTransaction()时执行。

CreateFeature()的缺点是用户无法知道哪些gml:id已分配给插入的功能。WFS驱动程序中引入了一个特殊的SQL语句来解决这个问题:通过发出 _LAST_INSERTED_FIDS_ 通过OGRDataSource::ExecuteSQL()从layer_name“(其中layer_name将替换为实际的layer_name)命令中,将返回一个层,其中具有单个属性gml_id的行数与上次提交事务期间插入的功能数相同。

注意:目前,只有CreateFeature()使用OGR事务机制。SetFeature()和DeleteFeature()仍将立即发出。

特殊SQL命令

传递给OGRDataSource::ExecuteSQL()的以下SQL/pseudo SQL命令是WFS驱动程序特有的:

  • “DELETE FROM layer_name WHERE expression”:这将导致WFS DELETE操作。这可以是删除一个或多个功能的快速方法。特别是,当gml:id已知时,这可以更快地替换OGRLayer::DeleteFeature(),但尚未从服务器获取该功能。

  • “选择 _LAST_INSERTED_FIDS_ “来自层名”:见上一段。

目前,任何其他SQL命令都将由泛型层处理,这意味着只在客户端处理。服务器端空间和属性筛选必须通过SetSpatialFilter()和SetAttributeFilter()接口完成。

特殊层:WFSLayerMetadata

名为“WFS layer metadata”的“隐藏”层由每个WFS层的元数据记录填充。

每个记录都包含GetCapabilities返回的文档中的“layer_name”、“title”和“abstract”字段。

该层通过GetLayerByName(“WFSLayerMetadata”)返回。

特殊层:WFSGetCapabilities

名为“WFSGetCapabilities”的“隐藏”层被GetCapabilities请求的原始XML结果填充。

该层通过GetLayerByName(“WFSGetCapabilities”)返回。

打开选项

以下选项可用:

  • URL =url:WFS服务器终结点的url。使用“WFS:”字符串作为连接字符串时必需。

  • TRUST_CAPABILITIES_BOUNDS =是/否:是否信任GetCapabilities响应中声明的层边界,以加快GetExtent()运行时的速度。默认为否

  • EMPTY_AS_NULL=YES/NO :默认情况下(EMPTY_AS_NULL=YES),内容为空的字段将报告为NULL,而不是空字符串。这是历史性的行为。但是,如果应用程序架构将这些字段声明为强制字段,则这将防止这些字段被声明为不可为null。因此,可以将此选项设置为NO,以使空字符串和强制字段都被报告为不可为空。

  • INVERT_AXIS_ORDER_IF_LAT_LONG=YES/NO :是否在传统GIS顺序中显示SRS和坐标顺序。默认为“是”。

  • CONSIDER_EPSG_AS_URN=YES/NO/AUTO :是否考虑srsName-likeEPSG:XXXX as公司关于EPSG轴顺序。默认为自动。

  • EXPOSE_GML_ID=YES/NO :是否暴露gml:id属性GML特性的一部分作为GMLu id OGR字段。注意,隐藏gmlu id将阻止WFS-T工作。默认为“是”。

实例

列出WFS服务器的类型:

ogrinfo -ro WFS:http://www2.dmsolutions.ca/cgi-bin/mswfs_gmap

列出其层结构缓存在XML文件中的WFS服务器的类型:

ogrinfo -ro mswfs_gmap.xml

列出popplace层的功能,带有空间过滤器:

ogrinfo -ro WFS:http://www2.dmsolutions.ca/cgi-bin/mswfs_gmap popplace -spat 0 0 2961766.250000 3798856.750000

从tows:world层检索gml:id“world.2”和“world.3”的功能:

ogrinfo "WFS:http://www.tinyows.org/cgi-bin/tinyows" tows:world -ro -al -where "gml_id='world.2' or gml_id='world.3'"

显示层元数据:

ogrinfo -ro -al "WFS:http://v2.suite.opengeo.org/geoserver/ows" WFSLayerMetadata

也见