Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:

And from openlayers-dev: http://lists.osgeo.org/pipermail/openlayers-dev/2007-April/000520.html

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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...

share|improve this answer
2  
Yes 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 Nov 16 '12 at 19:30
    
Nice answer. I will mark it once I have tried it in practise, it may take a week unfortunately. –  Janne Mattila Nov 19 '12 at 13:01
    
Tested and it works. Perfect. –  Janne Mattila Nov 23 '12 at 12:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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