1、Arcgis 功能类代码目录:1. 打点,Element类 22. 清除所有元素,Element类 33. 画线,Element类 34. 根据传入的点集画面,Element类,目前没有实现 45. 在图层上添加点,feature类 56. 显示当前选中图元属性,feature类 67. 删除当前选中图元,feature类 78. 查询图元并闪烁,feature类 89. 得到符号 910. 渲染图元,feature类 1011. 获取图片element,element类 1112. element旋转,element类 1213. 加载SHP文件 1214. 判断图形B是否包含在图形A中,f
2、eature类 1315. 获得点 1416. element沿线移动,element类 1517. 元素移动,element类 15Arcgis 功能类代码using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.SystemUI;using ESRI.ArcGIS.Display;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.Geometry;using ESRI.ArcGIS.DataSourcesFi
3、le;/Arcgis 功能代码 / 1.打点,Element类 / / 点的X坐标 / 点的Y坐标 private void DrawPoint(double x, double y) IActiveView activeView = this.axMapControl1.ActiveView.FocusMap as IActiveView; IElement pElement; IPoint pt = new PointClass(); pt.PutCoords(x, y); /设置点颜色 IRgbColor pColor = new RgbColorClass(); pColor.Red
4、= 255; /设置点的样式 ISimpleMarkerSymbol pSMS = new SimpleMarkerSymbolClass(); pSMS.Size = 9; pSMS.Color = pColor; pSMS.Style = esriSimpleMarkerStyle.esriSMSCircle; IMarkerElement pME = new MarkerElementClass(); pME.Symbol = pSMS; pElement = pME as IElement; pElement.Geometry = pt; activeView.GraphicsCont
5、ainer.AddElement(pElement, 0); activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); / 2.清除所有元素,Element类 / private void DeleteAllElements() IActiveView activeView = this.axMapControl1.ActiveView.FocusMap as IActiveView; activeView.GraphicsContainer.DeleteAllElements(); activeVie
6、w.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); / 3.画线,Element类 / / 点集 / 点集点的数目 private void DrawLine(double, pointArray, int arrayCount) if (arrayCount = 0) return; /点坐标数组不能为空 IActiveView activeView = this.axMapControl1.ActiveView.FocusMap as IActiveView; /设置颜色 IRgbColor color =
7、new RgbColorClass(); color.Red = 255; color.Blue = 255; color.Transparency = 255; /线样式 ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = color; lineSymbol.Style = esriSimpleLineStyle.esriSLSInsideFrame; lineSymbol.Width = 1; /点对象 IPoint pPoint = new PointClass(); /线元素 IL
8、ineElement lineElement = new LineElementClass(); lineElement.Symbol = lineSymbol; /线对象 IPolyline m_Polyline = new PolylineClass(); /点集合对象 IPointCollection m_PointCollection = new PolylineClass(); object missing = Type.Missing; for (int i = 0; i arrayCount; i+) pPoint.PutCoords(pointArrayi, 0, pointA
9、rrayi, 1); m_PointCollection.AddPoint(pPoint, ref missing, ref missing); m_Polyline = m_PointCollection as IPolyline; IElement element = lineElement as IElement; element.Geometry = m_Polyline; activeView.GraphicsContainer.AddElement(element, 0); activeView.PartialRefresh(esriViewDrawPhase.esriViewGr
10、aphics, null, null); / 4.根据传入的点集画面,Element类,目前没有实现 / / / private void DrawPolygon(double, pointArray, int arrayCount) ILayer pLayer = this.axMapControl1.get_Layer(0); IFeatureLayer pFLayer = pLayer as IFeatureLayer; IFeatureClass pFC = pFLayer.FeatureClass; /点对象 IPoint pPoint = new PointClass(); /点集
11、合对象 IPointCollection m_PointCollection = new PolylineClass(); object missing = Type.Missing; for (int i = 0; i arrayCount; i+) pPoint.PutCoords(pointArrayi, 0, pointArrayi, 1); m_PointCollection.AddPoint(pPoint, ref missing, ref missing); /由于要画面,所以polygon的最后一个点和第一个点是同一个点,因此代码多余用到图元复制,也可以把第一个点再添加一遍就可
12、以了 /把第一个点再添加一遍,此代码节俭,用这个 pPoint.PutCoords(pointArray0, 0, pointArray0, 1); m_PointCollection.AddPoint(pPoint, ref missing, ref missing); /下面这个用图元复制,不节俭,所以注释起来留待以后参考 /IClone pClone = m_PointCollection.get_Point(0) as IClone; /IPoint pEndPoint = pClone.Clone() as IPoint; /m_PointCollection.AddPoint(pE
13、ndPoint, ref missing, ref missing); IWorkspaceEdit pWE = (pFC as IDataset).Workspace as IWorkspaceEdit; pWE.StartEditing(false); pWE.StartEditOperation(); IFeature pFeature = pFC.CreateFeature(); pFeature.Shape = m_PointCollection as IPolygon; pFeature.Store(); pFeature.set_Value(pFeature.Fields.Fin
14、dField(类型), 新加图元); pFeature.Store(); pFeature.set_Value(pFeature.Fields.FindField(面积), 130); pFeature.Store(); pWE.StopEditOperation(); pWE.StopEditing(true); this.axMapControl1.ActiveView.Refresh(); / 5. 在图层上添加点,feature类 / / X坐标 / Y坐标 private void AddPointOnLayer(double x, double y) /得到要添加地物的图层 IFe
15、atureLayer iFeatureL = this.axMapControl1.Map.get_Layer(1) as IFeatureLayer; /定义一个地物类,把要编辑的图层转化为定义的地物类 IFeatureClass iFeatureC = iFeatureL.FeatureClass; /先定义一个编辑的工作空间,然后转化为数据集,最后转化为编辑工作空间 IWorkspaceEdit w = (iFeatureC as IDataset).Workspace as IWorkspaceEdit; IFeature pFeature; IPoint pPoint; /开始事务操
16、作 w.StartEditing(true); /开始编辑 w.StartEditOperation(); /创建一个地物 pFeature = iFeatureC.CreateFeature(); pPoint = new PointClass(); /设置点的坐标 pPoint.PutCoords(x, y); /确定图形类型 pFeature.Shape = pPoint; /保存地物 pFeature.Store(); pFeature.set_Value(pFeature.Fields.FindField(类别), Circle 2); pFeature.Store(); /结束编辑
17、 w.StopEditOperation(); /结束事务操作 w.StopEditing(true); this.axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, iFeatureL, null); / 6. 显示当前选中图元属性,feature类 / private void showAttri() string str = ; /获取图层 IQueryFilter pQueryFilter = new QueryFilterClass(); IFeatureLayer pFeature
18、Layer = this.axMapControl1.get_Layer(1) as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; int indexOfName = pFeatureClass.FindField(类别); IFeature pFeature; IMap pMap = this.axMapControl1.Map; ISelection pSelection = pMap.FeatureSelection; IEnumFeature pEnumFeature = pSelect
19、ion as IEnumFeature; pEnumFeature.Reset(); pFeature = pEnumFeature.Next(); if (pFeature = null) MessageBox.Show(未选中图元,请重新选择); else while (pFeature != null) pQueryFilter.WhereClause = FID=+pFeature.get_Value(0).ToString(); IFeatureCursor pFeatureCursor = pFeatureLayer.Search(pQueryFilter, true); IFea
20、ture xxfeature; xxfeature = pFeatureCursor.NextFeature(); str = str + 类别:+xxfeature.get_Value(indexOfName).ToString() + n; pFeature = pEnumFeature.Next(); MessageBox.Show(str); / 7.删除当前选中图元,feature类 / private void deleteFeature() IFeature pFeature; IFeatureLayer iFeatureL = this.axMapControl1.get_La
21、yer(1) as IFeatureLayer; IFeatureClass iFeatureC = iFeatureL.FeatureClass; IWorkspaceEdit iWorkspaceE = (iFeatureC as IDataset).Workspace as IWorkspaceEdit; iWorkspaceE.StartEditing(true); iWorkspaceE.StartEditOperation(); IMap pMap = this.axMapControl1.Map; IEnumFeature pEnumFeature = pMap.FeatureS
22、election as IEnumFeature; pEnumFeature.Reset(); pFeature = pEnumFeature.Next(); try if (pFeature != null) while (pFeature != null) DialogResult pDialogR = MessageBox.Show(确实要删除FID= + pFeature.get_Value(0).ToString() + 的图元吗?, 提示:, MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (pDialogR = D
23、ialogResult.Yes) pFeature.Delete(); MessageBox.Show(删除成功!); pFeature = pEnumFeature.Next(); catch (Exception err) MessageBox.Show(err.Message); iWorkspaceE.StopEditOperation(); iWorkspaceE.StopEditing(true); this.axMapControl1.ActiveView.Refresh(); / 8.查询图元并闪烁,feature类 / / 查询条件 private void FindFeat
24、ureAndShape(string sqlFilter) this.axMapControl1.Map.ClearSelection(); this.axMapControl1.ActiveView.Refresh(); IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = sqlFilter; IFeatureLayer pFeatureLayer = this.axMapControl1.get_Layer(1) as IFeatureLayer; IFeatureCursor pFe
25、atureCursor = pFeatureLayer.Search(pQueryFilter, true); IFeature pFeature; pFeature = pFeatureCursor.NextFeature(); if (pFeature = null) MessageBox.Show(未找到图元!); return; ISimpleMarkerSymbol iSimpleMarker = new SimpleMarkerSymbolClass(); iSimpleMarker.Style = esriSimpleMarkerStyle.esriSMSCircle; iSim
26、pleMarker.Size = 12; this.axMapControl1.Map.SelectFeature(pFeatureLayer, pFeature); this.axMapControl1.FlashShape(pFeature.Shape as IGeometry, 5, 300, iSimpleMarker); this.axMapControl1.Map.ClearSelection(); /this.axMapControl1.ActiveView.Refresh(); / 9. 得到符号 / / 符号路径 / 符号类型 / 符号名称 / 返回指定符号 private
27、ISymbol GetSymbol(string sServerStylePath, string sGalleryClassName, string symbolName) try IStyleGallery pStyleGaller = new ServerStyleGalleryClass(); IStyleGalleryStorage pStyleGalleryStorage = pStyleGaller as IStyleGalleryStorage; IEnumStyleGalleryItem pEnumSyleGalleryItem = null; IStyleGalleryIt
28、em pStyleGallerItem = null; IStyleGalleryClass pStyleGalleryClass = null; pStyleGalleryStorage.AddFile(sServerStylePath); for (int i = 0; i pStyleGaller.ClassCount; i+) pStyleGalleryClass = pStyleGaller.get_Class(i); if (pStyleGalleryClass.Name != sGalleryClassName) continue; pEnumSyleGalleryItem = pStyleGaller.get_Items(sGalleryClassName, sServerStylePath,
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1