7

I created a linestring wfs layer in postgis table and published to geoserver. I am able to display the layer on the openlayers map but while editing the layer getting error:

{http://localhost:8090/geoserver/postgis_24_sample}sampleLine is read-only

below is my code for posting the edit data. Please suggest me how to clear this issue.

var transactWFS = function(mode, f) {     
          var gml = new ol.format.GML({
            featureNS: 'http://localhost:8090/geoserver',
            featureType: 'sampleLine',
            srsName: 'EPSG:3857'
         }); 
         var node;
         switch (mode){
            case 'insert':
                node = formatWFS.writeTransaction([f], null, null, gml);
                break;
            case 'update': 
                node = formatWFS.writeTransaction(null, [f], null, gml);
                break;
            case 'delete':
            node = formatWFS.writeTransaction(null, null, [f], gml);
            break;
          }
        var payload = xs.serializeToString(node);   
        $.ajax('http://localhost:8090/geoserver/postgis_24_sample/wfs', {
            type: 'POST',
            dataType: 'xml',
            processData: false,
            contentType: 'text/xml',
            data: payload
            }).done(function() {
                mySampleLineVectorLayer.getSource().clear();
            });     
        }

5 Answers 5

6

In Geoserver, under the Workspace where you imported the layer, you need to activate WFS, specifically WFS-T (WFS Transactional)

In the Geoserver menu, click on Workspaces, find your workspace and click on it. Toggle-on/check WFS.

enter image description here

Click on the WFS letters to the right of the checkbox to open WFS settings. Under 'Service Level' toggle-on 'Transactional' or 'Complete'

enter image description here

Also as mkeller has answered here, you may need to add ROLE_ANONYMOUS to the write rule under the Data menu enter image description here

or on the Service menu grant ROLE_ANONYMOUS access the the WFS Transactional.

enter image description here

1
  • In order for a POST to work from JavaScript you will also need to enable the anonymous role for write otherwise it will not work. I have tried what you have listed above and it does not work.
    – mkeller
    May 3, 2018 at 17:29
5

There are two things you need to change in GeoServer to makes this possible.

  1. Enable Transactional under the WFS tab on GeoServer
  2. Under the Data tab on GeoServer you need to edit the rule ..w to enable the role ROLE_ANONYMOUS

After doing these two things I was able to get rid of this error and post data to GeoServer.

4

You need to change your geoserver settings to make your WFS transactional

1
  • WHAT ARE THE CHANGES I NEED TO DO IN GEOSERVER
    – Surya
    Dec 12, 2017 at 12:35
1

By default the wfs layers are read-only. To make them updatable, you have to enable transaction feature as shown by cm1

0

Add a primary key constraint to the table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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