sharpmap v2学习研究(三)

先看看图像坐标和位置坐标的转换

打开SharpMap.VS2010-->Utilities-->Transform.cs可以看到如下代码

ContractedBlock.gif ExpandedBlockStart.gif 位置坐标和图像坐标转化代码
 
   
1 /// <summary>
2 /// 图像坐标和位置坐标的转换
3 /// </summary>
4 public class Transform
5 {
6 /// <summary>
7 /// 位置坐标(WCS) to 转换到图像坐标。
8 /// 注意: 该方法不能代替SharpMap.Map.MapToWorld方法
9 /// </summary>
10 /// <param name="p"> x,y坐标 </param>
11 /// <param name="map"> 所在的地图 </param>
12 /// <returns> 图像上的坐标 </returns>
13 public static PointF WorldtoMap(Point p, Map map)
14 {
15 // if (map.MapTransform != null && !map.MapTransform.IsIdentity)
16 // map.MapTransform.TransformPoints(new System.Drawing.PointF[] { p });
17 PointF result = new System.Drawing.Point();
18 double Height = (map.Zoom * map.Size.Height) / map.Size.Width;
19 double left = map.Center.X - map.Zoom * 0.5 ;
20 double top = map.Center.Y + Height * 0.5 * map.PixelAspectRatio;
21 result.X = ( float ) ((p.X - left) / map.PixelWidth);
22 result.Y = ( float ) ((top - p.Y) / map.PixelHeight);
23 return result;
24 }
25
26 /// <summary>
27 /// 从图像坐标转化到位置坐标 (WCS).
28 /// 注意: 该方法不能代替SharpMap.Map.MapToWorld instead)
29 /// </summary>
30 /// <param name="p"> 图像中点的坐标 </param>
31 /// <param name="map"> 所在的地图 </param>
32 /// <returns> 返回位置坐标x,y </returns>
33 public static Point MapToWorld(PointF p, Map map)
34 {
35 // if (this.MapTransform != null && !this.MapTransform.IsIdentity)
36 // {
37 // System.Drawing.PointF[] p2 = new System.Drawing.PointF[] { p };
38 // this.MapTransform.TransformPoints(new System.Drawing.PointF[] { p });
39 // this.MapTransformInverted.TransformPoints(p2);
40 // return Utilities.Transform.MapToWorld(p2[0], this);
41 // }
42 // else
43 Point ul = new Point(map.Center.X - map.Zoom * . 5 , map.Center.Y + map.MapHeight * . 5 );
44 return new Point(ul.X + p.X * map.PixelWidth,
45 ul.Y - p.Y * map.PixelHeight);
46 // BoundingBox env = map.Envelope;
47 // return new Point(env.Min.X + p.X*map.PixelWidth,
48 // env.Max.Y - p.Y*map.PixelHeight);
49 }
50 }

现在分析一下

WorldtoMap 方法是把位置的坐标转化为图像中的坐标。

MapToWorld方法是把图像中的坐标转化为位置坐标系中。

转载于:https://www.cnblogs.com/sharpmap/archive/2011/02/23/1962014.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值