I am trying to insert properties in shapefile using Openlayer and WFS layer. I wrote my code and I believe it is correct because in response I am getting

<?xml version="1.0" encoding="UTF-8"?><wfs:TransactionResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:UK_Postal="http://www.openplans.org/uk_portal" xmlns:sf="http://www.openplans.org/spearfish" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:ows="http://www.opengis.net/ows" xmlns:tiger="http://www.census.gov" xmlns:topp="http://www.openplans.org/topp" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd"><wfs:TransactionSummary><wfs:totalInserted>1</wfs:totalInserted><wfs:totalUpdated>0</wfs:totalUpdated><wfs:totalDeleted>0</wfs:totalDeleted></wfs:TransactionSummary><wfs:TransactionResults/><wfs:InsertResults><wfs:Feature><ogc:FeatureId fid="new0"/></wfs:Feature></wfs:InsertResults></wfs:TransactionResponse>

As I am getting response you can check from complete stack


But when I am reading back I am not getting the extra property that I have added. Here is my code:

var formatWFS2 = new ol.format.WFS();
    var pointGML = new ol.format.GML({
        featureNS: 'http://www.openplans.org/uk_portal',
        featureType: 'AB_post',
        srsName: 'EPSG:3857',
    var pointWFS = function(p,f) {
        var node;
        switch(p) {
            case 'insert':
                node = formatWFS2.writeTransaction([f],null,null,pointGML);
            case 'update':
                node = formatWFS2.writeTransaction(null,[f],null,pointGML);
            case 'delete':
                node = formatWFS2.writeTransaction(null,null,[f],pointGML);
        var payload = new XMLSerializer().serializeToString(node);
                service: 'WFS',
                type: 'POST',
                dataType: 'xml',
                processData: false,
                contentType: 'text/xml',
                data: payload,
                success: function(data) {
                }, error: function(data) {
            }).done(function() {
                console.log(" point features were posted to server");

This is the json which I am adding and writing properties here:

wfs.html:139 {"type":"FeatureCollection","totalFeatures":1,"features":[{"type":"Feature","id":"AB_post.1","geometry":{"type":"MultiPolygon","coordinates":[[[[-233222.55760363,7790673.03403836],[-233223.96742674,7790673.41918759],[-233335.24515929,7790702.96970708],[-233301.26575108,7790777.5655439],[-233291.30310466,7790812.94485092],[-233217.13589042,7790756.28662714],[-233216.01896901,7790749.57981619],[-233211.98323025,7790748.84807779],[-233202.7519538,7790720.44402123],[-233196.2548373,7790706.68616474],[-233222.55760363,7790673.03403836]]]]},"geometry_name":"the_geom","properties":{"POSTCODE":"AB10 1AL","UPP":"00000000000000000003","PC_AREA":"AB","FERRETS":""}}],"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::3857"}}}

And this is how I am calling my method:

var newFeature = new ol.Feature({
            'ferrets': 12

This is my transanction XML

<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"><Insert><AB_post xmlns="http://www.openplans.org/uk_portal"><FERRETS>12</FERRETS></AB_post></Insert></Transaction>

Can you give me any suggestions?

  • Add also the generated Insert command. You can also copy that into the Demo request window of your GeoServer and try it directly. Shapefile format is kind of a toy format for GeoServer WFS and it is really suitable for testing only. I am remembering that GeoServer may well return "success" even if the transaction with shapefile fails. For reals needs use PostGIS.
    – user30184
    May 10 at 13:50
  • 1
    Not sure if understood well but you can't add a new column using WFS-T. You can only add new records but if your original records does not contain already the column, when you will try to send a new data to WFS end point, it will append the data but not add any column and store it. If you don't retrieve WFS data with a column ferrets don't expect to be able to update/fill it: it does not exist.
    – ThomasG77
    May 10 at 14:00
  • @ThomasG77 I have added a new column in dbf file with name ''ferrerts'. My new json layer I have updated above but still I am not able to update/insert the data
    – Piyush
    May 10 at 14:59
  • @user30184 I have added my transaction command also
    – Piyush
    May 10 at 15:23

You have created a new Feature with a single attribute called ferrets while your shapefile has an attribute called FERRETS so it will be dropped and a completely empty feature added to the shapefile. I'm not sure but I suspect that GeoServer doesn't bother to send null features back to the client.

If you want to add an attribute value to an existing feature then you must send that feature (with the new attribute set) to the server.

  • So how can I fix this?
    – Piyush
    May 11 at 5:23
  • select your feature, add the attribute and update it in WFS
    – Ian Turton
    May 11 at 7:41

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.