Search code examples
ajaxpostgresqlopenlayers-3geoserver

No such property: geometry when updating feature in openlayers 3 - Geoserver


I am working on a webmapping app with Openlayers 3, Postgresql and Geoserver 2.8, I want to make a WFS-T transactions for drawing and updating so I followed this steps https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58 Here is my modification code :

var dirty = {};
select.getFeatures().on('add', function(e) {
    e.element.on('change', function(e) {
        dirty[e.target.getId()] = true;
    });
});
var clone;
select.getFeatures().on('remove', function(e) {
    var f = e.element;
    if (dirty[f.getId()]){
        delete dirty[f.getId()];
        featureProperties = f.getProperties();
        delete featureProperties.boundedBy;
        clone = new ol.Feature(featureProperties);
        clone.setId(f.getId());
        clone.setGeometryName("the_geom");
    }
});

var node = formatwfs.writeTransaction(null, [clone], null, {
            featureNS: "myNameSpace",
            featureType: "myLayer"
        });

        $.ajax({
            type: "POST",
            url: "http://localhost:8080/geoserver/wfs",
            data: new XMLSerializer().serializeToString(node),
            contentType: 'text/xml',
            success: function(data) {
                alert((new XMLSerializer()).serializeToString(data));
            },
            error: function(e) {
                var errorMsg = e? (e.status + ' ' + e.statusText) : "";
                alert('Error saving this feature to GeoServer.<br><br>'
                + errorMsg);
            },
            context: this
        });

the drawing part works fine but for the updating I get an error:

<ows:ExceptionText>No such property: geometry</ows:ExceptionText>

the geometry column in my table and layer is "the_geom" so I double check it on my code with setGeometryName("the_geom") but yet when I make the AJAX call I get the error above.

The first thing that came to my mind is to change the geometry column name in my postgresql table to geometry and republish the layer in geoserver, but I want to know first if there is any less obedient solution for this, thanks in advance

After changing the geometry column name in postgresql to "geometry" I get now another error :

<ows:ExceptionText>java.lang.NullPointerException</ows:ExceptionText>

Solution

  • I changed the geometry column name into "geometry" and after that the error relative to the Java null pointer came, then I found out that the XML code generated was wrong and needs to be modified for it refers to a wrong typeName feature:myLayer while it should be myNameSpace:myLayer for this one all I had to do was to replace it with Javascript :

    var str=new XMLSerializer().serializeToString(node);
    var data=str.replace("feature:myLayer","myNameSpace:myLayer");