Quantcast
Channel: DotSpatial
Viewing all articles
Browse latest Browse all 3973

New Post: need a kick

$
0
0
OK, the scary thing is nobody else seems to know the web based services are displayed in WebMercator. Once I discovered that it was 5 minutes to have a Google search return a variety of conversion routines. Here is my version, as gleaned from several examples.

public static Coordinate WebMercatorToGeographic(double mercatorX, double mercatorY)
        {
        Coordinate coord = new Coordinate(0,0);
        if (((Math.Abs(mercatorX) > 20037508.3427892) || (Math.Abs(mercatorY) > 20037508.3427892)))
            {
            return coord;
            }
        double num4 = ((mercatorX / 6378137.0) * 57.295779513082323);
        double num5 = Math.Floor(Convert.ToDouble(((num4 + 180) / 360)));
        double num6 = (num4 - (num5 * 360));
        double num7 = (1.5707963267948966 - (2 * Math.Atan(Math.Exp((((1 * mercatorY) * -1) / 6378137.0)))));
        coord = new Coordinate(num6, num7 * 57.295779513082323);
        return coord;
        }

public static Coordinate GeographicToWebMercator(double lat, double lon)
        {
        Coordinate coord = new Coordinate(0,0);
        if ((Math.Abs(lon) > 180) || (Math.Abs(lat) > 90 ))
            {
            return coord;
            }
        double num = (lon * 0.017453292519943295);
        double x = (6378137.0 * num);
        double a = (lat * 0.017453292519943295);
        coord = new Coordinate(x, (3189068.5 * Math.Log(((1 + Math.Sin(a)) / (1 - Math.Sin(a))))));
        return coord;
        }
The map coordinates are converted for mouse move display to geo, and my database numbers, in geo, are converted to webmerc for plotting on the map. Works great now.

Viewing all articles
Browse latest Browse all 3973

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>