ArcGIS Engine 中的绘制与编辑

简介:

 

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帮助中找吧

 

 

参考文章

ArcGIS Engine 线段绘制研究

ArcEngine画shapefile点,线,面

ArcEngine中画shape点的另一种方法

Arcengine 绘制Element、Symbol 在控件上

 

 

 

没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。


    本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/8145435.html,如需转载请自行联系原作者


相关文章
|
4月前
|
人工智能 编解码 定位技术
ArcGIS导出AI或EPS格式的地图图片并在Adobe Illustrator中继续编辑
ArcGIS导出AI或EPS格式的地图图片并在Adobe Illustrator中继续编辑
|
4月前
|
定位技术
ArcGIS中各版本ArcMap安装OpenStreetMap编辑工具集插件ArcGIS Editor for OSM
ArcGIS中各版本ArcMap安装OpenStreetMap编辑工具集插件ArcGIS Editor for OSM
|
9月前
|
存储 C语言
ArcGIS:Excel/Txt 文件生成点图层、属性表编辑的基本方法、属性表之间的连接(合并)和关联的操作、属性表的字段计算器的使用
ArcGIS:Excel/Txt 文件生成点图层、属性表编辑的基本方法、属性表之间的连接(合并)和关联的操作、属性表的字段计算器的使用
177 0
|
9月前
|
定位技术
ArcGIS:如何对Shapefile文件进行符号系统修改、标注、合并、分割、拓扑编辑等?
ArcGIS:如何对Shapefile文件进行符号系统修改、标注、合并、分割、拓扑编辑等?
237 0
|
9月前
|
定位技术 索引
ArcGIS数据编辑1 新要素的创建
🏆在本文中,作者讲解了ArcGIS要素创建了全流程,从面要素到线要素,分别以不同的方法补全了道路的缺失部分
157 0
|
9月前
|
SQL 开发框架 数据可视化
ArcGIS Engine学习系列1 AE基础介绍
市面上AE教程大致到ArcGIS10.2,ESRI宣布从ArcGIS10.5开始便停止AE的更新,使用AO做开发,初学者可以在学习C#语言后,从AE入门,逐渐过度到AO。不同版本下AE数据类型数量Enums:枚举类型,用于实现一些定义的内容Structs:结构体Interfaces:接口Classes:类AE开发中,为了更好地管理COM对象,ESRI将这些COM对象放到不同的组件库中。
200 0
|
Web App开发 JavaScript 前端开发
|
定位技术
ArcGIS Engine中的Symbols详解
本文由本人翻译ESRI官方帮助文档。尊重劳动成果,转载请注明来源。 Symbols     ArcObjects用了三种类型的Symbol(符号样式)来绘制图形特征:marker symbols(标记符号),line symbols(线符号),和fill symbols(填充符号)。
832 0
|
定位技术 C# C++
VC2010+ArcGIS Engine 10.1 开发(一)
                      使用MFC(VS2010)开发ArcGIS Engine 10.1 网上C#结合ArcGIS Engine的资料简直太多了,多的都无法形容,但是C++的却很少,前一段时间不断的有人问在VC中如何开发ArcGI...
1085 0
|
C# 定位技术
VC2010+ArcGIS Engine 10.1 开发(二)
采用ActiveX控件插入的方式 上面我们是通过代码直接将地图控件放到界面上,这种有一个不好的地方就是,如果我们要设置控件的一些样式和视觉效果,我们要自己写很多代码,在C#中我们就很容易,其实在VC中也可以采用这种方式,下来我介绍下: 插入控件 在Vi...
824 0