I've used Proj.Net library to convert X, Y in EPSG 3857 to latitude and longitude coordinates in WGS84 and vice-versa, but the conversion of latitude is not accurate compared to http://spatialreference.org/ref/sr-org/6864/.
For example, if the input is:
5676207.469887, 4291510.258087
then outputs are:
50.990239260333, 36.116815741834
using spatialreference.org and50.990239260328906 36.116603266233213
using Proj.Net
Below is my code:
private const string Wkt3857 = "PROJCS[\"Popular Visualisation CRS / Mercator\", " +
"GEOGCS[\"Popular Visualisation CRS\", " +
"DATUM[\"Popular Visualisation Datum\", " +
"SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]]," +
"TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]]," +
"PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], " +
"UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], " +
"AXIS[\"E\", EAST], AXIS[\"N\", NORTH], " +
"AUTHORITY[\"EPSG\",\"4055\"]], " +
"PROJECTION[\"Mercator\"], " +
"PARAMETER[\"False_Easting\", 0], " +
"PARAMETER[\"False_Northing\", 0], " +
"PARAMETER[\"Central_Meridian\", 0], " +
"PARAMETER[\"Latitude_of_origin\", 0], " +
"UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], " +
"AXIS[\"East\", EAST], AXIS[\"North\", NORTH], " +
"AUTHORITY[\"EPSG\",\"3785\"]]";
public static void XyFromLatLng(double lat, double lng, out double x, out double y)
{
var gcsWgs84 = GeographicCoordinateSystem.WGS84;
var cf = new CoordinateSystemFactory();
var f = new CoordinateTransformationFactory();
var sys3857 = cf.CreateFromWkt(Wkt3857);
var transformTo3857 = f.CreateFromCoordinateSystems(gcsWgs84, sys3857);
double[] fromPoint = { lng, lat };
double[] output = transformTo3857.MathTransform.Transform(fromPoint);
x = output[0];
y = output[1];
}
public static void LatLngFromXY(double x, double y, out double lat, out double lng)
{
var gcsWgs84 = GeographicCoordinateSystem.WGS84;
var cf = new CoordinateSystemFactory();
var f = new CoordinateTransformationFactory();
var sys3857 = cf.CreateFromWkt(Wkt3857);
var transformToWgs84 = f.CreateFromCoordinateSystems(sys3857, gcsWgs84);
double[] fromPoint = { x, y };
double[] output = transformToWgs84.MathTransform.Transform(fromPoint);
lat = output[1];
lng = output[0];
}
So I need a library in C# to transform these two CRSs to each other as accurate as possible.
I used DotSpatial for projection and the values are accurate compared to PostGIS. But I don't find out the reason of latitude difference required using Proj.Net.