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 }
作者:太一吾鱼水
文章未经说明均属原创,学习笔记可能有大段的引用,一般会注明参考文献。
欢迎大家留言交流,转载请注明出处。
分类:
ArcGIS Engine
标签:
策略模式
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程