ThinkGeo.com    |     Documentation    |     Premium Support

GetGoogleMapParametersString returns a wrong map projection string

Hi ThinkGeo Support,


I think there is a bug in the static function Proj4Projection::GetGoogleMapParametersString() which should  return the map projection string used by Google Map.


The function returns:

"+proj=merc+a=6378137+b=6378137+lat_ts=0.0+lon_0=0.0+x_0=0.0+y_0=0+k=1.0+units=m+no_defs"

The parameters a and b cannot be identical. If they were identical the earth were spherical and not an ellipsoid as expected.


The correct map projection string is 

"+proj=merc+a=6378137+b=6356752.31424518+lat_ts=0.0+lon_0=0.0+x_0=0.0+y_0=0+k=1.0+units=m+no_defs"


This projection string is copied from the WGS 84 ellipsoid which is used by Google Map.


Best regards

Niels

 



I tested what you are claiming by projecting a shapefile in WGS84 to our Google Map projection and to your Google Map projection. You can see in the screen shot below that the shapefile in our projection (in red) is correct while the shapefile in your projection (in green) is incorrect. So I think that we have the correct projection string for Google Map.



This is the code I used:


 



           winformsMap1.MapUnit = GeographyUnit.Meter;
            winformsMap1.CurrentExtent = new RectangleShape(-14180662, 5547256, -7832569, 1777465);
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));

            // Create your overlay and make sure to register and insert your own key.
            GoogleMapsOverlay googleOverlay = new GoogleMapsOverlay(); //(@"Insert your key here!", @"C:\GoogleCache");
            winformsMap1.Overlays.Add(googleOverlay);

            // This sets the zoom levels to map to Googles.  We next make sure we snap to the zoomlevels
            winformsMap1.ZoomLevelSet = new GoogleMapZoomLevelSet();

            //Google
            Proj4Projection proj4 = new Proj4Projection();
            proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
            proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

            ShapeFileFeatureLayer layer1 = new ShapeFileFeatureLayer(@"..\..\Data\austinstreets.shp");
            LineStyle lineStyle = new LineStyle(new GeoPen(GeoColor.StandardColors.Red,2));
            layer1.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = lineStyle; 
            layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            layer1.FeatureSource.Projection = proj4;

            //Google test
            Proj4Projection proj42 = new Proj4Projection();
            proj42.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
            proj42.ExternalProjectionParametersString = "+proj=merc+a=6378137+b=6356752.31424518+lat_ts=0.0+lon_0=0.0+x_0=0.0+y_0=0+k=1.0+units=m+no_defs";

            ShapeFileFeatureLayer layer2 = new ShapeFileFeatureLayer(@"..\..\Data\austinstreets.shp");
            LineStyle lineStyle2 = new LineStyle(new GeoPen(GeoColor.StandardColors.Green, 2));
            layer2.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = lineStyle2;
            layer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            layer2.FeatureSource.Projection = proj42;
           

            LayerOverlay layerOverlay = new LayerOverlay();
            layerOverlay.Layers.Add(layer1);
            layerOverlay.Layers.Add(layer2);
            winformsMap1.Overlays.Add(layerOverlay);


            winformsMap1.Refresh();