6

I have a problem integrating WMS and WFS. Basically what i want is when user clicks on WMS then a clicked polygon is added to vector (and selected). The problem is that the WMS is in version 1.3.0 and WFS 1.1.0. OpenLayers automatically flips axis for WMS but when it calculates bbox for wfs request, it does not. I have the following code:




    var map = new OpenLayers.Map({numZoomLevels: 20});

             var wms = new OpenLayers.Layer.WMS(
                 "OpenLayers WMS",
                 "http://sdi.geoportal.gov.pl/wms_dzkat/wmservice.aspx?",
                 {layers: ['Dzialki','Numery_dzialek'], version:'1.3.0'}
             );
             select = new OpenLayers.Layer.Vector("Selection", {styleMap: 
                 new OpenLayers.Style(OpenLayers.Feature.Vector.style["select"])
             });

    var protocol = new OpenLayers.Protocol.WFS({
                 version: "1.1.0",
                 //url:  "http://sdi.geoportal.gov.pl/WFS_DzKat/service.svc/post",
                 url:'/GSIP/proxy/dopost/',
                 featureType: "Dzialki",
                 featureNS:'http://www.intergraph.com/geomedia/gml',
                 featurePrefix:'gmgml',
                 geometryName:"GEOMETRIA_DEG"
             });

             control = new OpenLayers.Control.GetFeature({
                 protocol: protocol,
                 box: true,
                 //hover: true,
                 multipleKey: "shiftKey",
                 toggleKey: "ctrlKey"
             });

     control.events.register("featureselected", this, function(e) {
                 select.addFeatures([e.feature]);
             });
             control.events.register("featureunselected", this, function(e) {
                 select.removeFeatures([e.feature]);
             });

     map.addControl(control);
             control.activate();

And generated request after click:

<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" maxFeatures="10" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:Query typeName="gmgml:Dzialki" srsName="EPSG:4326" xmlns:gmgml="http://www.intergraph.com/geomedia/gml">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:BBOX>
<ogc:PropertyName>GEOMETRIA_DEG</ogc:PropertyName>
<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
<gml:lowerCorner>19.143386078712 52.371721634254</gml:lowerCorner>
<gml:upperCorner>19.143439722893 52.371775278435</gml:upperCorner>
</gml:Envelope>
</ogc:BBOX>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>

The above request does not work (0 features returned) but when i flip coords so it looks like:

<gml:lowerCorner>52.371721634254 19.143386078712</gml:lowerCorner>
    <gml:upperCorner>52.371775278435 19.143439722893</gml:upperCorner>

it works. How to force OpenLayers to build getFeature request with flipped coords? In WMS Layer there is attribute reverseAxisOrder but can't find it in Vector Layer

2

You could try to use the URN form of the epsg code (urn:x-ogc:def:crs:EPSG:4326) which is supposed to avoid these problems by always being in the WMS 1.3 order. How well this will work kind of depends on the server you are talking to but if it is GeoTools based it will work.

Further discussion can be found at http://docs.geotools.org/latest/userguide/library/referencing/order.html

2

use the formatOptions: {xy: false} option as below....

var wfs = new OpenLayers.Layer.Vector("OSBrgs", {
    strategies: [new OpenLayers.Strategy.BBOX(),refresh],
            styleMap: new OpenLayers.StyleMap({
                           pointRadius: "6", 
                          fillColor: "#666666"
             }),
             protocol: new OpenLayers.Protocol.WFS({
                    version: "1.0.0",
                    srsName: "EPSG:4326",
                    url: "/OL_WFS/Request.aspx",
                    featureType: "OFF_SYSTEM_BRG",
                    featurePrefix: "gmgml",
                    featureNS: "http://www.intergraph.com/geomedia/gml",
                    geometryName: "GEOMETRY",
                    formatOptions: {
                           xy: false
                   }
              }),
             renderers: OpenLayers.Layer.Vector.prototype.renderers
       });     
0

I ran into the same problem. Here is one way to reverse the coordinates going out of OL:

        WKB = gmlParser.write(feature);

        //Another problem. The OL GML parser doesn't switch the axis order of 4326 on output. So, let's read it back in, then out again.

        //Bring it back in, but reverse the axis.
        var gmlParser2 = new OpenLayers.Format.GML();
        gmlParser2.srsName = "EPSG:4326";
        gmlParser2.xy = false;

        var ReverseAxisOrderFeature = gmlParser2.read(WKB);
        WKB = gmlParser2.write(ReverseAxisOrderFeature);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.