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

1. ITransform2D接口的Transform方法:

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

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

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

2. ITransform3D接口的Transform3D方法:

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

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

   private void RotateAroundPoint()
{
//Point to be rotated
IPoint rotatePoint = new ESRI.ArcGIS.Geometry.Point();
rotatePoint.PutCoords(, );
//Point around which to rotate
IPoint centerPoint = new ESRI.ArcGIS.Geometry.Point();
centerPoint.PutCoords(, );
//Rotation Angle
double angle = * Math.PI / 180.0;
//Rotate Around pCenter
IAffineTransformation2D3GEN affineTransformation = new AffineTransformation2D() as IAffineTransformation2D3GEN;
affineTransformation.Move(-centerPoint.X, -centerPoint.Y);//将参考点移动到原点
affineTransformation.Rotate(angle);//围绕原点旋转
affineTransformation.Move(centerPoint.X, centerPoint.Y);//再平移回原来的位置
ITransform2D transformator = rotatePoint as ITransform2D;
transformator.Transform(esriTransformDirection.esriTransformForward, affineTransformation as ITransformation); IPoint rotatePoint2 = new ESRI.ArcGIS.Geometry.Point();
rotatePoint2.PutCoords(, );
IAffineTransformation2D affineTransformation2D = new AffineTransformation2D() as IAffineTransformation2D;
// affineTransformation2D.Move(-centerPoint.X, -centerPoint.Y);//将参考点移动到原点
affineTransformation2D.Rotate(angle);//围绕原点旋转
//affineTransformation2D.Move(centerPoint.X, centerPoint.Y);//再平移回原来的位置
ITransform2D transformator2 = rotatePoint2 as ITransform2D;
transformator2.Transform(esriTransformDirection.esriTransformForward, affineTransformation2D); //Set up Comparison Point
//This is the point the transformation should result in
IPoint comparePoint = new ESRI.ArcGIS.Geometry.Point();
comparePoint.PutCoords(, );
transformator = comparePoint as ITransform2D;
transformator.Rotate(centerPoint, angle);
System.Windows.Forms.MessageBox.Show(
"Using IAffineTransformation2D3GEN.Rotate: Point X:" + rotatePoint.X + ", Y:" + rotatePoint.Y + "\n" +
"Using IAffineTransformation2D::Rotate, Point X:" + rotatePoint2.X + ", Y:" + rotatePoint2.Y + "\n" +
"Using ITransform2D::Rotate, Point X: " + comparePoint.X + ", Y:" + comparePoint.Y + "\n" +
"Did X coordinates match? " + (rotatePoint.X == comparePoint.X) + "\n" +
"Did Y coordinates match? " + (rotatePoint.Y == comparePoint.Y)
); }

测试代码

