[GIS] Trying to convert coordinates from WGS84 Web Mercator Auxiliary Sphere to WGS84

ccoordinate systemweb-mercatorwgs84

I've been struggling with this for way too long now. I've got some data that was georeferenced in the WGS84 Web Mercator Auxiliary Sphere that should have been done just in WGS84.

The Auxiliary Sphere (ESPG: 3857) is the projection commonly used by Google, Bing, and recently ArcGIS Online. The projected coordinates I have are in meters, as per Aux Sphere specs, but I've got to convert them to degrees and bring them into WGS84.

I know the Aux Sphere is just a projected version of WGS84, but I can't seem to wrap my mind around converting coordinates from a projected coordinate system to a geographic coordinate system.

I have some code that will convert from WGS84 Web Mercator (WKID: 102113) to WGS84, but because that system uses a spherical globe, rather than the ellipsoid used by WGS84 and the Aux Sphere, my results are a bit off. I've tried modifying it, but I can't seem to get it just right.

Here's my code if that is helpful:

public static void ToGeographic(ref double[] mercator)
    {
        if (Math.Abs(mercator[4]) < 180 && Math.Abs(mercator[5]) < 90)
            return;

        if ((Math.Abs(mercator[4]) > 20037508.3427892) || (Math.Abs(mercator[5]) > 20037508.3427892))
            return;

        double x = mercator[4];
        double y = mercator[5];
        double num3 = x / 6378137.0;
        double num4 = num3 * 57.295779513082323;
        double num5 = Math.Floor((double)((num4 + 180.0) / 360.0));
        double num6 = num4 - (num5 * 360.0);
        double num7 = 1.5707963267948966 - (2.0 * Math.Atan(Math.Exp((-1.0 * y) / 6378137.0)));
        mercator[4] = num6;
        mercator[5] = num7 * 57.295779513082323;


    }

Best Answer

My question is pretty much cleared up by mkennedy in the comments above.

The "Aux Sphere" version just has a parameter that says use the semimajor axis as the radius and then the sphere-based equations. -mkennedy

The code above transforms coordinates from WGS84 Web Mercator Auxiliary Sphere to WGS84 correctly. The issues I had were caused by a different problem within my data.

This post provides some excellent background on the two projections and their differences and uses.