2

I am using Openlayers + geoext to perform transaction operations in postgis database using geoserver . i can insert spatial data into postgis but cannot insert other data like road name, road type in my road database.

the openlayers generates this code during transaction

<wfs:Transaction xmlns:wfs="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">
 <wfs:Insert>
<feature:Complaint xmlns:feature="http://geoserver/postgis">
 <feature:geom>
 <gml:MultiCurve 
 xmlns:gml="http://www.opengis.net/gml" 
 srsName="EPSG:4326">
 <gml:curveMember>
 <gml:LineString>
 <gml:posList>85.292019896027 27.722567213659 85.303131631935 27.72224973549 85.303290371019 27.72478956084
 </gml:posList>
 </gml:LineString>
 </gml:curveMember>
 </gml:MultiCurve>
 </feature:geom>
 </feature:Complaint>
 </wfs:Insert>
</wfs:Transaction>

in geoserver demo i add fid and id so that it looks as

<wfs:Transaction xmlns:wfs="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">
 <wfs:Insert>
<feature:Complaint xmlns:feature="http://geoserver/postgis">
 <feature:geom>
 <gml:MultiCurve 
 xmlns:gml="http://www.opengis.net/gml" 
 srsName="EPSG:4326">
 <gml:curveMember>
 <gml:LineString>
 <gml:posList>85.292019896027 27.722567213659 85.303131631935 27.72224973549 85.303290371019 27.72478956084
 </gml:posList>
 </gml:LineString>
 </gml:curveMember>
 </gml:MultiCurve>
 </feature:geom>
 **<id>650</id>
 <fid>400</fid>**
 </feature:Complaint>
 </wfs:Insert>
</wfs:Transaction>

and i get what i want. my question is how can i post the 2nd request (with id and fid) instead of first using openlayers and/or geoext?

asked Aug 27, 2012 at 9:12
1

3 Answers 3

2

If I understood your problem correctly - just set attributes for your feature in OpenLayers, and that's all.

For example, presuming your table has roadname and roadtype fields:

feature.attributes.roadname = 'Foo';
feature.attributes.roadtype = 10;
answered Nov 28, 2012 at 7:36
1

When i want to edit features i do this.

How to edit feature attributes with openlayers?

Hope this helps.

answered Aug 30, 2012 at 5:41
0

i don't know the answer to this question, but if someone is stuck in same situation. i suggest that you extract the geometry of feature and assign it to an html element. then access the value of same element and use php to insert it to database along with other attributes. it works for simple geometries but is a tedious task, still it is a solution.

My code is like this

var draw = new OpenLayers.Control.DrawFeature(
 vector, //layer
 OpenLayers.Handler.Path, //Handler
 { multi:true,
 type: OpenLayers.Control.TYPE_TOGGLE,
 //handlerOptions : {maxVertices: 5}
 }//options
 );
 draw.events.register("featureadded",'' , FeatureAdded);
 function FeatureAdded(object){ 
 //alert('feature added');
 var oFeature = object.feature; 
 oFeature.state = OpenLayers.State.INSERT; 
 **document.getElementById('geometry').value = oFeature.geometry;
 //alert(oFeature.geometry); 
 } 
 map.addControl(draw);

the sql statement is like this in postgis

INSERT INTO table_name VALUES (ST_GeographyFromText('value of the element(geometry)',SRID))
answered Aug 29, 2012 at 19:29
2
  • 1
    WFS-T is ment for inserting both geometry and attributes into database (and it does it well), so there is no need for such non-standard workaround. Commented Nov 28, 2012 at 7:33
  • ya, i took a long time to figure out how to use the attributes object. If only there were simpler examples, it would have been much easy. Openlayers documentation sucks. Nowadays i use the feature attribute object. Commented Feb 4, 2013 at 15:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.