3

He,

I want to draw a Countrymap in C# with LAT/LNG coordinates. I have to translate the lat/lng to pixels, what would be the best way? I can draw the 'Map' but it's very small and it's not in the center of the window.

Can someone help? I have this code:

    void draw(Graphics g, PointF[] points, Pen p)
    {            
        Graphics gfx = g;
        gfx.PageUnit = GraphicsUnit.Point;

        GraphicsPath gpath = new GraphicsPath();
        gpath.StartFigure();
        gpath.AddLines(points);
        gpath.CloseFigure();

        Matrix m = new Matrix();
        m.Scale(5, 5);

        gfx.Transform = m;
        gfx.DrawPath(p, gpath);            
        gfx.Dispose();
        gpath.Dispose();

        return;
    }
Digital Human
  • 1,599
  • 1
  • 16
  • 26

1 Answers1

0

You will need to choose a map projection (eg. Mercator, Cylindrical Equal Area, or Mollweide) and then transform the coordinates from geographic lat,LNG to use this projection.

The standard open source library for this is proj.4. I understand there are C# wrappers around, ut personally I've used OGR with the ogrsharp wrappers. OGR uses proj.4 internally but also adds a lot of used functions when you want to work with specific coordinate systems (eg defined in a prj file).

winwaed
  • 7,645
  • 6
  • 36
  • 81
  • Of course you hard code a single projection. This would be simplest, but you will need to decide on your projection first. – winwaed Nov 23 '10 at 12:30
  • Ok thanks for the help. I'll take a look at it. I already found out how to move the drawing and resize it. – Digital Human Nov 23 '10 at 13:56