Search code examples
google-mapsgissharpmap

Google map as background to my sharpmap map not aligning correctly


I've been at this for quite a while now. What I'm trying to achieve here is to add Google map as background layer to my Sharpmap, I'm able to achieve this but the problem I'm facing now is My map always centre's to a point near a Greenland sea in Google Map , it's like it won't take my centre point coordinates.

I'm using Sharpmap 1.1 with BruTile 0.7.4.4

So far I've done the below.

SharpMap.Map _map = new SharpMap.Map();
SharpMap.Layers.VectorLayer layer = new SharpMap.Layers.VectorLayer("parcel");
SharpMap.Data.Providers.MsSqlSpatial DBlayer = new SharpMap.Data.Providers.MsSqlSpatial(_connectionString, "XXXXXX", "XXXX", "XXX");
layer.Style.Fill = new SolidBrush(Color.Transparent);
layer.Style.Outline = new Pen(Color.Black);
layer.Style.EnableOutline = true;
layer.MaxVisible = 13000;

layer.DataSource = DBlayer;

ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
layer.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
layer.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84);

//SharpMap.Layers.TileLayer layerBackground = new TileLayer(new BingTileSource(BingRequest.UrlBing, "", BingMapType.Aerial), "TileLayer");
SharpMap.Layers.TileLayer layerBackground = new TileLayer(new GoogleTileSource(GoogleMapType.GoogleMap), "googlemaps");   

_map.Layers.Add(layerBackground);

_map.Layers.Add(layer);

_map.BackColor = Color.White;

//-98.526890,29.411539  
_map.Center = new GeoAPI.Geometries.Coordinate(0,0);

return _map;

Even if I manually give Geo Coordinates It just points to the same spot in the sea.

Please see the below Google map Geo point, this is the point where my map shows as centre. Every time I generate no matter what I do it shows this point as its centre.

71.946088, -3.956171

Any help is much appreciated. Thanks and Cheers!


Solution

  • I found the problem for Google map layer not centring. The reason is that I used QGIS to convert my ESRI shapefile from WGS84(EPSG:4326) format to Spherical Mercator(EPSG:900913) and it changed the coordinates format but

    Google Maps use Google Maps Global Mercator (Spherical Mercator).

    When I used an online converter to test this out which you can find here. When I gave the resulting coordinates, it worked out just fine. Now all I have to do is find a way to convert Google Maps Global Mercator (Spherical Mercator). Thanks for your help @pauldendulk.