You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							215 lines
						
					
					
						
							8.1 KiB
						
					
					
				
			
		
		
	
	
							215 lines
						
					
					
						
							8.1 KiB
						
					
					
				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<string, List<IFeature>> GetSelectedFeaturesDic(IMap map, esriGeometryType geoType = esriGeometryType.esriGeometryAny) | 
						|
        { | 
						|
            if (map == null) | 
						|
            { | 
						|
                return null; | 
						|
            } | 
						|
            IEnumFeature enumFeature = map.FeatureSelection as IEnumFeature; | 
						|
            if (enumFeature == null) | 
						|
            { | 
						|
                return null; | 
						|
            } | 
						|
            Dictionary<string, List<IFeature>> geoList = new Dictionary<string, List<IFeature>>(); | 
						|
            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<IFeature>() { feart }); | 
						|
                        } | 
						|
                    } | 
						|
                } | 
						|
                feart = enumFeature.Next(); | 
						|
            } | 
						|
            return geoList; | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 创建点元素 | 
						|
        /// </summary> | 
						|
        /// <param name="pGeometry">点几何图形</param> | 
						|
        /// <returns>返回点元素</returns> | 
						|
        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; | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 创建线元素 | 
						|
        /// </summary> | 
						|
        /// <param name="pGeometry">线几何图形</param> | 
						|
        /// <returns>线元素</returns> | 
						|
        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; | 
						|
        } | 
						|
        /// <summary> | 
						|
        /// 创建面元素 | 
						|
        /// </summary> | 
						|
        /// <param name="pGeometry">面几何对象</param> | 
						|
        /// <returns>面元素</returns> | 
						|
        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; | 
						|
        } | 
						|
 | 
						|
        /// <summary> | 
						|
        /// 获取图形的所有点 | 
						|
        /// </summary> | 
						|
        /// <param name="geometry"></param> | 
						|
        /// <returns></returns> | 
						|
        public static Dictionary<int, IPoint> GetAllPoints(IGeometry geometry) | 
						|
        { | 
						|
            Dictionary<int, IPoint> dicOPnts = new Dictionary<int, IPoint>();//保存面的点坐标 | 
						|
            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<IPoint> GetMultipleRingPoints(IGeometry geometry) | 
						|
        { | 
						|
            List<IPoint> dicOPnts = new List<IPoint>(); | 
						|
            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; | 
						|
        } | 
						|
 | 
						|
    } | 
						|
}
 | 
						|
 |