C#中使用GEO坐标绘制地图
他,
我想用 C# 绘制一个带有 LAT/LNG 坐标的国家地图。我必须将纬度/经度转换为像素,最好的方法是什么?我可以绘制“地图”,但它非常小,而且不在窗口的中心。
有人可以帮忙吗?我有这个代码:
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要选择地图投影(例如墨卡托投影、柱面等积投影或 Mollweide 投影),然后将坐标从地理 lat、LNG 转换为使用此投影。
其标准开源库是 proj.4。我知道周围有 C# 包装器,但我个人已经将 OGR 与 ogrsharp 包装器一起使用。 OGR 在内部使用 proj.4,但当您想要使用特定坐标系(例如在 prj 文件中定义)时,还添加了许多常用函数。
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).