need a kick

Mar 6, 2013 at 9:00 AM
I am trying to plot some points on a map, taken online from Google Maps, Bing, etc. The coordinates in my database are lat/long ie 53,-120 such as you see from a GPS or Googleearth.

The points draw and a layer is being created BUT they are all around the map point 0,0 (equator, Greenwich) . The coordinates from the map when using any of the providers are very LARGE numbers (13277607.00, 6951393.00) and thus my GPS points are all very tiny.

How can I change the map to use what I consider to be standard coordinates or alternately, how can I convert my database entries?

There is an example I have followed to create a FeatureSet from an Excel file, and it appears they are using the same style as I use, ie 53, -119

I must have missed something obviously simple, so that is why I am requesting a kick.
Mar 6, 2013 at 12:45 PM
I am new to DotSpatial and have not used the Map Control, but I have seen in my searches that you need to set the Projection Property of the map component to the same projection that your Lat/Lon coordinates are.
ProjectionInfo wgs = KnownCoordinateSystems.Geographic.World.WGS1984;
map.Projection = wgs; //This I am not sure of since I do not know the control
Mar 6, 2013 at 12:50 PM
If you create a new point layer with this projection you can use your lat/long values.
_myPoints = New FeatureSet(FeatureType.Point)
_myPoints.Projection = KnownCoordinateSystems.Geographic.World.WGS1984

Dim c As New Coordinate(53,-120)
Dim p As New DotSpatial.Topology.Point(c)
Dim currentFeature As IFeature = _myPoints.AddFeature(p)
Mar 6, 2013 at 2:33 PM
Edited Mar 6, 2013 at 2:34 PM
Thanks for the advice. Here is what I have set up, but it still does not work. The status display of the x,y coordinates is still ridiculously BIG and my points make one star at 0,0 of the map (for about 200 points).

The MainForm routine:
public MainForm()

        Shell = this;

setSiteMarkers();  // this is the only code I added
In the setSiteMarkers function to setup the layer.

ProjectionInfo wgs = KnownCoordinateSystems.Geographic.World.WGS1984;
this.map1.Projection = wgs;

// The FeatureSet starts with no data; be sure to set it to the point featuretype
this.dbMarkers = new FeatureSet(FeatureType.Point);
this.dbMarkers.Projection = wgs;

// The MapPointLayer controls the drawing of the marker features
this.dbMarkerLayer = new MapPointLayer(this.dbMarkers);
this.dbMarkerLayer.Projection = wgs;

// The Symbolizer controls what the points look like
this.dbMarkerLayer.Symbolizer = new PointSymbolizer(Color.Blue, DotSpatial.Symbology.PointShape.Star, 15);

// A drawing layer draws on top of data layers, but is still georeferenced.

//add feature set to map
this.dbMarkerLayer.LegendText = "Points From Sqlite";

In the actual database read routine I set the points like this (after reading the record and storing values in Lat and Lng)

Coordinate coord = new Coordinate(Lng, Lat);
DotSpatial.Topology.Point point = new DotSpatial.Topology.Point(coord);
IFeature feature = this.dbMarkers.AddFeature(point);

The layers for the basemap and points are selectable. Everything is working except the scale of the map does not go to GPS lat/lng (20.00, -120.00)

I'm still missing something.
Mar 6, 2013 at 3:07 PM
In the DotSpatial code, using the Example --> DemoMap, when you select GoogleMaps, or Bing, etc as the online provider, what is the actual units displayed in the status bar?

This is what seems to be out of whack for the GPS laymen system I wish to use. The number being shown make no sense to me and I do not have any idea what to even search for on Google.
Mar 7, 2013 at 1:36 AM
I have removed all my code and am concentrating on getting the mapping base display to honour the lat/long entries. I found the following and tried it.

ProjectionInfo wgs = KnownCoordinateSystems.Geographic.World.WGS1984;
        this.map1.Projection = wgs;
        this.map1.Projection.IsLatLon = false;
IsLatLon makes no difference whether true or false to the displayed coordinates. All online maps still show those BIG numbers for x,y in the status line. Can anyone tell me what base they are? Is there a conversion that I can use to apply to my database numbers?
Mar 8, 2013 at 3:48 AM
Edited Mar 8, 2013 at 3:49 AM
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.
Sep 19, 2013 at 7:19 AM
lonnien, thank you very much. This two functions helped me a lot. Great!