OL3多边形WFS特征搜索 - 未定义轴方向

时间:2016-03-18 14:58:25

标签: openlayers-3 projection proj

我有一个应用程序,允许用户在地图上绘制一个多边形,然后使用JSTS库对WFS图层进行多边形交叉,并读取与用户多边形相交的要素。

一旦用户将选择多边形绘制到地图上,则会在返回错误时发生错误:

'无法读取未定义'

的属性'getAxisOrientation'

这似乎是投影相关的问题(我使用的是EPSG:27700投影)。

绘制用户多边形的代码如下:是否需要在WFS读取功能方法中包含投影?

draw.on('drawend',function(e){
var extent = e.feature.getGeometry().getExtent();
var geomA = e.feature.getGeometry();

myDrawSource.clear();
mySelectionsSource.clear();
$.ajax('../../geoserver/wfs', {
            type: 'GET',
            data: {
                service: 'WFS',
                version: '1.1.0',
                request: 'GetFeature',
                typename: 'planning:flood_zone_2',
                srsname: 'EPSG:27700',
                bbox: extent.join(',') + ',EPSG:27700'
            }
        }).done(function(resp){
        var formatWFS = new ol.format.WFS();
        var featuresInExtent = formatWFS.readFeatures(resp);
        var featuresOnDrawPoly = new Array();
        for (var i=0;i<featuresInExtent.length;i++){       
        var geomB = featuresInExtent[i].getGeometry();
          if (polyIntersectsPoly(geomA,geomB)===true){
          featuresOnDrawPoly.push(featuresInExtent[i])
          }
        }
        mySelectionsSource.addFeatures(featuresOnDrawPoly);
        //here you may iterate and get the attributes of those falling within the draw polygon
        for (var z=0;z<featuresOnDrawPoly.length;z++){
        console.log("address is ======", featuresOnDrawPoly[z].get('definition'));
        }
        }).fail(function () {
        alert("fail loading layer!!!")
        });

})

这是我的proj4投影的定义,我读到了关于轴并想知道这个定义是否存在问题?

proj4.defs("EPSG:27700", "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs");

2 个答案:

答案 0 :(得分:2)

您需要为http://www.opengis.net/gml/srs/epsg.xml#27700创建EPSG:27700的别名,因为这是GML解析器读取的containerSRS,请参阅:http://openlayers.org/en/v3.14.2/apidoc/ol.proj.html#.addEquivalentProjections

https://github.com/openlayers/ol3/issues/3898#issuecomment-120899034

答案 1 :(得分:0)

当使用OpenLayers 3.17.1从GeoServer 2.9.1加载WFS 1.1.0功能时,现在遇到了这个问题。

GML中指定的srsName是 urn:x-ogc:def:crs:EPSG:3763 所以以下内容对我有用:

&#13;
&#13;
var proj3763 = new ol.proj.Projection({
  code: 'EPSG:' + 3763,
  extent: [-121656.5849, -294200.8899, 172945.8815, 277430.8421],
  axis: 'enu'
});
ol.proj.addProjection(proj3763);
var proj3763OGC = new ol.proj.Projection({ // srsName from GeoServer GML3 (WFS)
  code: 'urn:x-ogc:def:crs:EPSG:' + 3763,
  axis: 'enu',
  extent: [-121656.5849, -294200.8899, 172945.8815, 277430.8421]
});
ol.proj.addProjection(proj3763OGC);
ol.proj.addEquivalentProjections([proj3763OGC, proj3763]);
&#13;
&#13;
&#13;