1

我有一个应用程序,它允许用户在地图上绘制多边形,然后使用 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");
4

2 回答 2

2

您需要为 to 创建一个别名,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

于 2016-03-21T08:01:11.383 回答
0

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

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

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]);

于 2016-08-08T12:47:04.260 回答