Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
    
Format/GML/Base.js has an xy property which is used to indicate if the x/y values should be reversed. See dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/… -- not sure how you're going to reach down into that value. –  ca0v Sep 12 '12 at 16:43

3 Answers 3

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
       });     
share|improve this answer

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);
share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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