Reputation: 1547
I am using OpenLayers 6 and GeoServer 2.16 (plus PostGIS) ; and when I load layers from GeoServer, the feature load, but their geometry name is overwritten. In GeoServer the geometry name (and column in PostGIS) is geom
. The XML returned reflects this. But the OpenLayers object then has a geometry name of geometry
, ignoring the geometry name GeoServer had returned.
It seems trivial, but causes issues as when I go to edit the feature I get an error with org.geoserver.wfs.WFSException: No such property: geometry
; so while I could edit the geometry name and corresponding value in my code, this seems like a bad hack.
Is this a bug or some setting that I just can't find in the docs?
Any help would be greatly appreciated! ( I haven't seen any questions reflecting this error (Getting WFS is my case, all the questions seem to be about POSTing back). If I am duplicate please let me know. )
Upvotes: 1
Views: 539
Reputation: 22089
You can fix this by asking OpenLayers to read the name of the geometry column from the input. For GeoJSON:
source: new VectorSource({
format: new GeoJSON({ extractGeometryName: true }),
url: ...
}),
Upvotes: 1
Reputation: 561
I don't know it's a bug or not. But it's really annoying. sadly in OpenLayers, there isn't any updated document about editing features.
There is some solution to solve this:
Changing the PostGIS field name. You can rename the PostGIS field or set the geometry field name to geometry
when you are importing to PostGIS.
Also, you can change the edit request in OpenLayers manually. The common way of editing features is sending an XML or POST request to GeoServer. So before sending it just replace geometry
to geom
! Something like this:
var node = wfs.writeTransaction(null, [feature], null, gml);
var s = new XMLSerializer();
var str = s.serializeToString(node);
str = str.replace("geometry", "geom");
xhr.open('POST', 'http://localhost:8080/geoserver/wfs', true);
xhr.send(str);
Upvotes: 0