ArcEngine几何变换中的策略模式的更多相关文章

  1. 设计模式(一):“穿越火线”中的“策略模式”(Strategy Pattern)

    在前段时间呢陆陆续续的更新了一系列关于重构的文章.在重构我们既有的代码时,往往会用到设计模式.在之前重构系列的博客中,我们在重构时用到了“工厂模式”.“策略模式”.“状态模式”等.当然在重构时,有的地 ...

  2. 理解javascript中的策略模式

    理解javascript中的策略模式 策略模式的定义是:定义一系列的算法,把它们一个个封装起来,并且使它们可以相互替换. 使用策略模式的优点如下: 优点:1. 策略模式利用组合,委托等技术和思想,有效 ...

  3. 在商城系统中使用设计模式----策略模式之在spring中使用策略模式

    1.前言: 这是策略模式在spring中的使用,对策略模式不了解对同学可以移步在商城中简单对使用策略模式. 2.问题: 在策略模式中,我们创建表示各种策略的对象和一个行为,随着策略对象改变而改变的 c ...

  4. Springboot中实现策略模式+工厂模式

    策略模式和工厂模式相信大家都比较熟悉,但是大家有没有在springboot中实现策略和工厂模式? 具体策略模式和工厂模式的UML我就不给出来了,使用这个这两个模式主要是防止程序中出现大量的IF ELS ...

  5. Java中的策略模式,完成一个简单地购物车,两种付款策略实例教程

    策略模式是一种行为模式.用于某一个具体的项目有多个可供选择的算法策略,客户端在其运行时根据不同需求决定使用某一具体算法策略. 策略模式也被称作政策模式.实现过程为,首先定义不同的算法策略,然后客户端把 ...

  6. JAVA中的策略模式strategy

    原文出自:http://ttitfly.iteye.com/blog/136467 1. 以一个算术运算为例,传统做法为: java 代码 package org.common; public cla ...

  7. JAVA中的策略模式

    现在我们有一个虚基类-鸭子(abstract Duck). 有真鸭子,野鸭子,橡皮鸭子继承了该类.虚基类有swing方法,毕竟游泳是所有的鸭子都应有的功能.还有一个虚方法display,这个方法在子类 ...

  8. 设计模式-策略模式(Strategy Model)

    1.概述     在开发过程中常常会遇到类似问题,实现一个功能的时候往往有多种算法/方法(策略),我们可以根据环境的不同来使用不同的算法或策略来实现这一功能.     如在人物比较排序的实现中,我们有 ...

  9. 第二章 --- 关于Javascript 设计模式 之 策略模式

    这一章节里面,我们会主要的针对JavaScript中的策略模式进行理解和学习 一.定义 策略模式: 定义一系列的算法,把他们封装起来,并且是他们可以相互替换. (这样的大的定义纲领,真的不好理解,特别 ...

随机推荐

  1. 【Graphlab】

    https://dato.com/ graphlab

  2. MySQL<事务与存储过程>

    事务与存储过程 事务管理 事务的概念 谓的事务就是针对数据库的一组操作,它可以由一条或多条SQL语句组成,同一个事务的操作具备同步的特点,即事务中的语句要么都执行,要么都不执行. 事务的使用 开启事务 ...

  3. ios 添加动画的方法

    转自文顶顶大神的博客:http://www.cnblogs.com/wendingding/p/3751519.html ios 开发UI中,经常会用添加动画效果的需求,下面就总结一下,添加动画的三种 ...

  4. Linux中下载、解压、安装文件(转)

    原文地址:http://www.cnblogs.com/red-code/p/5539399.html 一.将解压包发送到linux服务器上: 1.在windos上下载好压缩包文件后,通过winscp ...

  5. GeoServer安装说明-OpenSpirit

    一.安装步骤 1.安装JDK: 2.安装Tomcat:(本测试过程使用JspStudy,需要进行端口设置,并指定Web目录,如:D:\JspStudy\tomcat\webapps) 3.拷贝geos ...

  6. RIDE指定log和report的输出目录

    在命令行中,输入 pybot --help就可以看到他支持的所以命令和相关的介绍 我们可以看到outputdir这个命令,就是来知道report和log的输出目录的 如果你是在命令行中,那么直接后面跟 ...

  7. 安装memcacheq

    1.下载memcacheq包    下载地址:http://code.google.com/p/memcacheq/downloads/list    解压包:# tar -zxvf memcache ...

  8. ajax返回值传给js全局变量

    1. $.ajaxSetup({ async : false //设置ajax为同步方式,异步方式的话在赋值时数据还未提取出来 });var t = ""; var enginee ...

  9. poj_2352 Treap

    题目大意 对于二维平面上的n个点,给出点的坐标.定义一个点A覆盖的点的个数为满足以下条件的点B的个数:点B的x <= 点A的x坐标,点B的y坐标 <= 点A的y坐标.     给出N个点的 ...

  10. 腾讯云大数据套件Hermes-MR索引插件使用总结

    版权声明:本文由王亮原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/121 来源:腾云阁 https://www.qclou ...