[Geoserver-users] OpenLayers GeoServer update an array of features using WFS-T

I changed the featureNS to a URI, still the same result. featureType should be “streets_freiburg”. I have checked this before.

The description says that the update element describes an operation that can be applied to a set of features, but in my case, I have multiple update elements. Maybe that is the problem… just a guess

image.png

···

On 22/01/2020 15:51, Vitor Fonseca wrote:

as per WFS 1.1.0 specification

image.png

so i think you problem is similar to this

https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you should check formatGML. featureType should be FR_TEST:streets_freiburg" and featureNS a URI (Namespace URI)

Vitor Fonseca <vfonsecaz@…84…> escreveu no dia quarta, 22/01/2020 à(s) 14:32:

so each update block has a different and valid fid?

This bit xmlns:feature=“FR_TEST” looks strange. What’s FR_TEST?
The wfs update examples I came across with only state the typeName property.

How did you create formatGML?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:20:

Yes, I deleted an update block because it was too long to be included in this email haha. There were two features.

2 update blocks basically.

The second one starts like :

the_geom 7.8322757 47.9760968 7.8321782 47.9759269 7.8320462 47.9756999 7.8319787 47.9756003 7.831903 47.9755152 7.83138 47.9749857 7.8311329 47.9747349 Street_Id 2399319 Src_Str_id 0 .........

I can’t use

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

because I am sending in an array of features already.

On 22/01/2020 15:21, Vitor Fonseca wrote:

Is that the complete request?

