DotSpatial and GMap.NET

Nov 18, 2012 at 3:48 AM

Someone has worked with GMap.NET into DotSpatial to load a satellite image in the DotSpatial.Controls.Map?

Nov 23, 2012 at 12:50 PM

There are to ways I am working with satellite image in my DotSpatial app.

1. Take the actual map window an show the same frame (+- GMap.NET has fixed zoom levels) in GMap.NET.

 Dim wmX As Double
            Dim wmY As Double
            Dim wmWidth As Double
            Dim wmHeight As Double

            With GMapControl1
                '.Visible = True
                '.Dock = DockStyle.Fill
                .MapProvider = GMapProviders.GoogleSatelliteMap
                '.MapScaleInfoEnabled = True
                .MinZoom = 2
                .MaxZoom = 17
                '.Zoom = 2
                .Manager.Mode = GMap.NET.AccessMode.ServerAndCache
                GMapControl1.DragButton = Windows.Forms.MouseButtons.None
            End With


            If Map1.ProjectionEsriString.Contains("Web_Mercator") Then
                WebMercatorToGeographic(Map1.ViewExtents.MinX, Map1.ViewExtents.MaxY, wmX, wmY)
                WebMercatorToGeographic(Map1.ViewExtents.Width, Map1.ViewExtents.Height, wmWidth, wmHeight)
                'MsgBox(wmX & " - " & wmY)
                Dim OSM_rec_WM As New GMap.NET.RectLatLng(wmY, wmX, wmWidth, wmHeight)
                GMapControl1.SetZoomToFitRect(OSM_rec_WM)


            Else
                Dim OSM_rec As New GMap.NET.RectLatLng(Map1.ViewExtents.MaxY, Map1.ViewExtents.MinX, Map1.ViewExtents.Width, Map1.ViewExtents.Height)
                GMapControl1.SetZoomToFitRect(OSM_rec)
            End If
            currentMarker.Position = GMapControl1.Position
        

Private Sub WebMercatorToGeographic(ByVal mercatorX As Double, ByVal mercatorY As Double, ByRef lat As Double, ByRef lon As Double)
If ((mercatorX < -20037508.3427892) _
OrElse (mercatorX > 20037508.3427892)) Then
Throw New ArgumentException("Point does not fall within a valid range of the mercator projection.")
End If
Dim x As Double = mercatorX
Dim y As Double = mercatorY
Dim num3 As Double = (x / 6378137)
Dim num4 As Double = (num3 * 57.295779513082323)
Dim num5 As Double = Math.Floor(CType(((num4 + 180) / 360), Double))
Dim num6 As Double = (num4 - (num5 * 360))
Dim num7 As Double = (1.5707963267948966 - (2 * Math.Atan(Math.Exp((((1 * y) * -1) / 6378137)))))
lat = num6
lon = (num7 * 57.295779513082323)
End Sub

Private Sub GeographicToWebMercator(ByVal lat As Double, ByVal lon As Double, ByRef mercatorX As Double, ByRef mercatorY As Double)
If ((lat < -90) _
OrElse (lon > 90)) Then
Throw New ArgumentException("Point does not fall within a valid range of a geographic coordinate system.")
End If
Dim num As Double = (lat * 0.017453292519943295)
Dim x As Double = (6378137 * num)
Dim a As Double = (lon * 0.017453292519943295)
mercatorX = x
mercatorY = (3189068.5 * Math.Log(((1 + Math.Sin(a)) / (1 - Math.Sin(a)))))
End Sub

 

The second way is to use the DotSpatial.Controls.BruTileLayer from FObermaier. This works fine.

First download the source from

http://groups.google.com/group/dotspatial-dev/browse_thread/thread/5e8942d43c5b653e

Open the project and compile with your actual DotSpatial version.

To use with google maps add this to his code:

 public static BruTileLayer CreateGoogleMapLayer()
        {
            return new BruTileLayer(new GoogleTileSource(GoogleMapType.GoogleMap), new MemoryCache<byte[]>(100, 200));
        }

        public static BruTileLayer CreateGoogleSatelliteLayer()
        {
            return new BruTileLayer(new GoogleTileSource(GoogleMapType.GoogleSatellite), new MemoryCache<byte[]>(100, 200));
        }

The result is this:

https://dl.dropbox.com/u/39631349/googleSat.png

Nov 23, 2012 at 5:56 PM

thanks a lot...

I will try to do that you say...

Nov 23, 2012 at 5:56 PM

the link is broken....


http://groups.google.com/group/dotspatial-dev/browse_thread/thread/5e8942d43c5b653e

Nov 23, 2012 at 8:03 PM

You can download from my Dropbox

https://dl.dropbox.com/u/39631349/DotSpatial.Controls.BruTileLayer.zip

Nov 24, 2012 at 10:24 PM

Thank you very much...

downloading it... 

I will study thank a lot...

Mar 21, 2013 at 4:04 AM
Everything works fine but in the case of "CreateGoogleSatelliteLayer" server is not found
Mar 21, 2013 at 6:31 AM
I tried it this moment and for me it works.

_btLayer = BruTileLayer.CreateGoogleSatelliteLayer
Mar 21, 2013 at 2:48 PM
add to DotSpatial.Controls.BruTileLayer the above lines of code to add the kind of google, even I added:
GoogleTerrain
GoogleLabels

and all work well but not GoogleSatellite.

:(
Mar 21, 2013 at 3:11 PM
Now i compiled with DS 1.4 here the 2 dlls you need.
This works actualy for me, if this dlls work for you too I send you the source again.

https://dl.dropbox.com/u/39631349/Release.zip

-;)

Thomas
Mar 21, 2013 at 4:47 PM
Thomas thank you very much me your dll works great but I would like to have the project DotSpatial.Controls.BruTileLayer could you send it to me, since my project does not work well

sorry for me english... :D
Mar 23, 2013 at 6:13 AM
Hi Camiza,

You can download the source here.
https://dl.dropbox.com/u/39631349/DotSpatial.Controls.BruTileLayer.zip
It works with brutile.dll 0.5.1.0

Thomas
Sep 23, 2013 at 3:08 PM
Mar 4, 2014 at 5:15 AM
Dear Camiza,
I am facing the following error as i am using dotspatial 1.0.
I just want to add OSM layer to map control. It will be nice if you help me.
"Error 2 Assembly 'DotSpatial.Controls.BruTileLayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bd5ca4b760779a42' uses 'BruTile, Version=0.5.1.0, Culture=neutral, PublicKeyToken=00e75fd79e391f40' which has a higher version than referenced assembly 'BruTile, Version=0.4.0.0, Culture=neutral, PublicKeyToken=00e75fd79e391f40' c:\Users\Director\Documents\Visual Studio 2010\Projects\PRSC Desktop GIS\PRSC Desktop GIS\bin\DotSpatial.Controls.BruTileLayer.dll PRSC Desktop GIS"

Regards,
Dheeraj