using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using KGIS.Framework.AE; using KGIS.Framework.Utils; using stdole; using System.Collections.Generic; using System.Linq; namespace Kingo.PluginServiceInterface.Helper { public class LayerHelper { public static Dictionary> GetSelectedFeaturesDic(IMap map, esriGeometryType geoType = esriGeometryType.esriGeometryAny) { if (map == null) { return null; } IEnumFeature enumFeature = map.FeatureSelection as IEnumFeature; if (enumFeature == null) { return null; } Dictionary> geoList = new Dictionary>(); IFeature feart = enumFeature.Next(); while (feart != null) { if (feart.Shape != null && !feart.Shape.IsEmpty && (geoType == esriGeometryType.esriGeometryAny || feart.Shape.GeometryType == geoType)) { IDataset dataset = feart.Table as IDataset; if (dataset != null) { if (geoList.ContainsKey(dataset.BrowseName)) { geoList[dataset.BrowseName].Add(feart); } else { geoList.Add(dataset.BrowseName, new List() { feart }); } } } feart = enumFeature.Next(); } return geoList; } /// /// 创建点元素 /// /// 点几何图形 /// 返回点元素 public static IElement PointElement(IGeometry pGeometry) { IElement pElement = new MarkerElementClass(); IMarkerElement pMarkerElement = (IMarkerElement)pElement; ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pSimpleMarkerSymbol.Color = pRgbColor; pSimpleMarkerSymbol.Size = 10; pMarkerElement.Symbol = pSimpleMarkerSymbol; pElement.Geometry = pGeometry; return pElement; } /// /// 创建线元素 /// /// 线几何图形 /// 线元素 public static IElement PolylineElement(IGeometry pGeometry) { IElement pElement = new LineElementClass(); ILineElement pLineElement = (ILineElement)pElement; ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 0; pRgbColor.Green = 0; pRgbColor.Blue = 0; pSimpleLineSymbol.Color = pRgbColor; pSimpleLineSymbol.Width = 5; pLineElement.Symbol = pSimpleLineSymbol; pElement.Geometry = pGeometry; return pElement; } /// /// 创建面元素 /// /// 面几何对象 /// 面元素 public static IElement PolygonElement(IGeometry pGeometry) { IElement pElement = new PolygonElementClass(); //填充符号设置 ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); //填充符号的边框设置 ILineSymbol pLineSymbol = new SimpleLineSymbolClass(); IRgbColor pRgbColol = new RgbColorClass(); pRgbColol.Red = 0; pRgbColol.Green = 0; pRgbColol.Blue = 110; pLineSymbol.Color = pRgbColol; pLineSymbol.Width = 1; pSimpleFillSymbol.Outline = pLineSymbol; //填充符号颜色 pRgbColol = new RgbColorClass(); pRgbColol.Red = 229; pRgbColol.Green = 103; pRgbColol.Blue = 102; pSimpleFillSymbol.Color = pRgbColol; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSCross; //.esriSFSBackwardDiagonal; //面元素设置 IFillShapeElement pFillShapeElement = (IFillShapeElement)pElement; pFillShapeElement.Symbol = pSimpleFillSymbol; pElement.Geometry = pGeometry; return pElement; } public static IElement TextElement(IGeometry pGeometry, string textLabel) { IRgbColor pColor = new RgbColorClass() { Red = 0, Blue = 255, Green = 0 }; IFontDisp pFont = new StdFont() { Name = "宋体", Size = 12 } as IFontDisp; ITextSymbol pTextSymbol = new TextSymbolClass() { Color = pColor, Font = pFont, Size = 12 }; IGeometry geometry = pGeometry; switch (geometry.GeometryType) { case esriGeometryType.esriGeometryPolygon: geometry = (pGeometry as IArea).Centroid; break; } IElement pTextElment = new TextElementClass() { Symbol = pTextSymbol, ScaleText = true, Text = textLabel, Geometry = geometry }; return pTextElment; } /// /// 获取图形的所有点 /// /// /// public static Dictionary GetAllPoints(IGeometry geometry) { Dictionary dicOPnts = new Dictionary();//保存面的点坐标 if (geometry == null) return dicOPnts; IPointCollection iPntCollection = geometry as IPointCollection; if (iPntCollection == null || iPntCollection.PointCount <= 0) return dicOPnts; for (int i = 0; i < iPntCollection.PointCount - 1; i++) { dicOPnts.Add(i, iPntCollection.Point[i]); } return dicOPnts; } public static List GetMultipleRingPoints(IGeometry geometry) { List dicOPnts = new List(); try { if (geometry == null) return dicOPnts; IGeometryCollection geometryCollection = geometry as IGeometryCollection; IRing ring = null; if (geometryCollection == null) { IPointCollection iPntCollection = geometry as IPointCollection; if (iPntCollection == null || iPntCollection.PointCount <= 0) return dicOPnts; for (int j = 0; j < iPntCollection.PointCount - 1; j++) { dicOPnts.Add(iPntCollection.Point[j]); } } else { for (int i = 0; i < geometryCollection.GeometryCount; i++) { ring = geometryCollection.get_Geometry(i) as IRing; IPointCollection iPntCollection = ring as IPointCollection; if (iPntCollection == null || iPntCollection.PointCount <= 0) return dicOPnts; for (int j = 0; j < iPntCollection.PointCount - 1; j++) { dicOPnts.Add(iPntCollection.Point[j]); } } } } catch (System.Exception ex) { LogAPI.Debug($"{ex.Message + ex.StackTrace}"); } return dicOPnts; } } }