ArcGIS Engine 中的绘制与编辑
发布日期:2021-09-03 20:14:01 浏览次数:1 分类:技术文章

本文共 5014 字,大约阅读时间需要 16 分钟。

 

1、线段绘制

基本步骤

构建形状

1. 创建 IPoint

IPoint m_Point = new PointClass();
m_Point.PutCoords(x, y);
2. 创建 IPointCollection
IPointCollection m_PointCollection = new PolylineClass();
m_PointCollection.AddPoint(m_Point, ref Type.Missing, ref Type.Missing);
3. 创建 IPolyline
IPolyline m_Polyline = new PolylineClass();
m_Polyline = m_PointCollection as IPolyline;
4. 创建 IElement
// Element 不能实例化,需要用其派生类实例化
IElement m_Element = m_SimpleLineSymbol as IElement;
m_Element.Geometry = m_Polyline;
设置形状样式
1. 创建 ISimpleLineSymbol
ISimpleLineSymbol m_SimpleLineSymbol = new SimpleLineSymbolClass();
2. 创建 ILineElement
ILineElement m_LineElement = new LineElementClass();
m_LineElement.Symbol = m_SimpleLineSymbol;
加载到地图
IMap m_Map = axMapControl1.Map;
IActiveView m_ActiveView = m_Map as IActiveView;
IGraphicsContainer m_Container = m_Map as IGraphicsContainer;

m_Container.AddElement(m_Element, 0);

m_Active.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

 

 

-----------------------------------------------------------------------------------------------------------

其他方法

 
View Code

2、编辑

点编辑:

IPoint pt;  pt = axMapControl1.ToMapPoint(e.x, e.y);  IMarkerElement pMarkerElement;  pMarkerElement = new MarkerElementClass();  IElement pElement;  pElement = pMarkerElement as IElement;  pElement.Geometry = pt;  pGraphicsContainer = pMap as IGraphicsContainer;  pGraphicsContainer.AddElement((IElement)pMarkerElement, 0);  pActiveView.Refresh();

 

线编辑:

1
2
3
4
5
6
7
8
9
10
IGeometry polyline; 
polyline = axMapControl1.TrackLine(); 
ILineElement pLineElement; 
pLineElement = 
new 
LineElementClass(); 
IElement pElement; 
pElement = pLineElement 
as 
IElement; 
pElement.Geometry = polyline; 
pGraphicsContainer = pMap 
as 
IGraphicsContainer; 
pGraphicsContainer.AddElement((IElement)pLineElement, 0); 
pActiveView.Refresh(); 

 

 面编辑:

1
2
3
4
5
6
7
8
9
10
IGeometry Polygon; 
Polygon = axMapControl1.TrackPolygon(); 
IPolygonElement PolygonElement; 
PolygonElement = 
new 
PolygonElementClass(); 
IElement pElement; 
pElement = PolygonElement 
as 
IElement; 
pElement.Geometry = Polygon; 
pGraphicsContainer = pMap 
as 
IGraphicsContainer; 
pGraphicsContainer.AddElement((IElement)PolygonElement, 0); 
pActiveView.Refresh(); 

 

 

 

ArcEngine中画shape点的另一种方法

