Search code examples
openlayers-3projectionproj

OL3 polygon WFS feature search - axis orientation undefined


I have an application which allows the user to draw a polygon onto the map, which then uses the JSTS library to do a polygon intersect against a WFS layer and reads features that intersect the user's polygons.

An error occurs once the user has drawn the select polygon onto the map as an error is returned:

'Cannot read property 'getAxisOrientation' of undefined'

This appears to be a projection related issue (I am using the EPSG:27700 projection).

The code for when the user polygon has been drawn is below - would there be a requirement to include the projection in the WFS read features method?

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!!!")
        });

})

This is the definition for my proj4 projection, I read about axis and wonder if there is an issue with this definition?

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

Solution

  • You need to create an alias for http://www.opengis.net/gml/srs/epsg.xml#27700 to EPSG:27700 as this is the containerSRS read by the GML parser, see: http://openlayers.org/en/v3.14.2/apidoc/ol.proj.html#.addEquivalentProjections

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