3

I'm using openlayers-3 in client side and geoserver in server side. I have a vector layer. I get this layer from geoserver as follow:

var url = "http://localhost:8080/geoserver/wfs?&service=WFS&" +
           "version=1.1.0&request=GetFeature&typeName=points:cinema" + 
           "&outputFormate=application/json";

var format = new ol.format.WFS();
source = new ol.source.Vector({
    url: 'proxy.cgi?url=' + encodeURIComponent(u),
    format: format
});

cinemaLyr = new ol.layer.Vector({
    title: 'Cynema',
    source: source
});
map.addLayer(cinemaLyr);

I get cinemaLyr correctly, I modify this layer and save it as follow:

var node = wfs.writeTransaction(null, [modifiedFeature], null, {
    featureType: "points:cinema",
    featureNS: "http://opengeo.org",
    srsName: "EPSG:4326"
});
var s = new XMLSerializer();
var url = "http://localhost:8080/geoserver/wfs";

Ext.Ajax.request({
    url: 'proxy.cgi?url=' + encodeURIComponent(url),
    method: 'POST',
    xmlData: s.serializeToString(node),
    headers: {
        'Content-Type': 'text/xml'
    },
    success: function(response) {
        console.log("Everything is fine");
    }
});

This code save the modifiedFeature on server, but its coordinate is displacement(x save as y in geoserver and vice versa). In Insert and Delete it do correctly, Only in Update request displacement point coordinate. How do I fix it?

  • When you insert a point this occur(displacement point coordinate)? – Morteza Malvandi Aug 15 '15 at 7:06
  • In Insert and Delete it do correctly, Only in Update request displacement point coordinate. – itsme Aug 15 '15 at 7:11
  • Try indicating the srsname param in the request. See openlayers.org/en/master/examples/vector-wfs.html. It seems an issue with projection translation or a bug. – EricSonaron Aug 15 '15 at 8:47
  • When I set url as var url = "http://localhost:8080/geoserver/wfs?&service=WFS&" + "version=1.1.0&request=GetFeature&typeName=points:cinema" + "&srsName:EPSG4326&outputFormate=application/json" It doesn't work – itsme Aug 15 '15 at 10:46
  • 2
    Projections and coordinate axis order problems are easier to handle with WFS 1.0.0. I would first try to change the vesion from 1.1.0 into 1.0.0. BTW you made typos at least in the comment, should be srsName=EPSG:4326, as well as outputFormat. – user30184 Aug 15 '15 at 11:36
5

GeoServer indeed tends to swap coordinates on several occasions when using WFS. I couldn't backtrack this phenomenon to its exact origin, only to this post, where it is assumed, this confusion is created by the different axis orientation of EPSG:4326, and CRS:84, which are otherwise identical projections.

A possible workaround could be implemented on the client side, swapping the coordinates manually. I created a blog post about it, but I copy the relevant code part here, if it is gone for some reasons:

var swappedFeature = modifiedFeature.clone();
swappedFeature.getGeometry().applyTransform(function (coords, coords2, stride) {
    for (var i=0;i<coords.length;i+=stride) {
        var y = coords[i];
        var x = coords[i+1];
        coords[i] = x;
        coords[i+1] = y;
    }
});
var node = wfs.writeTransaction(null, [swappedFeature], null, {
    featureType: "points:cinema",
    featureNS: "http://opengeo.org",
    srsName: "EPSG:4326"
});

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.