public override void OnMouseDown(int Button, int Shift, int X, int Y)  {           //base.OnMouseDown(Button, Shift, X, Y);      IFeatureLayer pFeatureLayer = mapControl.Map.get_Layer(0) as IFeatureLayer;      IFeatureClass fc = pFeatureLayer.FeatureClass;      IFeatureClassWrite fr = fc as IFeatureClassWrite;      IWorkspaceEdit pWorkspaceEdit = (fc as IDataset).Workspace as IWorkspaceEdit;            IFeature pFeature;      IPoint pPoint;      //开始事物操作      pWorkspaceEdit.StartEditing(false);            //开始编辑      pWorkspaceEdit.StartEditOperation();            pFeature = fc.CreateFeature();      pPoint = new PointClass();      IPoint Mp = mapControl.ToMapPoint(X, Y);      pPoint.PutCoords(Mp.X, Mp.Y);      pPoint.SpatialReference = mapControl.SpatialReference;      pFeature.Shape = pPoint;      pFeature.Store();      mapControl.ActiveView.Refresh();      if (Button == 2)      {          pWorkspaceEdit.StopEditOperation();          pWorkspaceEdit.StopEditing(true);      }  }

3、绘制Element、Symbol 在控件上

做符号预览的时候需要将ISymbol或IElement绘制到指定的控件上,下面边码边说,一起讨论讨论:

3.1 绘制在Panel上

ISymbol接口有Draw函数,查询其接口可以发现,我们需要执行ISymbol.SetupDC -> ISymbol.Draw -> ISymbol.ResetDC 这三个步骤;

首先SetupDC需要参数 hDC和IDisplayTransformation;贴代码:

例如:绘制在Panel上:

int width=Panel.Width;int heigth=Panel.Heigth;//绘制方法Graphics graph=Graphics.FromHwnd(Panel.Handle);graph.Clear(Panel.BackColor);//分辨率double dpi=graph.DpiX;IEnvelope pEnve=new EnvelopeClass();pEnve.PutCoords(0,0,width,heigth);Ipoint pCenterPt=new PointClass;pCenter.PutCoords(width/2,height/2); tagRECT myRect=new tagRECT();设置MyRect 的 top=0;bottom=heigh; left=0,right=width;IDisplayransformation pDisTrans=new  DisplayTrabsformation();pDisTrans.VisiableBounds=pEnve;pDisTrans.Bounds=pEnv;pDisTrans.Set_DeviceFrame(ref myRect);pDisTrans.Resolution=dpi; intPtr hdc=graph.GetHdc();ISymbol.SetupDC(hec.ToInt32,pDisTrans);ISymbol.Draw(pCenterPt);ISymbol.ResetDC(); //绘制完成后 是否绘图对象 graph.ReleaseHdc(hdc);graph.Dispose();

Symbol的第二种方法

IStyleGalleryItem item=new ServerStyleGalleryItemClass();

item.Item=youSymbol;//你需要预览的ISymbol

stdole.IPictureDisp pic=axSymbologyControl1.GetStyleClass(esriSymbologyStyleClass).PriviewItem(item,100,100);

Image img=Image.FormHbitmap(new IntPtr(pic.Handle));

picPriview.Image=img;

 

3.2 绘制Element 在Panel控件上

其中 graph、pCenterPoint、pDisTrans 的设置方式和上面一样

以绘制线段为例:

IDisplay pDisplay=new SimpleDisplay();

pDisplay.StartDrawing(graph.GetHdc(),ToInt32(),(short)esriScreeCache.esriNoScreeCache);

pDisplay.DisplayTransformation=pDisTrans;

pDisplay.SetSymbol(LineSymbol);//设置绘制线段的符号

pDisplay.DrawPolyline(IGeometry) ;//设置绘制线段的几何数据

 

//在arcgis帮助中找吧

 

 

参考文章

 

 

 

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。
    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/8145435.html,如需转载请自行联系原作者

转载地址:https://blog.csdn.net/weixin_34194702/article/details/90096233 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:左右逢源:策略模式
下一篇:Fms3中client端与server端交互方式汇总

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年03月02日 01时25分10秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

linux磁盘的命令是,linux磁盘相关的命令 2019-04-21
linux服务器 缓存,Linux服务器内存使用分析及内存缓存 2019-04-21
linux查进程内存问题,关于linux 查看服务进程内存,cpu,内存占用的一些基础命令... 2019-04-21
linux英文包安装教程视频,Linux源码包安装过程讲解 2019-04-21
linux 关闭rsync服务器,linux下配置rsync服务器和实时同步 2019-04-21
linux初始化TCP服务失败,深入Linux系统追踪TCP初始化 2019-04-21
arch Linux添加源,在Arch Linux系统中使用Archlinuxcn源(清华源)的方法 2019-04-21
私人linux远程连接,Linux远程连接 - osc_5g1gl9wp的个人空间 - OSCHINA - 中文开源技术交流社区... 2019-04-21
windows文件迁移到linux,从Windows到Linux迁移之文件服务器(Samba和AD完美结合) 2019-04-21
linux下vi编辑器的命令大全,linux下VI编辑器命令大全(超级完整版) 2019-04-21
linux结构体数组的定义数组,task_struct结构体中的run_list和array域 2019-04-21
C语言极坐标转直角坐标,C语言实现直角坐标转换为极坐标的方法 2019-04-21
16F877A和24C02通信汇编语言,PIC16f877A读写24c02程序 2019-04-21
用c语言编写小于n的所有素数,关于求N以内素数的一点小问题(N小于一亿) 2019-04-21
华为100万部鸿蒙,2019年Q4发布 华为100万部鸿蒙OS手机已开测 2019-04-21
android+大富翁+局域网,【图片】大富翁6局域网(LAN)多人联机教程(求精)_大富翁吧_百度贴吧... 2019-04-21
rn webview加载本地静态html,React Native - Webview 加载本地文件 2019-04-21
vscode 不能使用中文输入法_vscode中vim插件设置 2019-04-21
fi sap 凭证冲销 稅_SAP中的成本要素 2019-04-21
kangle主机怎么配置MySQL_kangle web服务+easypanel主机控制面板快速搭建网站和数据库以及管理空间详细教程... 2019-04-21