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

share|improve this question
    
gis.stackexchange.com/questions/30162/… Hope this helps. –  Kliver Max Aug 30 '12 at 5:40

3 Answers 3

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;
share|improve this answer

When i want to edit features i do this.

How to edit feature attributes with openlayers?

Hope this helps.

share|improve this answer
up vote 0 down vote accepted

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))
share|improve this answer
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. –  user1702401 Nov 28 '12 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. –  neogeomat Feb 4 '13 at 15:14

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.