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 wfs vector layer for feature editing. There is no issue When I save the feature in postgis after editing. But when I refresh the wfs layer, its showing the edited portion in somewhere. See the below image

enter image description here

Here is my code:

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]);

   graphicsWFSlayer = new OpenLayers.Layer.Vector("Graphics Data", {
    strategies: [new OpenLayers.Strategy.BBOX()],       
    projection: osMap.projection,        //EPSG:404000
    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',
        maxExtent: osMap.getExtent,
        featureType: 'ODC_Private_Graphics_Data',
        geometryName: 'the_geom',
        extractAttributes: true,            
        srsName: osMap.projection,  //EPSG:404000
        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([graphicsWFSlayer]);
 }

 // This function will be called when we click save icon on map web page.

 function saveFeature(){
 var selFeat = graphicsWFSlayer.selectedfeatures[0];
 var featCoordinates = '';
 var geoType = selFeat.geometry.CLASS_NAME.split('.');
 var vertices = selFeat.geometry.getVertices();
 for (var nd = 0; nd < vertices.length; nd++) {
     if (featCoordinates == '') {
          featCoordinates = vertices[nd].y + " " + vertices[nd].x
     }
     else {
         featCoordinates += ', ' + vertices[nd].y + " " + vertices[nd].x
     }
 }
 if (selFeat.geometry.CLASS_NAME == 'OpenLayers.Geometry.Polygon' && vertices.length > 2) {
     featCoordinates += ', ' + vertices[0].y + " " + vertices[0].x
     featCoordinates = '(' + featCoordinates + ')';
 }            
 WebService.saveGraphicsFeature(keyId, featCoordinates);
}

//My webservice function is:
  <WebMethod(enablesession:=True)> _
  Public Function saveGraphicsFeature(ByVal ObjId As String, ByVal coordinates As      String) As String
    Try
   If updateGraphicsFeature(ObjId, coordinates) = False Then
            Dim qryStr As String = "INSERT INTO ODC_Private_Graphics_Data (the_geom)    VALUES (ST_GeomFromText('POLYGON(" + coordinates + ")'))"
            dbObj.Connect()
            Dim insertCmd As NpgsqlCommand = New NpgsqlCommand(qryStr, dbObj.dbCon)
            Dim affectedRows As Integer = insertCmd.ExecuteNonQuery
            dbObj.Disconnect()
            insertCmd.Dispose()
            insertCmd = Nothing
   End if
    Catch ex As Exception

    Finally
        dbObj.Disconnect()
    End Try
End Function

 Private Function updateGraphicsFeature(ByVal ObjId As String, ByVal coordinates As   String) As Boolean

    Try

        Dim qryStr As String = "UPDATE ODC_Private_Graphics_Data SET the_geom =    ST_GeomFromText('POLYGON(" + coordinates + ")') WHERE gid = " & ObjId

        dbObj.Connect()
        Dim updateCmd As NpgsqlCommand = New NpgsqlCommand(qryStr, dbObj.dbCon)
        Dim updatedRows As Integer = updateCmd.ExecuteNonQuery
        dbObj.Disconnect()
        updateCmd.Dispose()
        updateCmd = Nothing

        If updatedRows = 1 Then Return True

        Return False

    Catch ex As Exception

    Finally
        dbObj.Disconnect()
    End Try
End Function

Please help me to fix this issue. did i miss any step in my code? or Should I set projection anywhere?

share|improve this question
1  
Why don't you use GeoServer WFS-T workshops.boundlessgeo.com/geoext/wfs/wfst.html instead of reinventing the wheel on your server side? You will limit problems by reducing your own custom code (not a critic, just the less custom code you do the more you avoid trouble) –  ThomasG77 Nov 1 '13 at 20:18
    
Yes I tried that method. But I have problem in that method as well.Please see my post regarding this gis.stackexchange.com/questions/76259/… and give me your valuable solutions –  venkat Nov 2 '13 at 10:10

1 Answer 1

up vote 1 down vote accepted

It looks like you're incorrectly capturing the eastings/northings (x/y) components of your coordinates in your saveFeature javascript function: e.g.

featCoordinates = vertices[nd].y + " " + vertices[nd].x

I think should be

featCoordinates = vertices[nd].x + " " + vertices[nd].y
share|improve this answer
    
Yes problem solved. Thanks –  venkat Nov 4 '13 at 10:18

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.