0

I have a function that manage WFS-T Transaction between a web application client (based on OpenLayers 6) and a GeoServer instance.

import axios from "axios";
import { WFS } from "ol/format";
import { FeatureCollection } from "geojson";
import { WriteTransactionOptions } from "ol/format/WFS";
import Feature from "ol/Feature";

const WFSTransaction = (mode: TransactionMode, featuresArray: Feature[]) => {
    const formatWFS = new WFS();
    const xs = new XMLSerializer();
    const options: WriteTransactionOptions = {
      featureNS: "myDomain",
      featureType: "mylayer",
      srsName: "EPSG:4326",
      featurePrefix: "",
      nativeElements: [],
    };
    let node;

    switch (mode) {
      case "insert":
        node = formatWFS.writeTransaction(featuresArray, [], [], options);
        break;
      case "update":
        node = formatWFS.writeTransaction([], featuresArray, [], options);
        break;
      case "delete":
        node = formatWFS.writeTransaction([], [], featuresArray, options);
        break;
      default:
        console.log(
          "passed transaction mode  did not match any of the supported transactions mode"
        );
        break;
    }
    if (node) {
      const wfsNode = xs.serializeToString(node);
      return axios.post(
        `${this._domain}/ows?service=WFS&typeName=${this.fType}`,
        wfsNode,
        {
          headers: { "Content-Type": "text/xml" },
        }
      );
    }
  };

Everything is working fine.

BUT if I send a feature with some attributes that does not match my table schema in the geoserver store (which is basically a PostgreSQL instance), I got an error message :

<?xml version="1.0" encoding="UTF-8"?><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://meitarimdb:8080/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
<ows:Exception exceptionCode="InvalidParameterValue">
<ows:ExceptionText>No such property: editable</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>

Now the thing is that the property "editable" (that you can see in the error message) is something that I set on purpose and dynamically to the OpenLayers Feature on the flight.

myFeature.set("editable", true);

Well if I unset this property that I added before sending the transaction, my feature gets updated ...

But this not ideal because for each property that I add dynamically for logical purpose of the application, I have to unset it before sending the transaction. And there is a bunch of them...

So I wonder if there is any options to make the GeoServer more flexible with the properties that I send and simply ignore if a property is not present in the schema, and update those that are presents on the schemas

I did not found in the documentation.

1 Answer 1

1

No, I don't think there is any way to tell GeoServer to ignore values in a feature, you are expected to provide at least all the non-nullable attributes and none that are not listed in the schema.

3
  • Thanks for your answer. In ArcGIS Server I wrote a SOE that could be used as a middleware...do you may be know an equivalent of that in Geoserver ? Also : do you know why Geoserver is so strict with these non schemas values ?
    – jossefaz
    Apr 29, 2021 at 14:45
  • It's strict because that is what the standard says to do. I'm sure you could write a filter but not adding random attributes to features would be the easy answer
    – Ian Turton
    Apr 29, 2021 at 14:57
  • Thank you for this advice. I personally found the set method present in pretty every OL object (including Feature object) very useful and thats why I add them. But I understand.
    – jossefaz
    Apr 29, 2021 at 15:10

Your Answer

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

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