ArcEngine几何变换中的策略模式

     使用策略模式可以减少分支语句,switch...Case,同时便于策略的扩展。

1. ITransform2D接口的Transform方法:

1 [C#]public void Transform (
2     esriTransformDirection  direction,
3     ITransformation  transformation);

大部分的Geometry对象都实现了ITransform接口,比如:IPoint,IPolygon的基类

 ITransformation是策略的抽象接口,如下:

2. ITransform3D接口的Transform3D方法:

1 [C#]public void Transform3D (
2     esriTransformDirectiondirection,
3     ITransformation3Dtransformation);

 ITransformation3D是策略的抽象接口,如下:

 

 1   private void RotateAroundPoint()
 2         {
 3             //Point to be rotated
 4             IPoint rotatePoint = new ESRI.ArcGIS.Geometry.Point();
 5             rotatePoint.PutCoords(2, 2);
 6             //Point around which to rotate
 7             IPoint centerPoint = new ESRI.ArcGIS.Geometry.Point();
 8             centerPoint.PutCoords(1, 1);
 9             //Rotation Angle
10             double angle = 45 * Math.PI / 180.0;
11             //Rotate Around pCenter
12             IAffineTransformation2D3GEN affineTransformation = new AffineTransformation2D() as IAffineTransformation2D3GEN;
13             affineTransformation.Move(-centerPoint.X, -centerPoint.Y);//将参考点移动到原点
14             affineTransformation.Rotate(angle);//围绕原点旋转
15             affineTransformation.Move(centerPoint.X, centerPoint.Y);//再平移回原来的位置
16             ITransform2D transformator = rotatePoint as ITransform2D;
17             transformator.Transform(esriTransformDirection.esriTransformForward, affineTransformation as ITransformation);
18 
19 
20             IPoint rotatePoint2 = new ESRI.ArcGIS.Geometry.Point();
21             rotatePoint2.PutCoords(2, 2);
22             IAffineTransformation2D affineTransformation2D = new AffineTransformation2D() as IAffineTransformation2D;
23             // affineTransformation2D.Move(-centerPoint.X, -centerPoint.Y);//将参考点移动到原点
24             affineTransformation2D.Rotate(angle);//围绕原点旋转
25             //affineTransformation2D.Move(centerPoint.X, centerPoint.Y);//再平移回原来的位置
26             ITransform2D transformator2 = rotatePoint2 as ITransform2D;
27             transformator2.Transform(esriTransformDirection.esriTransformForward, affineTransformation2D);
28 
29             //Set up Comparison Point
30             //This is the point the transformation should result in
31             IPoint comparePoint = new ESRI.ArcGIS.Geometry.Point();
32             comparePoint.PutCoords(2, 2);
33             transformator = comparePoint as ITransform2D;
34             transformator.Rotate(centerPoint, angle);
35             System.Windows.Forms.MessageBox.Show(
36                 "Using IAffineTransformation2D3GEN.Rotate:  Point X:" + rotatePoint.X + ", Y:" + rotatePoint.Y + "\n" +
37                 "Using IAffineTransformation2D::Rotate,  Point X:" + rotatePoint2.X + ", Y:" + rotatePoint2.Y + "\n" +
38                 "Using ITransform2D::Rotate,  Point X: " + comparePoint.X + ", Y:" + comparePoint.Y + "\n" +
39                 "Did X coordinates match? " + (rotatePoint.X == comparePoint.X) + "\n" +
40                 "Did Y coordinates match? " + (rotatePoint.Y == comparePoint.Y)
41             );
42 
43         }
测试代码

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值