ArcEngine几何变换中的策略模式
使用策略模式可以减少分支语句,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几何变换中的策略模式的更多相关文章
- 设计模式(一):“穿越火线”中的“策略模式”(Strategy Pattern)
在前段时间呢陆陆续续的更新了一系列关于重构的文章.在重构我们既有的代码时,往往会用到设计模式.在之前重构系列的博客中,我们在重构时用到了“工厂模式”.“策略模式”.“状态模式”等.当然在重构时,有的地 ...
- 理解javascript中的策略模式
理解javascript中的策略模式 策略模式的定义是:定义一系列的算法,把它们一个个封装起来,并且使它们可以相互替换. 使用策略模式的优点如下: 优点:1. 策略模式利用组合,委托等技术和思想,有效 ...
- 在商城系统中使用设计模式----策略模式之在spring中使用策略模式
1.前言: 这是策略模式在spring中的使用,对策略模式不了解对同学可以移步在商城中简单对使用策略模式. 2.问题: 在策略模式中,我们创建表示各种策略的对象和一个行为,随着策略对象改变而改变的 c ...
- Springboot中实现策略模式+工厂模式
策略模式和工厂模式相信大家都比较熟悉,但是大家有没有在springboot中实现策略和工厂模式? 具体策略模式和工厂模式的UML我就不给出来了,使用这个这两个模式主要是防止程序中出现大量的IF ELS ...
- Java中的策略模式,完成一个简单地购物车,两种付款策略实例教程
策略模式是一种行为模式.用于某一个具体的项目有多个可供选择的算法策略,客户端在其运行时根据不同需求决定使用某一具体算法策略. 策略模式也被称作政策模式.实现过程为,首先定义不同的算法策略,然后客户端把 ...
- JAVA中的策略模式strategy
原文出自:http://ttitfly.iteye.com/blog/136467 1. 以一个算术运算为例,传统做法为: java 代码 package org.common; public cla ...
- JAVA中的策略模式
现在我们有一个虚基类-鸭子(abstract Duck). 有真鸭子,野鸭子,橡皮鸭子继承了该类.虚基类有swing方法,毕竟游泳是所有的鸭子都应有的功能.还有一个虚方法display,这个方法在子类 ...
- 设计模式-策略模式(Strategy Model)
1.概述 在开发过程中常常会遇到类似问题,实现一个功能的时候往往有多种算法/方法(策略),我们可以根据环境的不同来使用不同的算法或策略来实现这一功能. 如在人物比较排序的实现中,我们有 ...
- 第二章 --- 关于Javascript 设计模式 之 策略模式
这一章节里面,我们会主要的针对JavaScript中的策略模式进行理解和学习 一.定义 策略模式: 定义一系列的算法,把他们封装起来,并且是他们可以相互替换. (这样的大的定义纲领,真的不好理解,特别 ...
随机推荐
- python处理文本文件
在测试任务过程中都或多或少遇到自己处理文本文件的情况. 举个栗子: 客户端测试从异常日志中收集有用信息. 后端测试需要创建各种规则的压力的词表. ... 这里给大家分享一个使用python脚本处理文本 ...
- /etc/services
/etc/services文件是记录网络服务名和它们对应使用的端口号及协议,很多的系统程序要使用这个文件.一般情况下,不要修改该文件的内容,否则可能会造成端口冲突 常见的服务如下,各个字段分别表示:s ...
- 在windows上自动备份SVN版本库及定时删除
下面的脚本是在windows SVN的备份策略,采用的是hotcopy的方法 方案一: 1.先创建一个fullBackup的脚本:fullBackup.bat echo off rem Subvers ...
- 用gcc编译成可执行程序 (转)
#gcc hello.c 该命令将hello.c直接生成最终二进制可执行程序a.out 这条命令隐含执行了(1)预处理.(2)汇编.(3)编译并(4)链接形成最终的二进制可执行程序.这里未指定输出文件 ...
- iOS - UITableView判断reloadData加载数据已经结束
问题: stackoverflow上有人提问这样的问题 http://stackoverflow.com/questions/16071503/how-to-tell-when-uitableview ...
- Linux学习——定义命令行函数(cd .. -> ..)
在使用shell的时候,每天要面对各种命令行,比如ls , cd .. 等 抱着简单,可依赖的思想.有些可以简化的操作可以要通过在 ~/.bashrc 中进行添加: 1. cd .. -> .. ...
- JQuery事件e参数的方法preventDefault()取消默认行为
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 使用commons-email解析 eml文件
在对eml文件进行索引的时候需要先对其进行解析,提取出其中的收件人.发件人.文件内容和附件等信息 下边是解析eml文件的一个demo(在运行之前需要先导入mail.jar 和commons-email ...
- ios ASIHTTPRequest类库简介和使用说明
官方网站: http://allseeing-i.com/ASIHTTPRequest/ .可以从上面下载到最新源码,以及获取到相关的资料. 使用iOS SDK中的HTTP网络请求API,相当的复杂, ...
- Floyd求最小环并求不同最小环的个数
FZU2090 旅行社的烦恼 Time Limit: 2000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u [Subm ...