4

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;


    }
  • 1
    The "Aux Sphere" version just has a parameter that says use the semimajor axis as the radius and then the sphere-based equations. I don't see anything wrong, beyond the first check (those values are perfectly acceptable in Mercator although the area's offshore). What are you getting and what do you think you should be getting? – mkennedy Aug 20 '13 at 18:27
  • Here's a sample point. x = -10000000, y = +5000000. latitude = 40.91627447, longitude = -89.83152841 – mkennedy Aug 20 '13 at 18:32
  • Excellent. It's nice to get some validation on that. So my coordinates are getting transformed correctly, but I'm still having a problem with my data. I'm editing world files for some TIFF and JPEG images. I guess the problem I'm having is with the pixel size and rotation at this point, but that's getting off topic on this post. Thanks for your help! – BlakeG Aug 20 '13 at 21:13
  • 1
    It is simple but please one of you post the answer and check it. We want to promote GOOD question/answer practice – Brad Nesom Aug 21 '13 at 4:36
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.