OpenLayers 3 中来自 QGIS 服务器的 WFS
Posted
技术标签:
【中文标题】OpenLayers 3 中来自 QGIS 服务器的 WFS【英文标题】:WFS from QGIS Server in OpenLayers 3 【发布时间】:2016-08-15 13:36:41 【问题描述】:我正在尝试使用 QGIS Server (2.14) 实现此示例 https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58 并适应不同的 SRS。不幸的是,函数 ol.format.WFS.readFeatures() 无法读取 QGIS 服务器发回的几何图形(参见 console.log(features[k].getGeometry()); // => NULL ))
非常感谢任何帮助,谢谢!
顺便说一句:使用 ArcGIS-Server-WFS 时,下面的代码可以正常工作...
代码:
var formatWFS = new ol.format.WFS();
var sourceWFS = new ol.source.Vector(
loader: function (extent)
$.ajax('http://xxx/qgis/qgis_mapserv.fcgi.exe',
type: 'GET',
data:
service: 'WFS',
version: '1.0.0',
request: 'GetFeature',
typename: 'test2',
srsname: 'EPSG:2056',
bbox: extent.join(',') + ',EPSG:2056'
).done(function (response)
wfsresponsefeatures = formatWFS.readFeatures(response);
sourceWFS.addFeatures(wfsresponsefeatures);
features = sourceWFS.getFeatures();
for (var k in features)
console.log(features[k].getGeometry()); // => NULL
WFS 响应如下:
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml http://szhm4120/qgis/qgis_mapserv.fcgi.exe?srsname=EPSG%3A2056&SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=test2&OUTPUTFORMAT=XMLSCHEMA"><gml:boundedBy>
<gml:Box srsName="EPSG:2056">
<gml:coordinates cs="," ts=" ">2681188.02,1246449.97 2685167.35,1248977.27</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<qgs:test2 fid="test2.2">
<gml:boundedBy>
<gml:Box srsName="EPSG:2056">
<gml:coordinates cs="," ts=" ">2683250.99,1248618.11 2683250.99,1248618.11</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<qgs:geometry>
<gml:Point srsName="EPSG:2056">
<gml:coordinates cs="," ts=" ">2683250.99,1248618.11</gml:coordinates>
</gml:Point>
</qgs:geometry>
<qgs:id>2</qgs:id>
</qgs:test2>
</gml:featureMember>
<gml:featureMember>
<qgs:test2 fid="test2.3">
<gml:boundedBy>
<gml:Box srsName="EPSG:2056">
<gml:coordinates cs="," ts=" ">2681673.03,1247121.49 2681673.03,1247121.49</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<qgs:geometry>
<gml:Point srsName="EPSG:2056">
<gml:coordinates cs="," ts=" ">2681673.03,1247121.49</gml:coordinates>
</gml:Point>
</qgs:geometry>
<qgs:id>3</qgs:id>
</qgs:test2>
</gml:featureMember>
<gml:featureMember>
<qgs:test2 fid="test2.6">
<gml:boundedBy>
<gml:Box srsName="EPSG:2056">
<gml:coordinates cs="," ts=" ">2682779.23,1248227.69 2682779.23,1248227.69</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<qgs:geometry>
<gml:Point srsName="EPSG:2056">
<gml:coordinates cs="," ts=" ">2682779.23,1248227.69</gml:coordinates>
</gml:Point>
</qgs:geometry>
<qgs:id>6</qgs:id>
</qgs:test2>
</gml:featureMember>
</wfs:FeatureCollection>
【问题讨论】:
【参考方案1】:好的,所以 QGIS Server 只能为带有 GML2 几何图形的 WFS 1.0.0 提供服务...
以上示例通过将 WFS 设置为 GML2 来工作
var formatWFS = new ol.format.WFS(
'gmlFormat': new ol.format.GML2
);
【讨论】:
以上是关于OpenLayers 3 中来自 QGIS 服务器的 WFS的主要内容,如果未能解决你的问题,请参考以下文章
QGIS SERVER QGIS 用于 发布环境WEB 地图