|
|
|
|
using ESRI.ArcGIS.Carto;
|
|
|
|
|
using ESRI.ArcGIS.Display;
|
|
|
|
|
using ESRI.ArcGIS.Geodatabase;
|
|
|
|
|
using ESRI.ArcGIS.Geometry;
|
|
|
|
|
using stdole;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|