I'm new to Openlayers and I'm trying to edit and save a polygon from a postgres database with geoserver; I'm based in this example: openlayers3 wfs-t save drawing
My table definition is like this:
CREATE TABLE myschema.mytable
(
id_mytable serial NOT NULL,
element character varying(20) NOT NULL,
description character varying(50),
observation character varying(50),
date_created timestamp without time zone,
status boolean NOT NULL,
geometry geometry(Polygon,4326),
CONSTRAINT id_circuito_pk PRIMARY KEY (id_mytable),
CONSTRAINT cod_cir_uniq UNIQUE (element),
)
The problem is, when the edit button is triggered I get this error:
<ows:ExceptionReport xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ows="http://www.opengis.net/ows" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows http://myserver:8080/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="OperationProcessingFailed">
<ows:ExceptionText>No such property: bbox</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>
This is part of my code when I try to get the edited element and send it to a edit transaction to geoserver
var select = new ol.interaction.Select({
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#FF2828'
})
})
});
....
select.getFeatures().on('remove', function(e) {
var f = e.element;
console.log(f);
if (dirty[f.getId()]){
delete dirty[f.getId()];
var featureProperties = f.getProperties();
delete featureProperties.boundedBy;
var clone = new ol.Feature(featureProperties);
clone.setId(f.getId());
transactWFS('update',clone);
}
});
The console.log(f); line returns this in console:
{…}
S: {…}
bbox: Array(4) [ -57.5871151158136, -25.30012166784802, -57.57902551943073, … ]
element: "CIRVILLA001"
description: "CIRVILLA001"
state: true
date_creation: "2020-03-12T14:53:35.213Z"
geometry: Object { i: 8, Vo: 1888, v: 8, … }
id_mytable: 1853
observation: null
<prototype>: Object { … }
Ua: Object { }
Vo: 1889
a: "mytable.1853"
c: "geometry"
f: Object { lh: {…}, nh: false, type: "change", … }
fb: Object { "change:geometry": (1) […], change: (3) […], propertychange: (1) […] }
g: null
i: 9
j: undefined
oa: Object { "change:geometry": (1) […], change: (3) […], propertychange: (1) […] }
ra: Object { }
<prototype>: Object { constructor: H(a), clone: clone(), V: V(), … }
This specific part is the 'S' variable; I'm not sure why I get the 'bbox' variable along with the other table elements; I think this is the reason I get the error message but I'm not sure why
bbox: Array(4) [ -57.5871151158136, -25.30012166784802, -57.57902551943073, … ]
element: "CIRVILLA001"
description: "CIRVILLA001"
state: true
date_creation: "2020-03-12T14:53:35.213Z"
geometry: Object { i: 8, Vo: 1888, v: 8, … }
id_mytable: 1853
observation: null
This is the final petition to geoserver; the bbox variable is included
<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Update typeName="feature:mytable" xmlns:undefined="myfeature.com"><Property><Name>geometry</Name><Value><Polygon xmlns="http://www.opengis.net/gml" srsName="EPSG:4326"><exterior><LinearRing srsName="EPSG:4326"><posList>-25.29069838125067 -57.5871151158136 -25.294262176413937 -57.57902551943073 -25.300648657126356 -57.56431000423576 -25.30012166784802 -57.58149612589361 -25.29069838125067 -57.5871151158136</posList></LinearRing></exterior></Polygon></Value></Property><Property><Name>id_mytable</Name><Value>1853</Value></Property><Property><Name>element</Name><Value>CIRVILLA001</Value></Property><Property><Name>description</Name><Value>CIRVILLA001</Value></Property><Property><Name>observation</Name></Property><Property><Name>date_creation/Name><Value>2020-03-12T14:53:35.213Z</Value></Property><Property><Name>state</Name><Value>true</Value></Property><Property><Name>bbox</Name><Value>-57.5871151158136,-25.30012166784802,-57.57902551943073,-25.29069838125067</Value></Property><Filter xmlns="http://www.opengis.net/ogc"><FeatureId fid="mytable.1853"/></Filter></Update></Transaction>
Is there something I'm missing? I add the WFS vector definition, just in case:
sourceVector = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://myserver:8080/geoserver/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=MYWORKSPACE:mytable&' +
'outputFormat=application/json&srsname=EPSG:4326&';
},
});
I figured this out, still not sure why, but I made these changes and the update transaction works:
1) Right before sending the feature to writeTransaction, I perform an unset to delete de bbox property (this just for editing an existing polygon)
f.unset('bbox', true);
node = formatWFS.writeTransaction(null,[f],null,formatGML);
2) This is part of my xml generated petition:
<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Update typeName="feature:mytable"
The typeName is configured with feature:mytable, it should have my geoserver workspace; I had to perform a replace:
var data_=str.replace("typeName=\"feature:","typeName=\"myworkspace:");
And the POST request works fine, I got the replace idea from here