基本步骤
构建形状
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
点编辑:
<a></a>
线编辑:
1
2
3
4
5
6
7
8
9
10
<code>IGeometry polyline; </code>
<code>polyline = axMapControl1.TrackLine(); </code>
<code>ILineElement pLineElement; </code>
<code>pLineElement = </code><code>new</code> <code>LineElementClass(); </code>
<code>IElement pElement; </code>
<code>pElement = pLineElement </code><code>as</code> <code>IElement; </code>
<code>pElement.Geometry = polyline; </code>
<code>pGraphicsContainer = pMap </code><code>as</code> <code>IGraphicsContainer; </code>
<code>pGraphicsContainer.AddElement((IElement)pLineElement, 0); </code>
<code>pActiveView.Refresh(); </code>
面编辑:
<code>IGeometry Polygon; </code>
<code>Polygon = axMapControl1.TrackPolygon(); </code>
<code>IPolygonElement PolygonElement; </code>
<code>PolygonElement = </code><code>new</code> <code>PolygonElementClass(); </code>
<code>pElement = PolygonElement </code><code>as</code> <code>IElement; </code>
<code>pElement.Geometry = Polygon; </code>
<code>pGraphicsContainer.AddElement((IElement)PolygonElement, 0); </code>
ArcEngine中画shape点的另一种方法
做符号预览的时候需要将ISymbol或IElement绘制到指定的控件上,下面边码边说,一起讨论讨论:
ISymbol接口有Draw函数,查询其接口可以发现,我们需要执行ISymbol.SetupDC -> ISymbol.Draw -> ISymbol.ResetDC 这三个步骤;
首先SetupDC需要参数 hDC和IDisplayTransformation;贴代码:
例如:绘制在Panel上:
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;
其中 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帮助中找吧
<a href="http://blog.csdn.net/lab2013/article/details/6890474" target="_blank">ArcGIS Engine 线段绘制研究</a>
<a href="http://blog.csdn.net/scarlett_ohara/article/details/51159162">ArcEngine画shapefile点,线,面</a>
<a href="http://blog.csdn.net/scarlett_ohara/article/details/51163573">ArcEngine中画shape点的另一种方法</a>
<a href="http://blog.csdn.net/wangtao510/article/details/48675681" target="_blank">Arcengine 绘制Element、Symbol 在控件上</a>
没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。
本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/8145435.html,如需转载请自行联系原作者