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.

In my web map application, I have added the editable wfs vector layer for feature editing. But in save strategy method, Insert and Update Geometry is working fine.But Update Attributes is not saved in transaction. Did I miss anything to include while adding editable layer? Please suggest me to fix this problem.

var saveStrategy;
function init(){ 
format = 'image/png';

bounds = new OpenLayers.Bounds(
            -288161.9289062237, -435.65815425360597,
            949406.755566389, 1300000
        );
var options = {
controls: [],
maxExtent: bounds,
maxResolution: 5079.826789665053,
projection: "EPSG:404000",
units: 'm'
};

 osMap = new OpenLayers.Map('map', options);

//Setup Base layer
tiled = new OpenLayers.Layer.WMS(
            "Oxford_Map", "http://xxx.xx.x.xx:8080/geoserver/cite/wms",
            {
                LAYERS: 'Oxford_Map',
                STYLES: '',
                format: format,
                tiled: true,
                tilesOrigin: osMap.maxExtent.left + ',' + osMap.maxExtent.bottom
            },
            {                        
                buffer: 0,
                displayOutsideMaxExtent: true,
                isBaseLayer: true,
                yx: { 'EPSG:404000': false }
            }                  
        );

untiled = new OpenLayers.Layer.WMS(
            "Oxford_Map", "http://xxx.xx.x.xx:8080/geoserver/cite/wms",
            {
                LAYERS: 'Oxford_Map',
                STYLES: '',
                format: format
            },
            {                        
                singleTile: true,
                ratio: 1,
                isBaseLayer: true,
                yx: { 'EPSG:404000': false }
            }                    
        );

 osMap.addLayers([untiled, tiled]);

 //set up a save strategy
saveStrategy = new OpenLayers.Strategy.Save();
saveStrategy.events.register("success", '', ChangesSuccess);
saveStrategy.events.register("failure", '', ChangesFailed);

wfs = new OpenLayers.Layer.Vector("ODC_Private_Graphics_Data", {
    strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],     
    projection: 'EPSG:27700',
    protocol: new OpenLayers.Protocol.WFS({
        version: '1.1.0',
        url: 'http://xxx.xxx.x.xx:8080/geoserver/wfs',
        featurePrefix: 'cite',
        featureNS: 'http://www.opengeospatial.net/cite',                        
        featureType: 'ODC_Private_Graphics_Data', 
        geometryName: 'the_geom',           
        extractAttributes: true,
        srsName: 'EPSG:27700',
        isBaseLayer: false,
        visibility: true,
        schema: 'http://xxx.xxx.x.xx:8080/geoserver/wfs/DescribeFeatureType?version=1.1.0&;typename=cite:ODC_Private_Graphics_Data',
    });


osMap.addLayers([wfs]);
}

    //This function will be invoked when I click on save image in web map application 
 function saveFeature() { 
  for (var ss = 0; ss < wfs.selectedFeatures.length; ss++) {
      var selFeat = wfs.selectedFeatures[ss];

      selFeat.attributes.FeatureName = 'Test';
       selFeat.state = OpenLayers.State.UPDATE;
  }

  saveStrategy.save();
 }


function delFeature() {
if (wfs.selectedFeatures.length > 0) {
for (var dd = 0; dd < wfs.selectedFeatures.length; dd++) {
     var selFeat = wfs.selectedFeatures[dd];
     if (selFeat.fid == undefined) {
         this.wfs.destroyFeatures([selFeat]);
        } else {
        selFeat.state = OpenLayers.State.DELETE;
        this.wfs.events.triggerEvent("afterfeaturemodified", { feature: selFeat });
        selFeat.renderIntent = "select";
        this.wfs.drawFeature(selFeat);
        }
    }    
} 

 function ChangesSuccess() {
  alert('Done');
 }

 function ChangesFailed() {
  alert('Failed');
 }
share|improve this question

1 Answer 1

Only clues here: difficult to help you when not easy to reproduce on my own

  • Did you set the proxy?
  • Using the OpenLayers call, did you try to debug the save part only on your server side (GeoServer)? You can do that by using a tool like Fiddler Windows only) or Charles (not free) You have to catch the call, replay it and make modifications. You can also use the Firefox or Google Chrome "Copy as CURL" functions (https://coderwall.com/p/-fdgoq) to do the same. You will be able to play on the featureNS or featurePrefix parameters. When your tests will be done on server side (and work), you will just have to make modifications in your OpenLayers code to make things work.
share|improve this answer
    
Now its save the changes in postgis. But when we viewing it again, geoserver returns the error "Internal error occurred java.io.IOException null ERROR: Operation on two geometries with different SRIDs". I checked in postgis table, there is no different SRID, all are in 404000. I have used the below queries to check and update the SRIDS. SELECT ST_SRID(the_geom) FROM "ODC_Private_Graphics_Data" LIMIT 100; UPDATE "ODC_Private_Graphics_Data" SET the_geom = ST_Transform(the_geom,404000); UPDATE "ODC_Private_Graphics_Data" SET the_geom = ST_SetSRID(the_geom, 404000); –  venkat Nov 4 '13 at 10:41
    
I need to store Polygon,Point and LineString in ODC_Private_Graphics_Data table.Kindly suggest me. –  venkat Nov 4 '13 at 10:44
    
You have two place for SRID: at the geometry_columns table (or view for PostGIS 2.0). But you also have to set your SRID in the geometry of each database record. Do something like UPDATE yourTable set the_geom = ST_setSRID(the_geom, yourSRIDdeclaredInGeoServer); Your error is clearly due to this mismatch. Does your SRID is present in PostGIS spatial_ref_sys? And in your Geos EPSG declaration file (for transformation, PostGIS is using Geos and if SRID is not set, it will not work well) –  ThomasG77 Nov 4 '13 at 18:30
    
Yes thanks Thomas.As per your instruction now Insert,Update and Delete Geometry is working. But Update with Attributes is not working.I have updated the code above. (saveFeature) Now problem in update attribute or inserting feature with attribute. If it is fixed, my all issue will be solved.Kindly help me plz –  venkat Nov 5 '13 at 10:14
    
Thanks Thomas everything is working fine now.I did small mistake in geoserver thats what i cant update the attribute. I forget to reload the feature type in geoserver after added the new attribute column in postgis. –  venkat Nov 5 '13 at 11:29

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.