[GIS] Openlayers and Geoserver fail to reproject while editing Vector with WFS-T

coordinate systemgeoserveropenlayers-2wfswfs-t

I can't get the Openlayers and Geoserver work with WFS-T editing a vector layer.

I have a layer of points where the Native SRS is EPSG:32639.

After trying a lot of combinations, I ended up with two not working solutions.

1)
a. On the server I set 'Declared SRS' to EPSG:32639 and make SRS hadling 'Force declared'.
b. In Openlayers i set projection: new OpenLayers.Projection("EPSG:32639") for the layer.

it submits

<gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"<gml:coordinates decimal="." cs="," ts=" ">241602.05063766203,4958072.672210057</gml:coordinates>

and gets

'PointOutsideEnvelopeException: 241602.05063766203 outside of (-180.0,180.0)'

2)
a. On the server I set 'Declared SRS' to EPSG:4326 and make SRS hadling 'Reproject native to declared'.
b. In Openlayers i set projection: new OpenLayers.Projection("EPSG:4326") for the layer.

it successfully commits my changes to the database, but the coordinates in the database are wrong – degrees as for 4326 instead of meters of 32639.

The Firebug shows that it submits degrees.

I have proj4js enabled on the client side.

Any other combination including playing with 'displayProjection' of the map leads to not even displaying the points of my layer on the map.

Seems like Openlayers tells projection 4326 all the time AND the geoserver is unable to reproject the coordinates when receiving them from the client.

On the server, I tried unsetting Services / WFS / GML2 / Override GML Attributes checkbox with no success.

I am in a dead end, please help.

Some code snippets:

        Proj4js.defs["EPSG:32639"] = "+proj=utm +zone=39 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";


            new OpenLayers.Layer.Vector('Wells', {
                isBaseLayer: false,
                defaultLabelField: 'NAME',
                strategies: [new OpenLayers.Strategy.BBOX(), config.saveStrategy],
                protocol: new OpenLayers.Protocol.WFS({
                    url: config.vectorWfs,
                    featureType: "Wells_PRS",
                    featureNS: "http://gisxxxx",
                    geometryName: "GEOM"
                }),
                schema: config.vectorWfs + "/DescribeFeatureType?version=1.1.0&typename=gisxxxx:Wells_PRS"
                //,projection: new OpenLayers.Projection("EPSG:4326")
                ,version: "1.1.0"
                ,projection: new OpenLayers.Projection("EPSG:32639")
            }), 







            th.map = new OpenLayers.Map(th.body.dom.id, {
                controls: [
                    new OpenLayers.Control.Navigation(),
                    new OpenLayers.Control.PanZoom(),
                    new OpenLayers.Control.LayerSwitcher(),
                    new OpenLayers.Control.ArgParser(),
                    new OpenLayers.Control.Attribution()
                    ,
                    new OpenLayers.Control.MousePosition(
                        {div:document.getElementById("coordinates")}) 
                ],
                layers: layers
                //, displayProjection: new OpenLayers.Projection("EPSG:4326")
                //projection: new OpenLayers.Projection("EPSG:4326")
            });

            var editingBar = new OpenLayers.Control.EditingToolbar(layers[2]);
            var save = new OpenLayers.Control.Button({
                title: "Save Changes",
                trigger: function() {
                    //if(edit.feature) {
                    //    edit.selectControl.unselectAll();
                    //}
                    config.saveStrategy.save();
                // alert('saved');
                }//,
                //displayClass: "olControlSaveFeatures"
            });
            editingBar.addControls([
                save, 
                new config.DeleteFeature(layers[2], {title: "Delete Feature"})
            ]);
            th.map.addControl(editingBar);

This all done reading this link:

http://www.gistutor.com/openlayers/22-advanced-openlayers-tutorials/47-openlayers-wfs-t-using-a-geoserver-hosted-postgis-layer.html

Best Answer

On the protocol definition, you need to set srsName:

        new OpenLayers.Layer.Vector('Wells', {
            strategies: [new OpenLayers.Strategy.BBOX(), config.saveStrategy],
            protocol: new OpenLayers.Protocol.WFS({
                url: config.vectorWfs,
                featureType: "Wells_PRS",
                featureNS: "http://gisxxxx",
                geometryName: "GEOM",
                srsName: 'EPSG:4326'
            }),
            version: "1.1.0"
        }),

You do not need proj4js.