leafletgeoservercoordinate-systemsreprojection-error

Geoserver WFS coordinates reprojection returns wrong latitude


I'm using geoserver and leaflet to show some data in an application.

The geoserver connect to a DB which contains spatial data (points) in EPSG:3785 format.

Leaflet require EPSG:4326 format to show data so I'm getting geojson reference of this data asking the geoserver to reproject the coordinates from EPSG:3785 to EPSG:4326 using WFS param srsName. The problem is, while longitude is reprojected correctly latitude is not.

Fore example one of my points has this coordinates: 1078019.71674498 ; 5630250.19147139

Using CS2CS to convert them the result is 9.68401588134 ; 45.0554183303 (which are correct when showed on the map), while the geoserver returns 9.68401588 ; 45.24751598, way far from the position they should represent (rougthly 30km north).

I cannot understand why is just the longitude that is wrong neither what should I do to prevent this from happening, aside from asking data in the correct format.

Does anyone happen to had the same problem? Looking in the internet I couldn't find anything that could help me.

I tried to convert data in the layer definition but it was useless, the problem persist.


Solution

  • In case anyone would face this problem in future here is the solution:

    as LucasP.Luiz commented, it is simple as setting Declared SRS in layer definition to EPSG:3857 (see example), then the projection works as intended.