zoukankan      html  css  js  c++  java
  • 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 + "
    " +
    37                 "Using IAffineTransformation2D::Rotate,  Point X:" + rotatePoint2.X + ", Y:" + rotatePoint2.Y + "
    " +
    38                 "Using ITransform2D::Rotate,  Point X: " + comparePoint.X + ", Y:" + comparePoint.Y + "
    " +
    39                 "Did X coordinates match? " + (rotatePoint.X == comparePoint.X) + "
    " +
    40                 "Did Y coordinates match? " + (rotatePoint.Y == comparePoint.Y)
    41             );
    42 
    43         }
    测试代码

  • 相关阅读:
    正则中的顺序环视和逆序环视
    LeetCode 第 27 场双周赛
    LeetCode 每日一题 198. 打家劫舍
    LeetCode 每日一题 974. 和可被 K 整除的子数组
    LeetCode 每日一题 287. 寻找重复数
    LeetCode 每日一题 4. 寻找两个正序数组的中位数
    LeetCode 每日一题 146. LRU缓存机制
    LeetCode 每日一题 105. 从前序与中序遍历序列构造二叉树
    [转]多线程的那点儿事
    LeetCode 每日一题 5. 最长回文子串
  • 原文地址:https://www.cnblogs.com/yhlx125/p/3547918.html
Copyright © 2011-2022 走看看