There’s only one feature there (

what if you replace this

node = formatWFS.writeTransaction(null, f, null, formatGML);

with

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:10:

Yes. It looks like this :

<?xml version="1.0" encoding="UTF-8"?>

<Transaction xmlns=“http://www.opengis.net/wfs” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” service=“WFS” version=“1.1.0” xsi:schemaLocation=“http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd”>


the_geom

<MultiLineString xmlns=“http://www.opengis.net/gml” srsName=“CRS:84”>


7.8311329 47.9747349 7.8310331 47.9746403






Street_Id
2414838


Src_Str_id
0


Full_Name
Schlierbergstraße


Class
6


One_way



Extra_Pass
0


Length
12.878


Speed
30


DrivingTim
0.0257


Serv_Area



From_Z
0


To_Z
0


Width
0


Veh_Size



LPriority
0


RPriority
0


ZipL



ZipR



LComment



RComment



LServeTime
0


RServeTime
0


BServeTime
0


LQuantity
0


RQuantity
0


BQuantity
0


LCusts
0


RCusts
0


BCusts
0


LUnits
0


RUnits
0


BUnits
0


LRevenue
0


RRevenue
0


BRevenue
0


LRoute
0


RRoute
0


BRoute
0


LRouteFile



RRouteFile



LCycle
0


RCycle
0


CycleLegnd
0


LFacil
0


RFacil
0


LFacilCost
0


RFacilCost
0


LSP
0


RSP
0


X_LRoute
0


X_RRoute
0


NetErr



NetErr_Ok



NetErr_Id
0


Up_Date
0


SameSelect
1


Serv_Mode



WalkingTim
0


ARA_BU_L
0


ARA_BU_R
0


Prefix



Name



Type



Suffix



L_F_Add



L_T_Add



R_F_Add



R_T_Add



RndAb
0


Exclude
0


OSM_ID
198512516


OSM_NameL
Schlierbergstraße


OSM_NameI



OSM_RdRef



OSM_Meta
lcn=yes, lit=yes, name=Schlierbergstraße, FIXME=recheck position and access, layer=1, bridge=yes, highway=residential, surface=asphalt, maxspeed=30, maxweight=3.5, motor_vehicle:back


Meters
12.878


Feet
42.25


OSM_KMH
30


OSM_MPH
18.641


OSM_Lanes
0


Po_Class
41


Po_Flags
3


PoEdge_id
315286


PoEId_Src
209581


PoEId_Trg
244684


Po_Car
1


Po_Bike
1


Po_Foot
0


Po_Area
0

<Filter xmlns=“http://www.opengis.net/ogc”>


On 22/01/2020 15:04, Vitor Fonseca wrote:

well i suggest you check the payload on the wfs request (using developer tools)
should be something like

<wfs:Transaction service=“WFS” version=“1.0.0”
xmlns:topp=“http://www.openplans.org/topp
xmlns:ogc=“http://www.opengis.net/ogc
xmlns:wfs=“http://www.opengis.net/wfs”>
<wfs:Update typeName=…

to see if there’s something strange there…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:55:

Yes. Like the example. I have already tried that.

On 22/01/2020 14:58, Vitor Fonseca wrote:

Ok got it.

have you tried creating the clone with var clone = new ol.Feature(featureProperties); instead of the clone function?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:01:

It is basically creating a copy of the feature which looks exactly the same except for the boundedBy property. So the geoserver identifies the feature you want to update using the id.

On 22/01/2020 13:59, Vitor Fonseca wrote:

Yes. But cloning creates new features right?

You are trying to update features that did not exist in the first place, and that GeoServer is not aware…i’m a bit confused now :slight_smile:

A quarta, 22/01/2020, 12:53, Vikram <vikram.eswar@…10264…> escreveu:

No I am trying to update features. If you look at the example that you shared, one has to create a clone in order to strip the boundedBy property from the feature.

On 22/01/2020 13:28, Vitor Fonseca wrote:

Wait a minute. Shouldn’t you be making insert’s instead of update’s?
You are creating new features after all…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 12:14:

Yes I have seen this example. Gives me the same result.

Now, I don’t get the assertion error anymore, I create the feature with WKT. But the end result is the same. I think the geoserver is not updating the features separately ie. it reads the features one by one, but stores the properties in the same variable, thus overwriting the properties every time. And then it updates all the features with this set of properties, thus making them all look alike.

have you also tried calling writeTransaction within a loop for updating one feature at a time?

I just tried this. It doesn’t produce the problem, I can see that it is called multiple times through the loop, but in the end, only one feature is updated…

On 22/01/2020 12:53, Vitor Fonseca wrote:

The browser console should give you a little bit more detail on the error…(expand all the error lines…)what’s the OL version?

check this example:
https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58

see the new feature created with…

var clone = new ol.Feature(featureProperties);

have you also tried calling writeTransaction within a loop for updating one feature at a time?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:40:

It says assertion failed at this line of code :

node = formatWFS.writeTransaction(null, f, null, formatGML);

Well I am not able to see where the fid is… I can only see id_ and ol_uid on the console. They are different for every clone.

On 22/01/2020 12:33, Vitor Fonseca wrote:

I have struggle in the past with the clone feature too.

You have different id’s in the clones or differente fid’s?
Because you’re setting “clone.setId(feature.getId());” and that’s not the “internal” feature ID.

BTW what exactly is the assertion error?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:24:

Hi Vitor,

Thanks for your reply.

The clone approach works fine for one feature ie. when I try to update one feature. I have checked the console and the clones have different IDs.

I tried creating feature with WKT, but got an assertion error while passing the created feature to the writeTransaction method…

Regards,

Vikram

On 22/01/2020 11:58, Vitor Fonseca wrote:

Hi,

I think this is a programming problem rather than a Geoserver problem.
From my experience the issue should be with the clone functionality.

Check this
https://gis.stackexchange.com/questions/46730/openlayers-cloned-features-get-style-from-original-feature

Someone mentions "I have noticed that cloned features share the same featureID as the original. " and this should be the problem when sending the features over to WFS-T…
You could try creating new features some other way (wkt…)

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 10:24:

HI all,

I am trying to update features using WFS-T update. I am sending the request from my website (OpenLayers) by passing an array of features.

However, I have noticed that the attributes and geometry of last feature in the array is copied to all other features.

For example, if I pass 5 features to the writeTransaction method to update an attribute of all 5 features, it copies the attributes and geometry of the 5th feature to the other features.

var clones = []
selectedFeatures.forEach(function (feature) {
    var featureProperties = feature.getProperties();

    delete featureProperties.boundedBy;
    var clone = feature.clone();
    clone.setId(feature.getId());

    clone.setGeometryName('the_geom');

    clone.setProperties({'xyz':'xyz'})

    clones.push(clone)

})
console.log(clones)
transactWFS('update_batch', clones);

int the transactWFS method,

transactWFS = function (mode, f) {

    var node;
    switch (mode) {
        case 'insert':
            node = formatWFS.writeTransaction([f], null, null, formatGML);
            break;
        case 'update':
            node = formatWFS.writeTransaction(null, [f], null, formatGML);
            break;
        case 'update_batch':
            node = formatWFS.writeTransaction(null, f, null, formatGML);
            break;
        case 'delete':
            node = formatWFS.writeTransaction(null, null, [f], formatGML);
            break;
    }
    var payload = xs.serializeToString(node);

    $.ajax('[http://localhost:8080/geoserver/TEST/ows](http://localhost:8080/geoserver/TEST/ows)', {
        service: 'WFS',
        type: 'POST',
        dataType: 'xml',
        processData: false,
        contentType: 'text/xml',
        data: payload,
        success: function(data) {

        },
        error: function(e) {
            var errorMsg = e? (e.status + ' ' + e.statusText) : "";
            alert('Error saving this feature to GeoServer.<br><br>'
                + errorMsg);
        }
    }).done(function() {
        wfsSource.refresh()

    });
};

Does anyone have a solution?

Regards,

Vikram


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

the spec refers multiple “update” elements…so multiple update blocks are permitted

I think the problem is typeName, and so you should change the formatGML constructor.
the update block should state

<Update typeName="FR_TEST:streets_freiburg">

without the xmlns:feature=“FR_TEST” part.

Looks exactly like the problem shown here
https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you could also check geoserver logs for a nullpointerexception

Vikram <vikram.eswar@anonymised.com> escreveu no dia quarta, 22/01/2020 à(s) 15:08:

image.png

···

www.vfonsecaz.pt

That is my formatGML code :

var formatGML = new ol.format.GML({
featureNS: ‘http://192.168.2.38:2020/geoserver/FR_TEST’,
featureType: ‘streets_freiburg’,
srsName: ‘CRS:84’
});

When I use featureType: ‘FR_TEST:streets_freiburg’, I have an error on the geoserver side, it does not find the feature layer.

With my current code,

I see :

Update xmlns:feature=“http://192.168.2.38:2020/geoserver/FR_TEST” typeName=“feature:streets_freiburg”

and there is no error on the geoserver log. It just does not work as expected…

image.png

···

On 22/01/2020 16:17, Vitor Fonseca wrote:

the spec refers multiple “update” elements…so multiple update blocks are permitted

I think the problem is typeName, and so you should change the formatGML constructor.
the update block should state

<Update typeName="FR_TEST:streets_freiburg">

without the xmlns:feature=“FR_TEST” part.

Looks exactly like the problem shown here
https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you could also check geoserver logs for a nullpointerexception

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:08:

I changed the featureNS to a URI, still the same result. featureType should be “streets_freiburg”. I have checked this before.

The description says that the update element describes an operation that can be applied to a set of features, but in my case, I have multiple update elements. Maybe that is the problem… just a guess

On 22/01/2020 15:51, Vitor Fonseca wrote:

as per WFS 1.1.0 specification

image.png

so i think you problem is similar to this

https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you should check formatGML. featureType should be FR_TEST:streets_freiburg" and featureNS a URI (Namespace URI)

Vitor Fonseca <vfonsecaz@…84…> escreveu no dia quarta, 22/01/2020 à(s) 14:32:

so each update block has a different and valid fid?

This bit xmlns:feature=“FR_TEST” looks strange. What’s FR_TEST?
The wfs update examples I came across with only state the typeName property.

How did you create formatGML?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:20:

Yes, I deleted an update block because it was too long to be included in this email haha. There were two features.

2 update blocks basically.

The second one starts like :

the_geom 7.8322757 47.9760968 7.8321782 47.9759269 7.8320462 47.9756999 7.8319787 47.9756003 7.831903 47.9755152 7.83138 47.9749857 7.8311329 47.9747349 Street_Id 2399319 Src_Str_id 0 .........

I can’t use

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

because I am sending in an array of features already.

On 22/01/2020 15:21, Vitor Fonseca wrote:

Is that the complete request?

There’s only one feature there (

what if you replace this

node = formatWFS.writeTransaction(null, f, null, formatGML);

with

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:10:

Yes. It looks like this :

<?xml version="1.0" encoding="UTF-8"?>

<Transaction xmlns=“http://www.opengis.net/wfs” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” service=“WFS” version=“1.1.0” xsi:schemaLocation=“http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd”>


the_geom

<MultiLineString xmlns=“http://www.opengis.net/gml” srsName=“CRS:84”>


7.8311329 47.9747349 7.8310331 47.9746403






Street_Id
2414838


Src_Str_id
0


Full_Name
Schlierbergstraße


Class
6


One_way



Extra_Pass
0


Length
12.878


Speed
30


DrivingTim
0.0257


Serv_Area



From_Z
0


To_Z
0


Width
0


Veh_Size



LPriority
0


RPriority
0


ZipL



ZipR



LComment



RComment



LServeTime
0


RServeTime
0


BServeTime
0


LQuantity
0


RQuantity
0


BQuantity
0


LCusts
0


RCusts
0


BCusts
0


LUnits
0


RUnits
0


BUnits
0


LRevenue
0


RRevenue
0


BRevenue
0


LRoute
0


RRoute
0


BRoute
0


LRouteFile



RRouteFile



LCycle
0


RCycle
0


CycleLegnd
0


LFacil
0


RFacil
0


LFacilCost
0


RFacilCost
0


LSP
0


RSP
0


X_LRoute
0


X_RRoute
0


NetErr



NetErr_Ok



NetErr_Id
0


Up_Date
0


SameSelect
1


Serv_Mode



WalkingTim
0


ARA_BU_L
0


ARA_BU_R
0


Prefix



Name



Type



Suffix



L_F_Add



L_T_Add



R_F_Add



R_T_Add



RndAb
0


Exclude
0


OSM_ID
198512516


OSM_NameL
Schlierbergstraße


OSM_NameI



OSM_RdRef



OSM_Meta
lcn=yes, lit=yes, name=Schlierbergstraße, FIXME=recheck position and access, layer=1, bridge=yes, highway=residential, surface=asphalt, maxspeed=30, maxweight=3.5, motor_vehicle:back


Meters
12.878


Feet
42.25


OSM_KMH
30


OSM_MPH
18.641


OSM_Lanes
0


Po_Class
41


Po_Flags
3


PoEdge_id
315286


PoEId_Src
209581


PoEId_Trg
244684


Po_Car
1


Po_Bike
1


Po_Foot
0


Po_Area
0

<Filter xmlns=“http://www.opengis.net/ogc”>


On 22/01/2020 15:04, Vitor Fonseca wrote:

well i suggest you check the payload on the wfs request (using developer tools)
should be something like

<wfs:Transaction service=“WFS” version=“1.0.0”
xmlns:topp=“http://www.openplans.org/topp
xmlns:ogc=“http://www.opengis.net/ogc
xmlns:wfs=“http://www.opengis.net/wfs”>
<wfs:Update typeName=…

to see if there’s something strange there…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:55:

Yes. Like the example. I have already tried that.

On 22/01/2020 14:58, Vitor Fonseca wrote:

Ok got it.

have you tried creating the clone with var clone = new ol.Feature(featureProperties); instead of the clone function?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:01:

It is basically creating a copy of the feature which looks exactly the same except for the boundedBy property. So the geoserver identifies the feature you want to update using the id.

On 22/01/2020 13:59, Vitor Fonseca wrote:

Yes. But cloning creates new features right?

You are trying to update features that did not exist in the first place, and that GeoServer is not aware…i’m a bit confused now :slight_smile:

A quarta, 22/01/2020, 12:53, Vikram <vikram.eswar@…10264…> escreveu:

No I am trying to update features. If you look at the example that you shared, one has to create a clone in order to strip the boundedBy property from the feature.

On 22/01/2020 13:28, Vitor Fonseca wrote:

Wait a minute. Shouldn’t you be making insert’s instead of update’s?
You are creating new features after all…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 12:14:

Yes I have seen this example. Gives me the same result.

Now, I don’t get the assertion error anymore, I create the feature with WKT. But the end result is the same. I think the geoserver is not updating the features separately ie. it reads the features one by one, but stores the properties in the same variable, thus overwriting the properties every time. And then it updates all the features with this set of properties, thus making them all look alike.

have you also tried calling writeTransaction within a loop for updating one feature at a time?

I just tried this. It doesn’t produce the problem, I can see that it is called multiple times through the loop, but in the end, only one feature is updated…

On 22/01/2020 12:53, Vitor Fonseca wrote:

The browser console should give you a little bit more detail on the error…(expand all the error lines…)what’s the OL version?

check this example:
https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58

see the new feature created with…

var clone = new ol.Feature(featureProperties);

have you also tried calling writeTransaction within a loop for updating one feature at a time?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:40:

It says assertion failed at this line of code :

node = formatWFS.writeTransaction(null, f, null, formatGML);

Well I am not able to see where the fid is… I can only see id_ and ol_uid on the console. They are different for every clone.

On 22/01/2020 12:33, Vitor Fonseca wrote:

I have struggle in the past with the clone feature too.

You have different id’s in the clones or differente fid’s?
Because you’re setting “clone.setId(feature.getId());” and that’s not the “internal” feature ID.

BTW what exactly is the assertion error?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:24:

Hi Vitor,

Thanks for your reply.

The clone approach works fine for one feature ie. when I try to update one feature. I have checked the console and the clones have different IDs.

I tried creating feature with WKT, but got an assertion error while passing the created feature to the writeTransaction method…

Regards,

Vikram

On 22/01/2020 11:58, Vitor Fonseca wrote:

Hi,

I think this is a programming problem rather than a Geoserver problem.
From my experience the issue should be with the clone functionality.

Check this
https://gis.stackexchange.com/questions/46730/openlayers-cloned-features-get-style-from-original-feature

Someone mentions "I have noticed that cloned features share the same featureID as the original. " and this should be the problem when sending the features over to WFS-T…
You could try creating new features some other way (wkt…)

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 10:24:

HI all,

I am trying to update features using WFS-T update. I am sending the request from my website (OpenLayers) by passing an array of features.

However, I have noticed that the attributes and geometry of last feature in the array is copied to all other features.

For example, if I pass 5 features to the writeTransaction method to update an attribute of all 5 features, it copies the attributes and geometry of the 5th feature to the other features.

var clones = []
selectedFeatures.forEach(function (feature) {
    var featureProperties = feature.getProperties();

    delete featureProperties.boundedBy;
    var clone = feature.clone();
    clone.setId(feature.getId());

    clone.setGeometryName('the_geom');

    clone.setProperties({'xyz':'xyz'})

    clones.push(clone)

})
console.log(clones)
transactWFS('update_batch', clones);

int the transactWFS method,

transactWFS = function (mode, f) {

    var node;
    switch (mode) {
        case 'insert':
            node = formatWFS.writeTransaction([f], null, null, formatGML);
            break;
        case 'update':
            node = formatWFS.writeTransaction(null, [f], null, formatGML);
            break;
        case 'update_batch':
            node = formatWFS.writeTransaction(null, f, null, formatGML);
            break;
        case 'delete':
            node = formatWFS.writeTransaction(null, null, [f], formatGML);
            break;
    }
    var payload = xs.serializeToString(node);

    $.ajax('[http://localhost:8080/geoserver/TEST/ows](http://localhost:8080/geoserver/TEST/ows)', {
        service: 'WFS',
        type: 'POST',
        dataType: 'xml',
        processData: false,
        contentType: 'text/xml',
        data: payload,
        success: function(data) {

        },
        error: function(e) {
            var errorMsg = e? (e.status + ' ' + e.statusText) : "";
            alert('Error saving this feature to GeoServer.<br><br>'
                + errorMsg);
        }
    }).done(function() {
        wfsSource.refresh()

    });
};

Does anyone have a solution?

Regards,

Vikram


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

I changed the update block manually and sent it to the server, it works without errors, but produces the same result.

image.png

···

On 22/01/2020 16:20, Vikram wrote:

That is my formatGML code :

var formatGML = new ol.format.GML({
featureNS: ‘http://192.168.2.38:2020/geoserver/FR_TEST’,
featureType: ‘streets_freiburg’,
srsName: ‘CRS:84’
});

When I use featureType: ‘FR_TEST:streets_freiburg’, I have an error on the geoserver side, it does not find the feature layer.

With my current code,

I see :

Update xmlns:feature=“http://192.168.2.38:2020/geoserver/FR_TEST” typeName=“feature:streets_freiburg”

and there is no error on the geoserver log. It just does not work as expected…

On 22/01/2020 16:17, Vitor Fonseca wrote:

the spec refers multiple “update” elements…so multiple update blocks are permitted

I think the problem is typeName, and so you should change the formatGML constructor.
the update block should state

<Update typeName="FR_TEST:streets_freiburg">

without the xmlns:feature=“FR_TEST” part.

Looks exactly like the problem shown here
https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you could also check geoserver logs for a nullpointerexception

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:08:

I changed the featureNS to a URI, still the same result. featureType should be “streets_freiburg”. I have checked this before.

The description says that the update element describes an operation that can be applied to a set of features, but in my case, I have multiple update elements. Maybe that is the problem… just a guess

On 22/01/2020 15:51, Vitor Fonseca wrote:

as per WFS 1.1.0 specification

image.png

so i think you problem is similar to this

https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you should check formatGML. featureType should be FR_TEST:streets_freiburg" and featureNS a URI (Namespace URI)

Vitor Fonseca <vfonsecaz@…84…> escreveu no dia quarta, 22/01/2020 à(s) 14:32:

so each update block has a different and valid fid?

This bit xmlns:feature=“FR_TEST” looks strange. What’s FR_TEST?
The wfs update examples I came across with only state the typeName property.

How did you create formatGML?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:20:

Yes, I deleted an update block because it was too long to be included in this email haha. There were two features.

2 update blocks basically.

The second one starts like :

the_geom 7.8322757 47.9760968 7.8321782 47.9759269 7.8320462 47.9756999 7.8319787 47.9756003 7.831903 47.9755152 7.83138 47.9749857 7.8311329 47.9747349 Street_Id 2399319 Src_Str_id 0 .........

I can’t use

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

because I am sending in an array of features already.

On 22/01/2020 15:21, Vitor Fonseca wrote:

Is that the complete request?

There’s only one feature there (

what if you replace this

node = formatWFS.writeTransaction(null, f, null, formatGML);

with

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:10:

Yes. It looks like this :

<?xml version="1.0" encoding="UTF-8"?>

<Transaction xmlns=“http://www.opengis.net/wfs” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” service=“WFS” version=“1.1.0” xsi:schemaLocation=“http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd”>


the_geom

<MultiLineString xmlns=“http://www.opengis.net/gml” srsName=“CRS:84”>


7.8311329 47.9747349 7.8310331 47.9746403






Street_Id
2414838


Src_Str_id
0


Full_Name
Schlierbergstraße


Class
6


One_way



Extra_Pass
0


Length
12.878


Speed
30


DrivingTim
0.0257


Serv_Area



From_Z
0


To_Z
0


Width
0


Veh_Size



LPriority
0


RPriority
0


ZipL



ZipR



LComment



RComment



LServeTime
0


RServeTime
0


BServeTime
0


LQuantity
0


RQuantity
0


BQuantity
0


LCusts
0


RCusts
0


BCusts
0


LUnits
0


RUnits
0


BUnits
0


LRevenue
0


RRevenue
0


BRevenue
0


LRoute
0


RRoute
0


BRoute
0


LRouteFile



RRouteFile



LCycle
0


RCycle
0


CycleLegnd
0


LFacil
0


RFacil
0


LFacilCost
0


RFacilCost
0


LSP
0


RSP
0


X_LRoute
0


X_RRoute
0


NetErr



NetErr_Ok



NetErr_Id
0


Up_Date
0


SameSelect
1


Serv_Mode



WalkingTim
0


ARA_BU_L
0


ARA_BU_R
0


Prefix



Name



Type



Suffix



L_F_Add



L_T_Add



R_F_Add



R_T_Add



RndAb
0


Exclude
0


OSM_ID
198512516


OSM_NameL
Schlierbergstraße


OSM_NameI



OSM_RdRef



OSM_Meta
lcn=yes, lit=yes, name=Schlierbergstraße, FIXME=recheck position and access, layer=1, bridge=yes, highway=residential, surface=asphalt, maxspeed=30, maxweight=3.5, motor_vehicle:back


Meters
12.878


Feet
42.25


OSM_KMH
30


OSM_MPH
18.641


OSM_Lanes
0


Po_Class
41


Po_Flags
3


PoEdge_id
315286


PoEId_Src
209581


PoEId_Trg
244684


Po_Car
1


Po_Bike
1


Po_Foot
0


Po_Area
0

<Filter xmlns=“http://www.opengis.net/ogc”>


On 22/01/2020 15:04, Vitor Fonseca wrote:

well i suggest you check the payload on the wfs request (using developer tools)
should be something like

<wfs:Transaction service=“WFS” version=“1.0.0”
xmlns:topp=“http://www.openplans.org/topp
xmlns:ogc=“http://www.opengis.net/ogc
xmlns:wfs=“http://www.opengis.net/wfs”>
<wfs:Update typeName=…

to see if there’s something strange there…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:55:

Yes. Like the example. I have already tried that.

On 22/01/2020 14:58, Vitor Fonseca wrote:

Ok got it.

have you tried creating the clone with var clone = new ol.Feature(featureProperties); instead of the clone function?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:01:

It is basically creating a copy of the feature which looks exactly the same except for the boundedBy property. So the geoserver identifies the feature you want to update using the id.

On 22/01/2020 13:59, Vitor Fonseca wrote:

Yes. But cloning creates new features right?

You are trying to update features that did not exist in the first place, and that GeoServer is not aware…i’m a bit confused now :slight_smile:

A quarta, 22/01/2020, 12:53, Vikram <vikram.eswar@…10264…> escreveu:

No I am trying to update features. If you look at the example that you shared, one has to create a clone in order to strip the boundedBy property from the feature.

On 22/01/2020 13:28, Vitor Fonseca wrote:

Wait a minute. Shouldn’t you be making insert’s instead of update’s?
You are creating new features after all…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 12:14:

Yes I have seen this example. Gives me the same result.

Now, I don’t get the assertion error anymore, I create the feature with WKT. But the end result is the same. I think the geoserver is not updating the features separately ie. it reads the features one by one, but stores the properties in the same variable, thus overwriting the properties every time. And then it updates all the features with this set of properties, thus making them all look alike.

have you also tried calling writeTransaction within a loop for updating one feature at a time?

I just tried this. It doesn’t produce the problem, I can see that it is called multiple times through the loop, but in the end, only one feature is updated…

On 22/01/2020 12:53, Vitor Fonseca wrote:

The browser console should give you a little bit more detail on the error…(expand all the error lines…)what’s the OL version?

check this example:
https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58

see the new feature created with…

var clone = new ol.Feature(featureProperties);

have you also tried calling writeTransaction within a loop for updating one feature at a time?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:40:

It says assertion failed at this line of code :

node = formatWFS.writeTransaction(null, f, null, formatGML);

Well I am not able to see where the fid is… I can only see id_ and ol_uid on the console. They are different for every clone.

On 22/01/2020 12:33, Vitor Fonseca wrote:

I have struggle in the past with the clone feature too.

You have different id’s in the clones or differente fid’s?
Because you’re setting “clone.setId(feature.getId());” and that’s not the “internal” feature ID.

BTW what exactly is the assertion error?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:24:

Hi Vitor,

Thanks for your reply.

The clone approach works fine for one feature ie. when I try to update one feature. I have checked the console and the clones have different IDs.

I tried creating feature with WKT, but got an assertion error while passing the created feature to the writeTransaction method…

Regards,

Vikram

On 22/01/2020 11:58, Vitor Fonseca wrote:

Hi,

I think this is a programming problem rather than a Geoserver problem.
From my experience the issue should be with the clone functionality.

Check this
https://gis.stackexchange.com/questions/46730/openlayers-cloned-features-get-style-from-original-feature

Someone mentions "I have noticed that cloned features share the same featureID as the original. " and this should be the problem when sending the features over to WFS-T…
You could try creating new features some other way (wkt…)

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 10:24:

HI all,

I am trying to update features using WFS-T update. I am sending the request from my website (OpenLayers) by passing an array of features.

However, I have noticed that the attributes and geometry of last feature in the array is copied to all other features.

For example, if I pass 5 features to the writeTransaction method to update an attribute of all 5 features, it copies the attributes and geometry of the 5th feature to the other features.

var clones = []
selectedFeatures.forEach(function (feature) {
    var featureProperties = feature.getProperties();

    delete featureProperties.boundedBy;
    var clone = feature.clone();
    clone.setId(feature.getId());

    clone.setGeometryName('the_geom');

    clone.setProperties({'xyz':'xyz'})

    clones.push(clone)

})
console.log(clones)
transactWFS('update_batch', clones);

int the transactWFS method,

transactWFS = function (mode, f) {

    var node;
    switch (mode) {
        case 'insert':
            node = formatWFS.writeTransaction([f], null, null, formatGML);
            break;
        case 'update':
            node = formatWFS.writeTransaction(null, [f], null, formatGML);
            break;
        case 'update_batch':
            node = formatWFS.writeTransaction(null, f, null, formatGML);
            break;
        case 'delete':
            node = formatWFS.writeTransaction(null, null, [f], formatGML);
            break;
    }
    var payload = xs.serializeToString(node);

    $.ajax('[http://localhost:8080/geoserver/TEST/ows](http://localhost:8080/geoserver/TEST/ows)', {
        service: 'WFS',
        type: 'POST',
        dataType: 'xml',
        processData: false,
        contentType: 'text/xml',
        data: payload,
        success: function(data) {

        },
        error: function(e) {
            var errorMsg = e? (e.status + ' ' + e.statusText) : "";
            alert('Error saving this feature to GeoServer.<br><br>'
                + errorMsg);
        }
    }).done(function() {
        wfsSource.refresh()

    });
};

Does anyone have a solution?

Regards,

Vikram


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

_______________________________________________
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:
- Earning your support instead of buying it, but Ian Turton: [http://www.ianturton.com/talks/foss4g.html#/](http://www.ianturton.com/talks/foss4g.html#/)
- The GeoServer user list posting guidelines: [http://geoserver.org/comm/userlist-guidelines.html](http://geoserver.org/comm/userlist-guidelines.html)

If you want to request a feature or an improvement, also see this: [https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer](https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer)

[Geoserver-users@lists.sourceforge.net](mailto:Geoserver-users@lists.sourceforge.net)
[https://lists.sourceforge.net/lists/listinfo/geoserver-users](https://lists.sourceforge.net/lists/listinfo/geoserver-users)

another similar error
https://gis.stackexchange.com/questions/214850/editing-wfs-layer

featureNS should be the geoserver workspace Namespace URI

chrome-capture (15).jpg

Vikram <vikram.eswar@anonymised.com> escreveu no dia quarta, 22/01/2020 à(s) 15:30:

image.png

···

www.vfonsecaz.pt

Tried it too, same result.

But if the featureNS is wrong, I should get an error which I don’t.

image001.png

image.png

···

On 22/01/2020 16:44, Vitor Fonseca wrote:

another similar error
https://gis.stackexchange.com/questions/214850/editing-wfs-layer

featureNS should be the geoserver workspace Namespace URI

chrome-capture (15).jpg

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:30:

I changed the update block manually and sent it to the server, it works without errors, but produces the same result.

On 22/01/2020 16:20, Vikram wrote:

That is my formatGML code :

var formatGML = new ol.format.GML({
featureNS: ‘http://192.168.2.38:2020/geoserver/FR_TEST’,
featureType: ‘streets_freiburg’,
srsName: ‘CRS:84’
});

When I use featureType: ‘FR_TEST:streets_freiburg’, I have an error on the geoserver side, it does not find the feature layer.

With my current code,

I see :

Update xmlns:feature=“http://192.168.2.38:2020/geoserver/FR_TEST” typeName=“feature:streets_freiburg”

and there is no error on the geoserver log. It just does not work as expected…

On 22/01/2020 16:17, Vitor Fonseca wrote:

the spec refers multiple “update” elements…so multiple update blocks are permitted

I think the problem is typeName, and so you should change the formatGML constructor.
the update block should state

<Update typeName="FR_TEST:streets_freiburg">

without the xmlns:feature=“FR_TEST” part.

Looks exactly like the problem shown here
https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you could also check geoserver logs for a nullpointerexception

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:08:

I changed the featureNS to a URI, still the same result. featureType should be “streets_freiburg”. I have checked this before.

The description says that the update element describes an operation that can be applied to a set of features, but in my case, I have multiple update elements. Maybe that is the problem… just a guess

On 22/01/2020 15:51, Vitor Fonseca wrote:

as per WFS 1.1.0 specification

image.png

so i think you problem is similar to this

https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you should check formatGML. featureType should be FR_TEST:streets_freiburg" and featureNS a URI (Namespace URI)

Vitor Fonseca <vfonsecaz@…84…> escreveu no dia quarta, 22/01/2020 à(s) 14:32:

so each update block has a different and valid fid?

This bit xmlns:feature=“FR_TEST” looks strange. What’s FR_TEST?
The wfs update examples I came across with only state the typeName property.

How did you create formatGML?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:20:

Yes, I deleted an update block because it was too long to be included in this email haha. There were two features.

2 update blocks basically.

The second one starts like :

the_geom 7.8322757 47.9760968 7.8321782 47.9759269 7.8320462 47.9756999 7.8319787 47.9756003 7.831903 47.9755152 7.83138 47.9749857 7.8311329 47.9747349 Street_Id 2399319 Src_Str_id 0 .........

I can’t use

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

because I am sending in an array of features already.

On 22/01/2020 15:21, Vitor Fonseca wrote:

Is that the complete request?

There’s only one feature there (

what if you replace this

node = formatWFS.writeTransaction(null, f, null, formatGML);

with

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:10:

Yes. It looks like this :

<?xml version="1.0" encoding="UTF-8"?>

<Transaction xmlns=“http://www.opengis.net/wfs” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” service=“WFS” version=“1.1.0” xsi:schemaLocation=“http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd”>


the_geom

<MultiLineString xmlns=“http://www.opengis.net/gml” srsName=“CRS:84”>


7.8311329 47.9747349 7.8310331 47.9746403






Street_Id
2414838


Src_Str_id
0


Full_Name
Schlierbergstraße


Class
6


�� One_way



Extra_Pass
0


Length
12.878


Speed
30


DrivingTim
0.0257


Serv_Area



From_Z
0


To_Z
0


Width
0


Veh_Size



LPriority
0


RPriority
0


ZipL



ZipR



LComment



RComment



LServeTime
0


RServeTime
0


BServeTime
0


LQuantity
0


RQuantity
0


BQuantity
0


LCusts
0


RCusts
0


BCusts
0


LUnits
0


RUnits
0


BUnits
0


LRevenue
0


RRevenue
0


BRevenue
0


LRoute
0


RRoute
0


BRoute
0


LRouteFile



RRouteFile



LCycle
0


RCycle
0


CycleLegnd
0


LFacil
0


RFacil
0


LFacilCost
0


RFacilCost
0


LSP
0


RSP
0


X_LRoute
0


X_RRoute
0


NetErr



NetErr_Ok



NetErr_Id
0


Up_Date
0


SameSelect
1


Serv_Mode



WalkingTim
0


ARA_BU_L
0


ARA_BU_R
0


Prefix



Name



Type



Suffix



L_F_Add



L_T_Add



R_F_Add



R_T_Add



RndAb
0


Exclude
0


OSM_ID
198512516


OSM_NameL
Schlierbergstraße


OSM_NameI



OSM_RdRef



OSM_Meta
lcn=yes, lit=yes, name=Schlierbergstraße, FIXME=recheck position and access, layer=1, bridge=yes, highway=residential, surface=asphalt, maxspeed=30, maxweight=3.5, motor_vehicle:back


Meters
12.878


Feet
42.25


OSM_KMH
30


OSM_MPH
18.641


OSM_Lanes
0


Po_Class
41


Po_Flags
3


PoEdge_id
315286


PoEId_Src
209581


PoEId_Trg
244684


Po_Car
1


Po_Bike
1


Po_Foot
0


Po_Area
0

<Filter xmlns=“http://www.opengis.net/ogc”>


On 22/01/2020 15:04, Vitor Fonseca wrote:

well i suggest you check the payload on the wfs request (using developer tools)
should be something like

<wfs:Transaction service=“WFS” version=“1.0.0”
xmlns:topp=“http://www.openplans.org/topp
xmlns:ogc=“http://www.opengis.net/ogc
xmlns:wfs=“http://www.opengis.net/wfs”>
<wfs:Update typeName=…

to see if there’s something strange there…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:55:

Yes. Like the example. I have already tried that.

On 22/01/2020 14:58, Vitor Fonseca wrote:

Ok got it.

have you tried creating the clone with var clone = new ol.Feature(featureProperties); instead of the clone function?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:01:

It is basically creating a copy of the feature which looks exactly the same except for the boundedBy property. So the geoserver identifies the feature you want to update using the id.

On 22/01/2020 13:59, Vitor Fonseca wrote:

Yes. But cloning creates new features right?

You are trying to update features that did not exist in the first place, and that GeoServer is not aware…i’m a bit confused now :slight_smile:

A quarta, 22/01/2020, 12:53, Vikram <vikram.eswar@…10264…> escreveu:

No I am trying to update features. If you look at the example that you shared, one has to create a clone in order to strip the boundedBy property from the feature.

On 22/01/2020 13:28, Vitor Fonseca wrote:

Wait a minute. Shouldn’t you be making insert’s instead of update’s?
You are creating new features after all…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 12:14:

Yes I have seen this example. Gives me the same result.

Now, I don’t get the assertion error anymore, I create the feature with WKT. But the end result is the same. I think the geoserver is not updating the features separately ie. it reads the features one by one, but stores the properties in the same variable, thus overwriting the properties every time. And then it updates all the features with this set of properties, thus making them all look alike.

have you also tried calling writeTransaction within a loop for updating one feature at a time?

I just tried this. It doesn’t produce the problem, I can see that it is called multiple times through the loop, but in the end, only one feature is updated…

On 22/01/2020 12:53, Vitor Fonseca wrote:

The browser console should give you a little bit more detail on the error…(expand all the error lines…)what’s the OL version?

check this example:
https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58

see the new feature created with…

var clone = new ol.Feature(featureProperties);

have you also tried calling writeTransaction within a loop for updating one feature at a time?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:40:

It says assertion failed at this line of code :

node = formatWFS.writeTransaction(null, f, null, formatGML);

Well I am not able to see where the fid is… I can only see id_ and ol_uid on the console. They are different for every clone.

On 22/01/2020 12:33, Vitor Fonseca wrote:

I have struggle in the past with the clone feature too.

You have different id’s in the clones or differente fid’s?
Because you’re setting “clone.setId(feature.getId());” and that’s not the “internal” feature ID.

BTW what exactly is the assertion error?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:24:

Hi Vitor,

Thanks for your reply.

The clone approach works fine for one feature ie. when I try to update one feature. I have checked the console and the clones have different IDs.

I tried creating feature with WKT, but got an assertion error while passing the created feature to the writeTransaction method…

Regards,

Vikram

On 22/01/2020 11:58, Vitor Fonseca wrote:

Hi,

I think this is a programming problem rather than a Geoserver problem.
From my experience the issue should be with the clone functionality.

Check this
https://gis.stackexchange.com/questions/46730/openlayers-cloned-features-get-style-from-original-feature

Someone mentions "I have noticed that cloned features share the same featureID as the original. " and this should be the problem when sending the features over to WFS-T…
You could try creating new features some other way (wkt…)

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 10:24:

HI all,

I am trying to update features using WFS-T update. I am sending the request from my website (OpenLayers) by passing an array of features.

However, I have noticed that the attributes and geometry of last feature in the array is copied to all other features.

For example, if I pass 5 features to the writeTransaction method to update an attribute of all 5 features, it copies the attributes and geometry of the 5th feature to the other features.

var clones = []
selectedFeatures.forEach(function (feature) {
    var featureProperties = feature.getProperties();

    delete featureProperties.boundedBy;
    var clone = feature.clone();
    clone.setId(feature.getId());

    clone.setGeometryName('the_geom');

    clone.setProperties({'xyz':'xyz'})

    clones.push(clone)

})
console.log(clones)
transactWFS('update_batch', clones);

int the transactWFS method,

transactWFS = function (mode, f) {

    var node;
    switch (mode) {
        case 'insert':
            node = formatWFS.writeTransaction([f], null, null, formatGML);
            break;
        case 'update':
            node = formatWFS.writeTransaction(null, [f], null, formatGML);
            break;
        case 'update_batch':
            node = formatWFS.writeTransaction(null, f, null, formatGML);
            break;
        case 'delete':
            node = formatWFS.writeTransaction(null, null, [f], formatGML);
            break;
    }
    var payload = xs.serializeToString(node);

    $.ajax('[http://localhost:8080/geoserver/TEST/ows](http://localhost:8080/geoserver/TEST/ows)', {
        service: 'WFS',
        type: 'POST',
        dataType: 'xml',
        processData: false,
        contentType: 'text/xml',
        data: payload,
        success: function(data) {

        },
        error: function(e) {
            var errorMsg = e? (e.status + ' ' + e.statusText) : "";
            alert('Error saving this feature to GeoServer.<br><br>'
                + errorMsg);
        }
    }).done(function() {
        wfsSource.refresh()

    });
};

Does anyone have a solution?

Regards,

Vikram


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

_______________________________________________
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:
- Earning your support instead of buying it, but Ian Turton: [http://www.ianturton.com/talks/foss4g.html#/](http://www.ianturton.com/talks/foss4g.html#/)
- The GeoServer user list posting guidelines: [http://geoserver.org/comm/userlist-guidelines.html](http://geoserver.org/comm/userlist-guidelines.html)

If you want to request a feature or an improvement, also see this: [https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer](https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer)

[Geoserver-users@lists.sourceforge.net](mailto:Geoserver-users@lists.sourceforge.net)
[https://lists.sourceforge.net/lists/listinfo/geoserver-users](https://lists.sourceforge.net/lists/listinfo/geoserver-users)


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

Tried it too, same result.

But if the featureNS is wrong, I should get an error which I don’t…

image001.png

image.png

···

On 22/01/2020 16:44, Vitor Fonseca wrote:

another similar error
https://gis.stackexchange.com/questions/214850/editing-wfs-layer

featureNS should be the geoserver workspace Namespace URI

chrome-capture (15).jpg

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:30:

I changed the update block manually and sent it to the server, it works without errors, but produces the same result.

On 22/01/2020 16:20, Vikram wrote:

That is my formatGML code :

var formatGML = new ol.format.GML({
featureNS: ‘http://192.168.2.38:2020/geoserver/FR_TEST’,
featureType: ‘streets_freiburg’,
srsName: ‘CRS:84’
});

When I use featureType: ‘FR_TEST:streets_freiburg’, I have an error on the geoserver side, it does not find the feature layer.

With my current code,

I see :

Update xmlns:feature=“http://192.168.2.38:2020/geoserver/FR_TEST” typeName=“feature:streets_freiburg”

and there is no error on the geoserver log. It just does not work as expected…

On 22/01/2020 16:17, Vitor Fonseca wrote:

the spec refers multiple “update” elements…so multiple update blocks are permitted

I think the problem is typeName, and so you should change the formatGML constructor.
the update block should state

<Update typeName="FR_TEST:streets_freiburg">

without the xmlns:feature=“FR_TEST” part.

Looks exactly like the problem shown here
https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you could also check geoserver logs for a nullpointerexception

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:08:

I changed the featureNS to a URI, still the same result. featureType should be “streets_freiburg”. I have checked this before.

The description says that the update element describes an operation that can be applied to a set of features, but in my case, I have multiple update elements. Maybe that is the problem… just a guess

On 22/01/2020 15:51, Vitor Fonseca wrote:

as per WFS 1.1.0 specification

image.png

so i think you problem is similar to this

https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you should check formatGML. featureType should be FR_TEST:streets_freiburg" and featureNS a URI (Namespace URI)

Vitor Fonseca <vfonsecaz@…84…> escreveu no dia quarta, 22/01/2020 à(s) 14:32:

so each update block has a different and valid fid?

This bit xmlns:feature=“FR_TEST” looks strange. What’s FR_TEST?
The wfs update examples I came across with only state the typeName property.

How did you create formatGML?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:20:

Yes, I deleted an update block because it was too long to be included in this email haha. There were two features.

2 update blocks basically.

The second one starts like :

the_geom 7.8322757 47.9760968 7.8321782 47.9759269 7.8320462 47.9756999 7.8319787 47.9756003 7.831903 47.9755152 7.83138 47.9749857 7.8311329 47.9747349 Street_Id 2399319 Src_Str_id 0 .........

I can’t use

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

because I am sending in an array of features already.

On 22/01/2020 15:21, Vitor Fonseca wrote:

Is that the complete request?

There’s only one feature there (

what if you replace this

node = formatWFS.writeTransaction(null, f, null, formatGML);

with

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:10:

Yes. It looks like this :

<?xml version="1.0" encoding="UTF-8"?>

<Transaction xmlns=“http://www.opengis.net/wfs” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” service=“WFS” version=“1.1.0” xsi:schemaLocation=“http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd”>


the_geom

<MultiLineString xmlns=“http://www.opengis.net/gml” srsName=“CRS:84”>


7.8311329 47.9747349 7.8310331 47.9746403






Street_Id
2414838


Src_Str_id
0


Full_Name
Schlierbergstraße


Class
6


�� One_way



Extra_Pass
0


Length
12.878


Speed
30


DrivingTim
0.0257


Serv_Area



From_Z
0


To_Z
0


Width
0


Veh_Size



LPriority
0


RPriority
0


ZipL



ZipR



LComment



RComment



LServeTime
0


RServeTime
0


BServeTime
0


LQuantity
0


RQuantity
0


BQuantity
0


LCusts
0


RCusts
0


BCusts
0


LUnits
0


RUnits
0


BUnits
0


LRevenue
0


RRevenue
0


BRevenue
0


LRoute
0


RRoute
0


BRoute
0


LRouteFile



RRouteFile



LCycle
0


RCycle
0


CycleLegnd
0


LFacil
0


RFacil
0


LFacilCost
0


RFacilCost
0


LSP
0


RSP
0


X_LRoute
0


X_RRoute
0


NetErr



NetErr_Ok



NetErr_Id
0


Up_Date
0


SameSelect
1


Serv_Mode



WalkingTim
0


ARA_BU_L
0


ARA_BU_R
0


Prefix



Name



Type



Suffix



L_F_Add



L_T_Add



R_F_Add



R_T_Add



RndAb
0


Exclude
0


OSM_ID
198512516


OSM_NameL
Schlierbergstraße


OSM_NameI



OSM_RdRef



OSM_Meta
lcn=yes, lit=yes, name=Schlierbergstraße, FIXME=recheck position and access, layer=1, bridge=yes, highway=residential, surface=asphalt, maxspeed=30, maxweight=3.5, motor_vehicle:back


Meters
12.878


Feet
42.25


OSM_KMH
30


OSM_MPH
18.641


OSM_Lanes
0


Po_Class
41


Po_Flags
3


PoEdge_id
315286


PoEId_Src
209581


PoEId_Trg
244684


Po_Car
1


Po_Bike
1


Po_Foot
0


Po_Area
0

<Filter xmlns=“http://www.opengis.net/ogc”>


On 22/01/2020 15:04, Vitor Fonseca wrote:

well i suggest you check the payload on the wfs request (using developer tools)
should be something like

<wfs:Transaction service=“WFS” version=“1.0.0”
xmlns:topp=“http://www.openplans.org/topp
xmlns:ogc=“http://www.opengis.net/ogc
xmlns:wfs=“http://www.opengis.net/wfs”>
<wfs:Update typeName=…

to see if there’s something strange there…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:55:

Yes. Like the example. I have already tried that.

On 22/01/2020 14:58, Vitor Fonseca wrote:

Ok got it.

have you tried creating the clone with var clone = new ol.Feature(featureProperties); instead of the clone function?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:01:

It is basically creating a copy of the feature which looks exactly the same except for the boundedBy property. So the geoserver identifies the feature you want to update using the id.

On 22/01/2020 13:59, Vitor Fonseca wrote:

Yes. But cloning creates new features right?

You are trying to update features that did not exist in the first place, and that GeoServer is not aware…i’m a bit confused now :slight_smile:

A quarta, 22/01/2020, 12:53, Vikram <vikram.eswar@…10264…> escreveu:

No I am trying to update features. If you look at the example that you shared, one has to create a clone in order to strip the boundedBy property from the feature.

On 22/01/2020 13:28, Vitor Fonseca wrote:

Wait a minute. Shouldn’t you be making insert’s instead of update’s?
You are creating new features after all…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 12:14:

Yes I have seen this example. Gives me the same result.

Now, I don’t get the assertion error anymore, I create the feature with WKT. But the end result is the same. I think the geoserver is not updating the features separately ie. it reads the features one by one, but stores the properties in the same variable, thus overwriting the properties every time. And then it updates all the features with this set of properties, thus making them all look alike.

have you also tried calling writeTransaction within a loop for updating one feature at a time?

I just tried this. It doesn’t produce the problem, I can see that it is called multiple times through the loop, but in the end, only one feature is updated…

On 22/01/2020 12:53, Vitor Fonseca wrote:

The browser console should give you a little bit more detail on the error…(expand all the error lines…)what’s the OL version?

check this example:
https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58

see the new feature created with…

var clone = new ol.Feature(featureProperties);

have you also tried calling writeTransaction within a loop for updating one feature at a time?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:40:

It says assertion failed at this line of code :

node = formatWFS.writeTransaction(null, f, null, formatGML);

Well I am not able to see where the fid is… I can only see id_ and ol_uid on the console. They are different for every clone.

On 22/01/2020 12:33, Vitor Fonseca wrote:

I have struggle in the past with the clone feature too.

You have different id’s in the clones or differente fid’s?
Because you’re setting “clone.setId(feature.getId());” and that’s not the “internal” feature ID.

BTW what exactly is the assertion error?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:24:

Hi Vitor,

Thanks for your reply.

The clone approach works fine for one feature ie. when I try to update one feature. I have checked the console and the clones have different IDs.

I tried creating feature with WKT, but got an assertion error while passing the created feature to the writeTransaction method…

Regards,

Vikram

On 22/01/2020 11:58, Vitor Fonseca wrote:

Hi,

I think this is a programming problem rather than a Geoserver problem.
From my experience the issue should be with the clone functionality.

Check this
https://gis.stackexchange.com/questions/46730/openlayers-cloned-features-get-style-from-original-feature

Someone mentions "I have noticed that cloned features share the same featureID as the original. " and this should be the problem when sending the features over to WFS-T…
You could try creating new features some other way (wkt…)

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 10:24:

HI all,

I am trying to update features using WFS-T update. I am sending the request from my website (OpenLayers) by passing an array of features.

However, I have noticed that the attributes and geometry of last feature in the array is copied to all other features.

For example, if I pass 5 features to the writeTransaction method to update an attribute of all 5 features, it copies the attributes and geometry of the 5th feature to the other features.

var clones = []
selectedFeatures.forEach(function (feature) {
    var featureProperties = feature.getProperties();

    delete featureProperties.boundedBy;
    var clone = feature.clone();
    clone.setId(feature.getId());

    clone.setGeometryName('the_geom');

    clone.setProperties({'xyz':'xyz'})

    clones.push(clone)

})
console.log(clones)
transactWFS('update_batch', clones);

int the transactWFS method,

transactWFS = function (mode, f) {

    var node;
    switch (mode) {
        case 'insert':
            node = formatWFS.writeTransaction([f], null, null, formatGML);
            break;
        case 'update':
            node = formatWFS.writeTransaction(null, [f], null, formatGML);
            break;
        case 'update_batch':
            node = formatWFS.writeTransaction(null, f, null, formatGML);
            break;
        case 'delete':
            node = formatWFS.writeTransaction(null, null, [f], formatGML);
            break;
    }
    var payload = xs.serializeToString(node);

    $.ajax('[http://localhost:8080/geoserver/TEST/ows](http://localhost:8080/geoserver/TEST/ows)', {
        service: 'WFS',
        type: 'POST',
        dataType: 'xml',
        processData: false,
        contentType: 'text/xml',
        data: payload,
        success: function(data) {

        },
        error: function(e) {
            var errorMsg = e? (e.status + ' ' + e.statusText) : "";
            alert('Error saving this feature to GeoServer.<br><br>'
                + errorMsg);
        }
    }).done(function() {
        wfsSource.refresh()

    });
};

Does anyone have a solution?

Regards,

Vikram


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

_______________________________________________
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:
- Earning your support instead of buying it, but Ian Turton: [http://www.ianturton.com/talks/foss4g.html#/](http://www.ianturton.com/talks/foss4g.html#/)
- The GeoServer user list posting guidelines: [http://geoserver.org/comm/userlist-guidelines.html](http://geoserver.org/comm/userlist-guidelines.html)

If you want to request a feature or an improvement, also see this: [https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer](https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer)

[Geoserver-users@lists.sourceforge.net](mailto:Geoserver-users@lists.sourceforge.net)
[https://lists.sourceforge.net/lists/listinfo/geoserver-users](https://lists.sourceforge.net/lists/listinfo/geoserver-users)


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

Tried it too, same result.

But if the featureNS is wrong, I should get an error which I don't.

seems there’s a lot of people facing the same problem…
https://gis.stackexchange.com/questions/193761/wrong-typename-generated-by-wfs-t-update-request-in-xml

geoserver log should show something. make sure verbose logging is active…

also try GML3 instead of GML

I can only think of some versioning conflict…maybe wfs version vs ol version vs gml version…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:50:

image001.png

image.png

···

www.vfonsecaz.pt

Okay I will look at the versions… On the GeoServer console, it looks fine, no errors and the update is completed. I will try GML3 to start with…

image001.png

image.png

···

On 22/01/2020 16:57, Vitor Fonseca wrote:

seems there’s a lot of people facing the same problem…
https://gis.stackexchange.com/questions/193761/wrong-typename-generated-by-wfs-t-update-request-in-xml

geoserver log should show something. make sure verbose logging is active…

also try GML3 instead of GML

I can only think of some versioning conflict…maybe wfs version vs ol version vs gml version…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:50:

Tried it too, same result.

But if the featureNS is wrong, I should get an error which I don’t.

On 22/01/2020 16:44, Vitor Fonseca wrote:

another similar error
https://gis.stackexchange.com/questions/214850/editing-wfs-layer

featureNS should be the geoserver workspace Namespace URI

chrome-capture (15).jpg

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:30:

I changed the update block manually and sent it to the server, it works without errors, but produces the same result.

On 22/01/2020 16:20, Vikram wrote:

That is my formatGML code :

var formatGML = new ol.format.GML({
featureNS: ‘http://192.168.2.38:2020/geoserver/FR_TEST’,
featureType: ‘streets_freiburg’,
srsName: ‘CRS:84’
});

When I use featureType: ‘FR_TEST:streets_freiburg’, I have an error on the geoserver side, it does not find the feature layer.

With my current code,

I see :

Update xmlns:feature=“http://192.168.2.38:2020/geoserver/FR_TEST” typeName=“feature:streets_freiburg”

and there is no error on the geoserver log. It just does not work as expected…

On 22/01/2020 16:17, Vitor Fonseca wrote:

the spec refers multiple “update” elements…so multiple update blocks are permitted

I think the problem is typeName, and so you should change the formatGML constructor.
the update block should state

<Update typeName="FR_TEST:streets_freiburg">

without the xmlns:feature=“FR_TEST” part.

Looks exactly like the problem shown here
https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you could also check geoserver logs for a nullpointerexception

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:08:

I changed the featureNS to a URI, still the same result. featureType should be “streets_freiburg”. I have checked this before.

The description says that the update element describes an operation that can be applied to a set of features, but in my case, I have multiple update elements. Maybe that is the problem… just a guess

On 22/01/2020 15:51, Vitor Fonseca wrote:

as per WFS 1.1.0 specification

image.png

so i think you problem is similar to this

https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you should check formatGML. featureType should be FR_TEST:streets_freiburg" and featureNS a URI (Namespace URI)

Vitor Fonseca <vfonsecaz@…84…> escreveu no dia quarta, 22/01/2020 à(s) 14:32:

so each update block has a different and valid fid?

This bit xmlns:feature=“FR_TEST” looks strange. What’s FR_TEST?
The wfs update examples I came across with only state the typeName property.

How did you create formatGML?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:20:

Yes, I deleted an update block because it was too long to be included in this email haha. There were two features.

2 update blocks basically.

The second one starts like :

the_geom 7.8322757 47.9760968 7.8321782 47.9759269 7.8320462 47.9756999 7.8319787 47.9756003 7.831903 47.9755152 7.83138 47.9749857 7.8311329 47.9747349 Street_Id 2399319 Src_Str_id 0 .........

I can’t use

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

because I am sending in an array of features already.

On 22/01/2020 15:21, Vitor Fonseca wrote:

Is that the complete request?

There’s only one feature there (

what if you replace this

node = formatWFS.writeTransaction(null, f, null, formatGML);

with

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:10:

Yes. It looks like this :

<?xml version="1.0" encoding="UTF-8"?>

<Transaction xmlns=“http://www.opengis.net/wfs” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” service=“WFS” version=“1.1.0” xsi:schemaLocation=“http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd”>


the_geom

<MultiLineString xmlns=“http://www.opengis.net/gml” srsName=“CRS:84”>


7.8311329 47.9747349 7.8310331 47.9746403






Street_Id
2414838


Src_Str_id
0


Full_Name
Schlierbergstraße


Class
6


�� One_way



Extra_Pass
0


Length
12.878


Speed
30


DrivingTim
0.0257


Serv_Area



From_Z
0


To_Z
0


Width
0


Veh_Size



LPriority
0


RPriority
0


ZipL



ZipR



LComment



RComment



LServeTime
0


RServeTime
0


BServeTime
0


LQuantity
0


RQuantity
0


BQuantity
0


LCusts
0


RCusts
0


BCusts
0


LUnits
0


RUnits
0


BUnits
0


LRevenue
0


RRevenue
0


BRevenue
0


LRoute
0


RRoute
0


BRoute
0


LRouteFile



RRouteFile



LCycle
0


RCycle
0


CycleLegnd
0


LFacil
0


RFacil
0


LFacilCost
0


RFacilCost
0


LSP
0


RSP
0


X_LRoute
0


X_RRoute
0


NetErr



NetErr_Ok



NetErr_Id
0


Up_Date
0


SameSelect
1


Serv_Mode



WalkingTim
0


ARA_BU_L
0


ARA_BU_R
0


Prefix



Name



Type



Suffix



L_F_Add



L_T_Add



R_F_Add



R_T_Add



RndAb
0


Exclude
0


OSM_ID
198512516


OSM_NameL
Schlierbergstraße


OSM_NameI



OSM_RdRef



OSM_Meta
lcn=yes, lit=yes, name=Schlierbergstraße, FIXME=recheck position and access, layer=1, bridge=yes, highway=residential, surface=asphalt, maxspeed=30, maxweight=3.5, motor_vehicle:back


Meters
12.878


Feet
42.25


OSM_KMH
30


OSM_MPH
18.641


OSM_Lanes
0


Po_Class
41


Po_Flags
3


PoEdge_id
315286


PoEId_Src
209581


PoEId_Trg
244684


Po_Car
1


Po_Bike
1


Po_Foot
0


Po_Area
0

<Filter xmlns=“http://www.opengis.net/ogc”>


On 22/01/2020 15:04, Vitor Fonseca wrote:

well i suggest you check the payload on the wfs request (using developer tools)
should be something like

<wfs:Transaction service=“WFS” version=“1.0.0”
xmlns:topp=“http://www.openplans.org/topp
xmlns:ogc=“http://www.opengis.net/ogc
xmlns:wfs=“http://www.opengis.net/wfs”>
<wfs:Update typeName=…

to see if there’s something strange there…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:55:

Yes. Like the example. I have already tried that.

On 22/01/2020 14:58, Vitor Fonseca wrote:

Ok got it.

have you tried creating the clone with var clone = new ol.Feature(featureProperties); instead of the clone function?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:01:

It is basically creating a copy of the feature which looks exactly the same except for the boundedBy property. So the geoserver identifies the feature you want to update using the id.

On 22/01/2020 13:59, Vitor Fonseca wrote:

Yes. But cloning creates new features right?

You are trying to update features that did not exist in the first place, and that GeoServer is not aware…i’m a bit confused now :slight_smile:

A quarta, 22/01/2020, 12:53, Vikram <vikram.eswar@…10264…> escreveu:

No I am trying to update features. If you look at the example that you shared, one has to create a clone in order to strip the boundedBy property from the feature.

On 22/01/2020 13:28, Vitor Fonseca wrote:

Wait a minute. Shouldn’t you be making insert’s instead of update’s?
You are creating new features after all…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 12:14:

Yes I have seen this example. Gives me the same result.

Now, I don’t get the assertion error anymore, I create the feature with WKT. But the end result is the same. I think the geoserver is not updating the features separately ie. it reads the features one by one, but stores the properties in the same variable, thus overwriting the properties every time. And then it updates all the features with this set of properties, thus making them all look alike.

have you also tried calling writeTransaction within a loop for updating one feature at a time?

I just tried this. It doesn’t produce the problem, I can see that it is called multiple times through the loop, but in the end, only one feature is updated…

On 22/01/2020 12:53, Vitor Fonseca wrote:

The browser console should give you a little bit more detail on the error…(expand all the error lines…)what’s the OL version?

check this example:
https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58

see the new feature created with…

var clone = new ol.Feature(featureProperties);

have you also tried calling writeTransaction within a loop for updating one feature at a time?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:40:

It says assertion failed at this line of code :

node = formatWFS.writeTransaction(null, f, null, formatGML);

Well I am not able to see where the fid is… I can only see id_ and ol_uid on the console. They are different for every clone.

On 22/01/2020 12:33, Vitor Fonseca wrote:

I have struggle in the past with the clone feature too.

You have different id’s in the clones or differente fid’s?
Because you’re setting “clone.setId(feature.getId());” and that’s not the “internal” feature ID.

BTW what exactly is the assertion error?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:24:

Hi Vitor,

Thanks for your reply.

The clone approach works fine for one feature ie. when I try to update one feature. I have checked the console and the clones have different IDs.

I tried creating feature with WKT, but got an assertion error while passing the created feature to the writeTransaction method…

Regards,

Vikram

On 22/01/2020 11:58, Vitor Fonseca wrote:

Hi,

I think this is a programming problem rather than a Geoserver problem.
From my experience the issue should be with the clone functionality.

Check this
https://gis.stackexchange.com/questions/46730/openlayers-cloned-features-get-style-from-original-feature

Someone mentions "I have noticed that cloned features share the same featureID as the original. " and this should be the problem when sending the features over to WFS-T…
You could try creating new features some other way (wkt…)

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 10:24:

HI all,

I am trying to update features using WFS-T update. I am sending the request from my website (OpenLayers) by passing an array of features.

However, I have noticed that the attributes and geometry of last feature in the array is copied to all other features.

For example, if I pass 5 features to the writeTransaction method to update an attribute of all 5 features, it copies the attributes and geometry of the 5th feature to the other features.

var clones = []
selectedFeatures.forEach(function (feature) {
    var featureProperties = feature.getProperties();

    delete featureProperties.boundedBy;
    var clone = feature.clone();
    clone.setId(feature.getId());

    clone.setGeometryName('the_geom');

    clone.setProperties({'xyz':'xyz'})

    clones.push(clone)

})
console.log(clones)
transactWFS('update_batch', clones);

int the transactWFS method,

transactWFS = function (mode, f) {

    var node;
    switch (mode) {
        case 'insert':
            node = formatWFS.writeTransaction([f], null, null, formatGML);
            break;
        case 'update':
            node = formatWFS.writeTransaction(null, [f], null, formatGML);
            break;
        case 'update_batch':
            node = formatWFS.writeTransaction(null, f, null, formatGML);
            break;
        case 'delete':
            node = formatWFS.writeTransaction(null, null, [f], formatGML);
            break;
    }
    var payload = xs.serializeToString(node);

    $.ajax('[http://localhost:8080/geoserver/TEST/ows](http://localhost:8080/geoserver/TEST/ows)', {
        service: 'WFS',
        type: 'POST',
        dataType: 'xml',
        processData: false,
        contentType: 'text/xml',
        data: payload,
        success: function(data) {

        },
        error: function(e) {
            var errorMsg = e? (e.status + ' ' + e.statusText) : "";
            alert('Error saving this feature to GeoServer.<br><br>'
                + errorMsg);
        }
    }).done(function() {
        wfsSource.refresh()

    });
};

Does anyone have a solution?

Regards,

Vikram


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

_______________________________________________
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:
- Earning your support instead of buying it, but Ian Turton: [http://www.ianturton.com/talks/foss4g.html#/](http://www.ianturton.com/talks/foss4g.html#/)
- The GeoServer user list posting guidelines: [http://geoserver.org/comm/userlist-guidelines.html](http://geoserver.org/comm/userlist-guidelines.html)

If you want to request a feature or an improvement, also see this: [https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer](https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer)

[Geoserver-users@lists.sourceforge.net](mailto:Geoserver-users@lists.sourceforge.net)
[https://lists.sourceforge.net/lists/listinfo/geoserver-users](https://lists.sourceforge.net/lists/listinfo/geoserver-users)


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

www.vfonsecaz.pt

On the other hand i did not find any example with a “batch update”, only single updates…

good luck

Vikram <vikram.eswar@anonymised.com> escreveu no dia quarta, 22/01/2020 à(s) 16:02:

image001.png

image.png

···

www.vfonsecaz.pt

Yes that is exactly my problem too. Single update works fine for me. Thanks for your time. I appreciate that.

image001.png

image.png

···

On 22/01/2020 17:14, Vitor Fonseca wrote:

On the other hand i did not find any example with a “batch update”, only single updates…

good luck

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 16:02:

Okay I will look at the versions… On the GeoServer console, it looks fine, no errors and the update is completed. I will try GML3 to start with…

On 22/01/2020 16:57, Vitor Fonseca wrote:

seems there’s a lot of people facing the same problem…
https://gis.stackexchange.com/questions/193761/wrong-typename-generated-by-wfs-t-update-request-in-xml

geoserver log should show something. make sure verbose logging is active…

also try GML3 instead of GML

I can only think of some versioning conflict…maybe wfs version vs ol version vs gml version…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:50:

Tried it too, same result.

But if the featureNS is wrong, I should get an error which I don’t.

On 22/01/2020 16:44, Vitor Fonseca wrote:

another similar error
https://gis.stackexchange.com/questions/214850/editing-wfs-layer

featureNS should be the geoserver workspace Namespace URI

chrome-capture (15).jpg

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:30:

I changed the update block manually and sent it to the server, it works without errors, but produces the same result.

On 22/01/2020 16:20, Vikram wrote:

That is my formatGML code :

var formatGML = new ol.format.GML({
featureNS: ‘http://192.168.2.38:2020/geoserver/FR_TEST’,
featureType: ‘streets_freiburg’,
srsName: ‘CRS:84’
});

When I use featureType: ‘FR_TEST:streets_freiburg’, I have an error on the geoserver side, it does not find the feature layer.

With my current code,

I see :

Update xmlns:feature=“http://192.168.2.38:2020/geoserver/FR_TEST” typeName=“feature:streets_freiburg”

and there is no error on the geoserver log. It just does not work as expected…

On 22/01/2020 16:17, Vitor Fonseca wrote:

the spec refers multiple “update” elements…so multiple update blocks are permitted

I think the problem is typeName, and so you should change the formatGML constructor.
the update block should state

<Update typeName="FR_TEST:streets_freiburg">

without the xmlns:feature=“FR_TEST” part.

Looks exactly like the problem shown here
https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you could also check geoserver logs for a nullpointerexception

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 15:08:

I changed the featureNS to a URI, still the same result. featureType should be “streets_freiburg”. I have checked this before.

The description says that the update element describes an operation that can be applied to a set of features, but in my case, I have multiple update elements. Maybe that is the problem… just a guess

On 22/01/2020 15:51, Vitor Fonseca wrote:

as per WFS 1.1.0 specification

image.png

so i think you problem is similar to this

https://stackoverflow.com/questions/36145503/openlayers-3-ol-format-wfs-writetransaction-produces-incorrect-xml-for-simple-up

you should check formatGML. featureType should be FR_TEST:streets_freiburg" and featureNS a URI (Namespace URI)

Vitor Fonseca <vfonsecaz@…84…> escreveu no dia quarta, 22/01/2020 à(s) 14:32:

so each update block has a different and valid fid?

This bit xmlns:feature=“FR_TEST” looks strange. What’s FR_TEST?
The wfs update examples I came across with only state the typeName property.

How did you create formatGML?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:20:

Yes, I deleted an update block because it was too long to be included in this email haha. There were two features.

2 update blocks basically.

The second one starts like :

the_geom 7.8322757 47.9760968 7.8321782 47.9759269 7.8320462 47.9756999 7.8319787 47.9756003 7.831903 47.9755152 7.83138 47.9749857 7.8311329 47.9747349 Street_Id 2399319 Src_Str_id 0 .........

I can’t use

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

because I am sending in an array of features already.

On 22/01/2020 15:21, Vitor Fonseca wrote:

Is that the complete request?

There’s only one feature there (

what if you replace this

node = formatWFS.writeTransaction(null, f, null, formatGML);

with

node = formatWFS.writeTransaction(null, **[f]**, null, formatGML);

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 14:10:

Yes. It looks like this :

<?xml version="1.0" encoding="UTF-8"?>

<Transaction xmlns=“http://www.opengis.net/wfs” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” service=“WFS” version=“1.1.0” xsi:schemaLocation=“http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd”>


the_geom

<MultiLineString xmlns=“http://www.opengis.net/gml” srsName=“CRS:84”>


7.8311329 47.9747349 7.8310331 47.9746403






Street_Id
2414838


Src_Str_id
0


Full_Name
Schlierbergstraße


Class
6


�� One_way



Extra_Pass
0


Length
12.878


Speed
30


DrivingTim
0.0257


Serv_Area



From_Z
0


To_Z
0


Width
0


Veh_Size



LPriority
0


RPriority
0


ZipL



ZipR



LComment



RComment



LServeTime
0


RServeTime
0


BServeTime
0


LQuantity
0


RQuantity
0


BQuantity
0


LCusts
0


RCusts
0


BCusts
0


LUnits
0


RUnits
0


BUnits
0


LRevenue
0


RRevenue
0


BRevenue
0


LRoute
0


RRoute
0


BRoute
0


LRouteFile



RRouteFile



LCycle
0


RCycle
0


CycleLegnd
0


LFacil
0


RFacil
0


LFacilCost
0


RFacilCost
0


LSP
0


RSP
0


X_LRoute
0


X_RRoute
0


NetErr



NetErr_Ok



NetErr_Id
0


Up_Date
0


SameSelect
1


Serv_Mode



WalkingTim
0


ARA_BU_L
0


ARA_BU_R
0


Prefix



Name



Type



Suffix



L_F_Add



L_T_Add



R_F_Add



R_T_Add



RndAb
0


Exclude
0


OSM_ID
198512516


OSM_NameL
Schlierbergstraße


OSM_NameI



OSM_RdRef



OSM_Meta
lcn=yes, lit=yes, name=Schlierbergstraße, FIXME=recheck position and access, layer=1, bridge=yes, highway=residential, surface=asphalt, maxspeed=30, maxweight=3.5, motor_vehicle:back


Meters
12.878


Feet
42.25


OSM_KMH
30


OSM_MPH
18.641


OSM_Lanes
0


Po_Class
41


Po_Flags
3


PoEdge_id
315286


PoEId_Src
209581


PoEId_Trg
244684


Po_Car
1


Po_Bike
1


Po_Foot
0


Po_Area
0

<Filter xmlns=“http://www.opengis.net/ogc”>


On 22/01/2020 15:04, Vitor Fonseca wrote:

well i suggest you check the payload on the wfs request (using developer tools)
should be something like

<wfs:Transaction service=“WFS” version=“1.0.0”
xmlns:topp=“http://www.openplans.org/topp
xmlns:ogc=“http://www.opengis.net/ogc
xmlns:wfs=“http://www.opengis.net/wfs”>
<wfs:Update typeName=…

to see if there’s something strange there…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:55:

Yes. Like the example. I have already tried that.

On 22/01/2020 14:58, Vitor Fonseca wrote:

Ok got it.

have you tried creating the clone with var clone = new ol.Feature(featureProperties); instead of the clone function?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 13:01:

It is basically creating a copy of the feature which looks exactly the same except for the boundedBy property. So the geoserver identifies the feature you want to update using the id.

On 22/01/2020 13:59, Vitor Fonseca wrote:

Yes. But cloning creates new features right?

You are trying to update features that did not exist in the first place, and that GeoServer is not aware…i’m a bit confused now :slight_smile:

A quarta, 22/01/2020, 12:53, Vikram <vikram.eswar@…10264…> escreveu:

No I am trying to update features. If you look at the example that you shared, one has to create a clone in order to strip the boundedBy property from the feature.

On 22/01/2020 13:28, Vitor Fonseca wrote:

Wait a minute. Shouldn’t you be making insert’s instead of update’s?
You are creating new features after all…

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 12:14:

Yes I have seen this example. Gives me the same result.

Now, I don’t get the assertion error anymore, I create the feature with WKT. But the end result is the same. I think the geoserver is not updating the features separately ie. it reads the features one by one, but stores the properties in the same variable, thus overwriting the properties every time. And then it updates all the features with this set of properties, thus making them all look alike.

have you also tried calling writeTransaction within a loop for updating one feature at a time?

I just tried this. It doesn’t produce the problem, I can see that it is called multiple times through the loop, but in the end, only one feature is updated…

On 22/01/2020 12:53, Vitor Fonseca wrote:

The browser console should give you a little bit more detail on the error…(expand all the error lines…)what’s the OL version?

check this example:
https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58

see the new feature created with…

var clone = new ol.Feature(featureProperties);

have you also tried calling writeTransaction within a loop for updating one feature at a time?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:40:

It says assertion failed at this line of code :

node = formatWFS.writeTransaction(null, f, null, formatGML);

Well I am not able to see where the fid is… I can only see id_ and ol_uid on the console. They are different for every clone.

On 22/01/2020 12:33, Vitor Fonseca wrote:

I have struggle in the past with the clone feature too.

You have different id’s in the clones or differente fid’s?
Because you’re setting “clone.setId(feature.getId());” and that’s not the “internal” feature ID.

BTW what exactly is the assertion error?

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 11:24:

Hi Vitor,

Thanks for your reply.

The clone approach works fine for one feature ie. when I try to update one feature. I have checked the console and the clones have different IDs.

I tried creating feature with WKT, but got an assertion error while passing the created feature to the writeTransaction method…

Regards,

Vikram

On 22/01/2020 11:58, Vitor Fonseca wrote:

Hi,

I think this is a programming problem rather than a Geoserver problem.
From my experience the issue should be with the clone functionality.

Check this
https://gis.stackexchange.com/questions/46730/openlayers-cloned-features-get-style-from-original-feature

Someone mentions "I have noticed that cloned features share the same featureID as the original. " and this should be the problem when sending the features over to WFS-T…
You could try creating new features some other way (wkt…)

Vikram <vikram.eswar@…10264…> escreveu no dia quarta, 22/01/2020 à(s) 10:24:

HI all,

I am trying to update features using WFS-T update. I am sending the request from my website (OpenLayers) by passing an array of features.

However, I have noticed that the attributes and geometry of last feature in the array is copied to all other features.

For example, if I pass 5 features to the writeTransaction method to update an attribute of all 5 features, it copies the attributes and geometry of the 5th feature to the other features.

var clones = []
selectedFeatures.forEach(function (feature) {
    var featureProperties = feature.getProperties();

    delete featureProperties.boundedBy;
    var clone = feature.clone();
    clone.setId(feature.getId());

    clone.setGeometryName('the_geom');

    clone.setProperties({'xyz':'xyz'})

    clones.push(clone)

})
console.log(clones)
transactWFS('update_batch', clones);

int the transactWFS method,

transactWFS = function (mode, f) {

    var node;
    switch (mode) {
        case 'insert':
            node = formatWFS.writeTransaction([f], null, null, formatGML);
            break;
        case 'update':
            node = formatWFS.writeTransaction(null, [f], null, formatGML);
            break;
        case 'update_batch':
            node = formatWFS.writeTransaction(null, f, null, formatGML);
            break;
        case 'delete':
            node = formatWFS.writeTransaction(null, null, [f], formatGML);
            break;
    }
    var payload = xs.serializeToString(node);

    $.ajax('[http://localhost:8080/geoserver/TEST/ows](http://localhost:8080/geoserver/TEST/ows)', {
        service: 'WFS',
        type: 'POST',
        dataType: 'xml',
        processData: false,
        contentType: 'text/xml',
        data: payload,
        success: function(data) {

        },
        error: function(e) {
            var errorMsg = e? (e.status + ' ' + e.statusText) : "";
            alert('Error saving this feature to GeoServer.<br><br>'
                + errorMsg);
        }
    }).done(function() {
        wfsSource.refresh()

    });
};

Does anyone have a solution?

Regards,

Vikram


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

_______________________________________________
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:
- Earning your support instead of buying it, but Ian Turton: [http://www.ianturton.com/talks/foss4g.html#/](http://www.ianturton.com/talks/foss4g.html#/)
- The GeoServer user list posting guidelines: [http://geoserver.org/comm/userlist-guidelines.html](http://geoserver.org/comm/userlist-guidelines.html)

If you want to request a feature or an improvement, also see this: [https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer](https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer)

[Geoserver-users@lists.sourceforge.net](mailto:Geoserver-users@lists.sourceforge.net)
[https://lists.sourceforge.net/lists/listinfo/geoserver-users](https://lists.sourceforge.net/lists/listinfo/geoserver-users)


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

www.vfonsecaz.pt

www.vfonsecaz.pt

www.vfonsecaz.pt

found his

https://osgeo-org.atlassian.net/browse/GEOS-6367

Vikram <vikram.eswar@anonymised.com> escreveu no dia quarta, 22/01/2020 à(s) 16:11:

image001.png

image.png

···

www.vfonsecaz.pt

I just looking at your code I think the problem may be with the call to transactWFS.

···
The update function called is written like this: formatWFS.writeTransaction(null, [f], null, formatGML);

Your clones object is already an array, so you are than wrapping that in an array with only one element. Try modifying the writeTransaction call to this:

:formatWFS.writeTransaction(null, f, null, formatGML);

Cheers,

Graham

From: Vikram [mailto:vikram.eswar@…10264…]
Sent: Wednesday, 22 January 2020 9:10 PM
To: geoserver-users@lists.sourceforge.net
Subject: [Geoserver-users] OpenLayers GeoServer update an array of features using WFS-T

HI all,

I am trying to update features using WFS-T update. I am sending the request from my website (OpenLayers) by passing an array of features.

However, I have noticed that the attributes and geometry of last feature in the array is copied to all other features.

For example, if I pass 5 features to the writeTransaction method to update an attribute of all 5 features, it copies the attributes and geometry of the 5th feature to the other features.

var clones = []
selectedFeatures.forEach(function (feature) {
    var featureProperties = feature.getProperties();

    delete featureProperties.boundedBy;
    var clone = feature.clone();
    clone.setId(feature.getId());

    clone.setGeometryName('the_geom');

    clone.setProperties({'xyz':'xyz'})

    clones.push(clone)



})
console.log(clones)
transactWFS('update_batch', clones);

int the transactWFS method,

transactWFS = function (mode, f) {

    var node;
    switch (mode) {
        case 'insert':
            node = formatWFS.writeTransaction([f], null, null, formatGML);
            break;
        case 'update':
            node = formatWFS.writeTransaction(null, [f], null, formatGML);
            break;
        case 'update_batch':
            node = formatWFS.writeTransaction(null, f, null, formatGML);
            break;
        case 'delete':
            node = formatWFS.writeTransaction(null, null, [f], formatGML);
            break;
    }
    var payload = xs.serializeToString(node);

    $.ajax('[http://localhost:8080/geoserver/TEST/ows](http://localhost:8080/geoserver/TEST/ows)', {
        service: 'WFS',
        type: 'POST',
        dataType: 'xml',
        processData: false,
        contentType: 'text/xml',
        data: payload,
        success: function(data) {

        },
        error: function(e) {
            var errorMsg = e? (e.status + ' ' + e.statusText) : "";
            alert('Error saving this feature to GeoServer.<br><br>'
                + errorMsg);
        }
    }).done(function() {
        wfsSource.refresh()

    });
};

Does anyone have a solution?

Regards,

Vikram

Hi Graham,

I have already tried that. I have two different cases ‘update’ and ‘update_batch’.

Regards,

Vikram

···

On 22/01/2020 22:57, Humphries, Graham wrote:

I just looking at your code I think the problem may be with the call to transactWFS.

The update function called is written like this: formatWFS.writeTransaction(null, [f], null, formatGML);

Your clones object is already an array, so you are than wrapping that in an array with only one element. Try modifying the writeTransaction call to this:

:formatWFS.writeTransaction(null, f, null, formatGML);

Cheers,

Graham

From: Vikram [mailto:vikram.eswar@…10264…]
Sent: Wednesday, 22 January 2020 9:10 PM
To: geoserver-users@lists.sourceforge.net
Subject: [Geoserver-users] OpenLayers GeoServer update an array of features using WFS-T

HI all,

I am trying to update features using WFS-T update. I am sending the request from my website (OpenLayers) by passing an array of features.

However, I have noticed that the attributes and geometry of last feature in the array is copied to all other features.

For example, if I pass 5 features to the writeTransaction method to update an attribute of all 5 features, it copies the attributes and geometry of the 5th feature to the other features.

var clones = []
selectedFeatures.forEach(function (feature) {
    var featureProperties = feature.getProperties();

    delete featureProperties.boundedBy;
    var clone = feature.clone();
    clone.setId(feature.getId());

    clone.setGeometryName('the_geom');

    clone.setProperties({'xyz':'xyz'})

    clones.push(clone)



})
console.log(clones)
transactWFS('update_batch', clones);

int the transactWFS method,

transactWFS = function (mode, f) {

    var node;
    switch (mode) {
        case 'insert':
            node = formatWFS.writeTransaction([f], null, null, formatGML);
            break;
        case 'update':
            node = formatWFS.writeTransaction(null, [f], null, formatGML);
            break;
        case 'update_batch':
            node = formatWFS.writeTransaction(null, f, null, formatGML);
            break;
        case 'delete':
            node = formatWFS.writeTransaction(null, null, [f], formatGML);
            break;
    }
    var payload = xs.serializeToString(node);

    $.ajax('[http://localhost:8080/geoserver/TEST/ows](http://localhost:8080/geoserver/TEST/ows)', {
        service: 'WFS',
        type: 'POST',
        dataType: 'xml',
        processData: false,
        contentType: 'text/xml',
        data: payload,
        success: function(data) {

        },
        error: function(e) {
            var errorMsg = e? (e.status + ' ' + e.statusText) : "";
            alert('Error saving this feature to GeoServer.<br><br>'
                + errorMsg);
        }
    }).done(function() {
        wfsSource.refresh()

    });
};

Does anyone have a solution?

Regards,

Vikram


CONFIDENTIALITY NOTICE AND DISCLAIMER
The information in this transmission may be confidential and/or protected by legal professional privilege, and is intended only for the person or persons to whom it is addressed. If you are not such a person, you are warned that any disclosure, copying or dissemination of the information is unauthorised. If you have received the transmission in error, please immediately contact this office by telephone, fax or email, to inform us of the error and to enable arrangements to be made for the destruction of the transmission, or its return at our cost. No liability is accepted for any unauthorised use of the information contained in this transmission.