I have published a WFS-T layer (using geoserver) and am able to add, edit and delete features using OpenLayers and it's Vector layer.
But, I don't know how can I populate additional attributes using OpenLayers and WFS-T. Any pointers?
Let's say I have database structure:
ARMY (
ID NUMBER PRIMARY KEY,
NAME VARCHAR2(200));
INVADED_AREA (
ID NUMBER PRIMARY KEY,
INVADED_BY_ARMY_ID NUMBER NOT NULL,
AREA_GEOMETRY SDO_GEOMETRY,
CONSTRAINT ia_fk FOREIGN KEY(INVADED_BY_ARMY_ID) REFERENCES ARMY(ID));
and I have a web application where you first select an army (with e.g. ID 42) and then start drawing geometries of invaded areas using OpenLayers. How do I get OpenLayers to put value 42 into INVADED_AREA.INVADED_BY_ARMY_ID column?
EDIT: I have found http://dev4.mapgears.com/bdga/bdgaWFS-T.html# which seems to do what I am looking for. Will update when I have investigated it more.
Also found bunch of related gis.stackexchange questions. I will look through them more carefully, at first glance none had an easy answer:
- I want to edit corresponding postgresql data of a vector from openlayers- how to do it?
- How to edit Attributes on WFS Layer through Popup?
- How to edit feature attributes with openlayers?
- Modify WFS with OpenLayers
- adding non spatial attributes using geoserver
- How to insert non-spatial data through WFS-T insert?
And from openlayers-dev: http://lists.osgeo.org/pipermail/openlayers-dev/2007-April/000520.html
1 Answer 1
Simply add the attribute to the feature before the wfs-commit:
// feat is the feature with the area the user drawn
feat.attributes.INVADED_BY_ARMY_ID = 42;
Of course, you should save somewhere the army id...
-
2Yes that's correct - all attributes of feature are saved to according database fields. There's one more thing to remember - if you want to update attributes of existing feature, you have to set feature's state to OpenLayers.State.UPDATE
feat.attributes.INVADED_BY_ARMY_ID = 42; /* Update state, if it is not set allready. Otherwise you may overwrite INSERT state */ if (!feature.state) feature.state = OpenLayers.State.UPDATE; saveStrategy.save();
user1702401– user17024012012年11月16日 19:30:24 +00:00Commented Nov 16, 2012 at 19:30 -
Nice answer. I will mark it once I have tried it in practise, it may take a week unfortunately.Janne Mattila– Janne Mattila2012年11月19日 13:01:06 +00:00Commented Nov 19, 2012 at 13:01
-
Tested and it works. Perfect.Janne Mattila– Janne Mattila2012年11月23日 12:41:51 +00:00Commented Nov 23, 2012 at 12:41