blakerg

Trying to convert coordinates from Web Mercator Auxiliary Sphere to WGS84

Discussion created by blakerg on Aug 20, 2013
Latest reply on Aug 20, 2013 by MKennedy-esristaff
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.

I work in a library and we are uploading scanned georeferenced maps to an internet archive service that prefers WGS84 (I know every other web mapping service uses the Auxiliary Sphere, but that's what they want) so I've got to fix my data.

The Auxiliary Sphere (ESPG: 3957) 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;


    }

Outcomes