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 want to add a polygon to the database. I used the following code. The problem is that I am to able to save in database. Whatever polygon I draw on map it gets save temporary and as soon as I reload the application all the polygon vanishes. Please help

wfs_layer = new OpenLayers.Layer.Vector("wfs_layer", {
       strategies: [new OpenLayers.Strategy.Fixed(),saveStrategy],
       visibility: false,
       protocol: new OpenLayers.Protocol.WFS({
       version: "1.0.0",
       srsName: "EPSG:4326", // this is the default
       url:  "http://localhost:8089/geoserver/IIRS1/wms",
       featureType: "india_state",
       featureNS: "http://www.opengeospatial.net/IIRS1",
       extractAttributes: true,
   geometryName: "the_geom",
schema: "http://localhost/geoserver/wfs/DescribeFeatureType?version=1.1.0&;typename=IIRS1:india_state"
    })                     
        }
);

vector = new OpenLayers.Layer.Vector('vector');
map.addLayers([wfs_layer,vector]);

// saving

function saveSuccess(event) {
          alert('Changes saved');
          }
            function saveFail(event) {
           alert('Error! Changes not saved');
              }

        var saveStrategy = new OpenLayers.Strategy.Save();
        saveStrategy.events.register('success', null, saveSuccess);
        saveStrategy.events.register('fail', null, saveFail);

//adding draw polygon button to tool bar

    action = new GeoExt.Action({
    text: "draw_poly",
    control: new OpenLayers.Control.DrawFeature(
        vector, OpenLayers.Handler.Polygon),
    strategies: [saveStrategy],
    map: map,
    toggleGroup: "draw",
    allowDepress: false,
    tooltip: "draw_polygon",
     });
actions["draw_poly"] = action;


toolbarItems.push(action);
 toolbarItems.push("-");

// Saving button

action = new GeoExt.Action({
    text: "Save",
    control: new OpenLayers.Control.Button({
           trigger: function() {
      if(feature) {
                  feature.selectControl.unselectAll();
                  }
      saveStrategy.save();
  }
    }),
    map: map,
    // button options
    toggleGroup: "Save",
    allowDepress: false,
    tooltip: "Save",
     });
actions["Save"] = action;
toolbarItems.push(action);

toolbarItems.push("-")

share|improve this question
    
Is the feature getting saved in the database? –  pecoanddeco Oct 17 '12 at 15:33
    
No the feature does not get save in database..that is my main problem I sorry I forget to mention it in my question..I m using postgis 2.0 and postgresql 9.0 plz tell how to save the feature in database.. –  aaliya Oct 18 '12 at 5:01
    
Does your code ever reach the saveSuccess or saveFail functions? If it does then it's worth looking in the event object and seeing if anything useful is in there. If it doesn't then it would be worth hooking into the save start event to see whether any features are trying to be saved or not. –  pecoanddeco Oct 18 '12 at 13:04
    
Yes it does whenever I draw any polygon and then save it "changes saved" message comes and it is there till I reload the application again.As soon as the application is reloaded all the saved features are gone.. which means they don't get saved in database. –  aaliya Oct 19 '12 at 4:55

1 Answer 1

I had a similar problem before, what helped me, that I uncommented the line that starts with "schema", so like this:

geometryName: "the_geom",
//schema: "http://localhost/geoserver/wfs/DescribeFeatureType?version=1.1.0&;typename=IIRS1:india_state"
    }) 

and also I think this line is maybe wrong:

url:  "http://localhost:8089/geoserver/IIRS1/wms",

it should be wfs at the end, shouldn't it?

this article: http://www.gistutor.com/openlayers/22-advanced-openlayers-tutorials/47-openlayers-wfs-t-using-a-geoserver-hosted-postgis-layer.html helped me a lot, and also there is some troubleshooting in the comments

share|improve this answer
    
thanks Ylka for your suggestions but in may case the problem was in my geoserver It was not supporting the transaction I dont know why so I switeched to geoserver 2.2 and now it is working well. –  aaliya Oct 31 '12 at 5: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.