Geoserver WFS Point Coordinates

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Nov 25, 2013 at 2:30 PM
I'm using SharpMap's desktop client within a C# WinForms application and GeoServer/PostGis as datasource.
When i add a WFS layer that contains Multi-Line it works like charm. But when i add a point layer SharpMap.Utilities.Wfs.ParseCoordinates function parses coordinates with the wrong order, i meant it assigns X coordinate to Y value and Y to X.

ParseCoordinate function is like that:

protected Coordinate[] ParseCoordinates(XmlReader reader)
{
    if (!reader.Read()) return null;

    string name = reader.LocalName;
    string coordinateString = reader.ReadElementString();
    var vertices = new List<Coordinate>();
    string[] coordinateValues;
    int i = 0, length = 0;

    if (name.Equals("coordinates"))
        coordinateValues = coordinateString.Split(_Cs[0], _Ts[0]);
    else
        coordinateValues = coordinateString.Split(' ');

    length = coordinateValues.Length;

    while (i < length - 1)
    {
        double c1 = Convert.ToDouble(coordinateValues[i++], _FormatInfo);
        double c2 = Convert.ToDouble(coordinateValues[i++], _FormatInfo);

        if (name.Equals("coordinates") || name.Equals("pos"))
            vertices.Add(new Coordinate(c1, c2));
        else
            vertices.Add(new Coordinate(c2, c1));
    }

    return vertices.ToArray();
}
I've changed order of c1 and c2 values to fix that problem but not sure why it's acting like that.
Here goes the GML output of my geoserver:
<gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">51.52672002,25.33049886</gml:coordinates>
X = 51 and y = 25

but reader.ReadElementString(); statement at ParseCoordinates function reads them like that:

25 - 51
Developer
Nov 25, 2013 at 7:24 PM
AFAIK how to read X and Y values depends on SRID.
What coordinate system do you use?
Nov 25, 2013 at 7:35 PM
EPSG:4326 - WGS84
Nov 26, 2013 at 6:32 AM
Btw if i view that layers with open layers there isn't any problem. Altough i've tried to group these two layers with geoserver and open layers still fine but sharpmap still parses point layer's coordinates wrong.
Developer
Nov 26, 2013 at 8:42 AM
Edited Nov 26, 2013 at 8:42 AM
ahmetkakici wrote:
Btw if i view that layers with open layers there isn't any problem.
OpenLayers WFS? Or Geoserver Preview? Anyway, EPSG 4326 one of the most used SRS, so it's really strange a bug with this kind of data...
Nov 26, 2013 at 8:48 AM
I meant i'm using geoserver preview with openlayers/wms. I said that to clarify that my data coordinates are not wrong.
And i just gave up using wfs and turned back to wms and sending getFeatureRequests to GeoServer from codebehind. Just curious about that problem is only for me or everyone (:
Coordinator
Nov 26, 2013 at 9:51 AM
From the GDAL documentation for the GML driver I gather that the coordinates should be in the order defined by the spatial reference system.
The ParseCoordinates function does not evaluate the coordinate order of the spatial reference system, so this seems to be a bug.
Coordinator
Nov 26, 2013 at 9:52 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Marked as answer by ahmetkakici on 11/26/2013 at 7:21 AM