|
|
|
|
|
|
|
|
|
using ESRI.ArcGIS.Carto;
|
|
|
|
|
using ESRI.ArcGIS.Display;
|
|
|
|
|
using ESRI.ArcGIS.esriSystem;
|
|
|
|
|
using ESRI.ArcGIS.Geodatabase;
|
|
|
|
|
using ESRI.ArcGIS.Geometry;
|
|
|
|
|
using KGIS.Plugin.LayerProperty.Enum;
|
|
|
|
|
using KGIS.Plugin.LayerProperty.Interface;
|
|
|
|
|
using KGIS.Plugin.LayerProperty.View;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace KGIS.Plugin.LayerProperty.Utils
|
|
|
|
|
{
|
|
|
|
|
internal class RenderUtil
|
|
|
|
|
{
|
|
|
|
|
public delegate void LayerRenderDescriptionDelegate(string desc);
|
|
|
|
|
private const string CONST_SYMBOL = "F_Symbol";
|
|
|
|
|
private const string CONST_VALUE = "F_Value";
|
|
|
|
|
private const string CONST_LABEL = "F_Label";
|
|
|
|
|
private const string CONST_BITMAP = "F_BITMAP";
|
|
|
|
|
private static FormSymbolSelector frmSymbolSelector;
|
|
|
|
|
private static IUIPlugIn symbolSelector;
|
|
|
|
|
private static FormGalleryPathSelector frmGalleryPathSelector;
|
|
|
|
|
private static KGIS.Framework.Utils.Dialog.OpenFileDialog openFileDialog;
|
|
|
|
|
public static event RenderUtil.LayerRenderDescriptionDelegate LayerRenderDescription;
|
|
|
|
|
internal static IDoStyleGalleryItem OpenStyleSelector(esriGeometryType GeometryType)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (RenderUtil.frmSymbolSelector == null)
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.frmSymbolSelector = new FormSymbolSelector();
|
|
|
|
|
RenderUtil.symbolSelector = RenderUtil.frmSymbolSelector;
|
|
|
|
|
//RenderUtil.symbolSelector.RDBHelper = RdbUtil.RDBHelper;
|
|
|
|
|
//RenderUtil.symbolSelector.TraceHandler = Util.TraceHandler;
|
|
|
|
|
//RenderUtil.symbolSelector.Log = Util.Log;
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init();
|
|
|
|
|
}
|
|
|
|
|
switch (GeometryType)
|
|
|
|
|
{
|
|
|
|
|
case esriGeometryType.esriGeometryPoint:
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init(esriStyleClass.MarkerSymbols);
|
|
|
|
|
break;
|
|
|
|
|
case esriGeometryType.esriGeometryPolyline:
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init(esriStyleClass.LineSymbols);
|
|
|
|
|
break;
|
|
|
|
|
case esriGeometryType.esriGeometryPolygon:
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init(esriStyleClass.FillSymbols);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (RenderUtil.frmSymbolSelector.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
return RenderUtil.frmSymbolSelector.DoStyleGalleryItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
internal static object OpenStyleSelector(esriGeometryType GeometryType, ISymbol symbol)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (RenderUtil.frmSymbolSelector == null)
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.frmSymbolSelector = new FormSymbolSelector();
|
|
|
|
|
RenderUtil.symbolSelector = RenderUtil.frmSymbolSelector;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//RenderUtil.symbolSelector.RDBHelper = RdbUtil.RDBHelper;
|
|
|
|
|
//RenderUtil.symbolSelector.TraceHandler = Util.TraceHandler;
|
|
|
|
|
//RenderUtil.symbolSelector.Log = Util.Log;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init();
|
|
|
|
|
}
|
|
|
|
|
switch (GeometryType)
|
|
|
|
|
{
|
|
|
|
|
case esriGeometryType.esriGeometryPoint:
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init(esriStyleClass.MarkerSymbols, ref symbol);
|
|
|
|
|
break;
|
|
|
|
|
case esriGeometryType.esriGeometryPolyline:
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init(esriStyleClass.LineSymbols, ref symbol);
|
|
|
|
|
break;
|
|
|
|
|
case esriGeometryType.esriGeometryPolygon:
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init(esriStyleClass.FillSymbols, ref symbol);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (RenderUtil.frmSymbolSelector.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
return RenderUtil.frmSymbolSelector.ResultSymbol;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
internal static object OpenStyleSelector(esriStyleClass styleClass, ISymbol symbol)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (RenderUtil.frmSymbolSelector == null)
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.frmSymbolSelector = new FormSymbolSelector();
|
|
|
|
|
RenderUtil.symbolSelector = RenderUtil.frmSymbolSelector;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//RenderUtil.symbolSelector.RDBHelper = RdbUtil.RDBHelper;
|
|
|
|
|
//RenderUtil.symbolSelector.TraceHandler = Util.TraceHandler;
|
|
|
|
|
//RenderUtil.symbolSelector.Log = Util.Log;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init();
|
|
|
|
|
}
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init(styleClass, ref symbol);
|
|
|
|
|
if (RenderUtil.frmSymbolSelector.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
return RenderUtil.frmSymbolSelector.ResultSymbol;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
internal static object OpenGalleryPathSelector()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (RenderUtil.frmGalleryPathSelector == null)
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.frmGalleryPathSelector = new FormGalleryPathSelector();
|
|
|
|
|
RenderUtil.symbolSelector = RenderUtil.frmGalleryPathSelector;
|
|
|
|
|
//RenderUtil.symbolSelector.RDBHelper = RdbUtil.RDBHelper;
|
|
|
|
|
//RenderUtil.symbolSelector.TraceHandler = Util.TraceHandler;
|
|
|
|
|
//RenderUtil.symbolSelector.Log = Util.Log;
|
|
|
|
|
RenderUtil.frmGalleryPathSelector.Init();
|
|
|
|
|
}
|
|
|
|
|
if (RenderUtil.frmGalleryPathSelector.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
if (frmGalleryPathSelector.UpdateTextName != null)
|
|
|
|
|
{
|
|
|
|
|
frmGalleryPathSelector.SelectedPath = frmGalleryPathSelector.UpdateTextName;
|
|
|
|
|
}
|
|
|
|
|
return RenderUtil.frmGalleryPathSelector.SelectedPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
internal static IDoStyleGalleryItem OpenStyleSelector(esriStyleClass styleClass)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (RenderUtil.frmSymbolSelector == null)
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.frmSymbolSelector = new FormSymbolSelector();
|
|
|
|
|
RenderUtil.symbolSelector = RenderUtil.frmSymbolSelector;
|
|
|
|
|
//RenderUtil.symbolSelector.RDBHelper = RdbUtil.RDBHelper;
|
|
|
|
|
//RenderUtil.symbolSelector.TraceHandler = Util.TraceHandler;
|
|
|
|
|
//RenderUtil.symbolSelector.Log = Util.Log;
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init();
|
|
|
|
|
}
|
|
|
|
|
RenderUtil.frmSymbolSelector.Init(styleClass);
|
|
|
|
|
if (RenderUtil.frmSymbolSelector.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
return RenderUtil.frmSymbolSelector.DoStyleGalleryItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
internal static Bitmap GetSymbolBitMap(int width, int height, IStyleGalleryClass symbologyStyleClass, ISymbol pSymbol)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Bitmap result;
|
|
|
|
|
if (pSymbol == null || symbologyStyleClass == null)
|
|
|
|
|
{
|
|
|
|
|
result = null;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
result = StyleGalleryItemView.StyleGalleryItemToBmp(width, height, symbologyStyleClass, new ServerStyleGalleryItemClass
|
|
|
|
|
{
|
|
|
|
|
Item = pSymbol
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
internal static Hashtable GetAllSymbols(string path, string className)
|
|
|
|
|
{
|
|
|
|
|
IStyleGallery styleGallery = new ServerStyleGalleryClass();
|
|
|
|
|
Hashtable hashtable = new Hashtable();
|
|
|
|
|
IStyleGalleryStorage styleGalleryStorage = styleGallery as IStyleGalleryStorage;
|
|
|
|
|
styleGalleryStorage.AddFile(path);
|
|
|
|
|
IEnumStyleGalleryItem enumStyleGalleryItem = styleGallery.get_Items(className, path, null);
|
|
|
|
|
enumStyleGalleryItem.Reset();
|
|
|
|
|
for (IStyleGalleryItem styleGalleryItem = enumStyleGalleryItem.Next(); styleGalleryItem != null; styleGalleryItem = enumStyleGalleryItem.Next())
|
|
|
|
|
{
|
|
|
|
|
object item = styleGalleryItem.Item;
|
|
|
|
|
if (item is ISymbol)
|
|
|
|
|
{
|
|
|
|
|
ISymbol value = item as ISymbol;
|
|
|
|
|
string name = styleGalleryItem.Name;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
hashtable.Add(name, value);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return hashtable;
|
|
|
|
|
}
|
|
|
|
|
internal static Hashtable GetAllSymbols(IDoStyleGalleryPath path, string className)
|
|
|
|
|
{
|
|
|
|
|
Hashtable hashtable = new Hashtable();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
IDoStyleGallery doStyleGallery = StyleGalleryFactory.CreateDistStyleGallery();
|
|
|
|
|
IDoStyleGalleryStorage doStyleGalleryStorage = doStyleGallery as IDoStyleGalleryStorage;
|
|
|
|
|
doStyleGalleryStorage.AddDoStyleGalleryPath(path);
|
|
|
|
|
List<IDoStyleGalleryItem> list = doStyleGallery.get_Items(className, path, "");
|
|
|
|
|
foreach (IDoStyleGalleryItem current in list)
|
|
|
|
|
{
|
|
|
|
|
object item = current.Item.Item;
|
|
|
|
|
if (item is ISymbol)
|
|
|
|
|
{
|
|
|
|
|
ISymbol value = item as ISymbol;
|
|
|
|
|
string name = current.Name;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
hashtable.Add(name, value);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
return hashtable;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取匹配的符号集
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path"></param>
|
|
|
|
|
/// <param name="className"></param>
|
|
|
|
|
/// <returns>王欢 2018-12-13</returns>
|
|
|
|
|
internal static Hashtable GetAllSymbols_NEW(string path, string className)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//ServerStyleGallery对象
|
|
|
|
|
Hashtable hashtable = new Hashtable();
|
|
|
|
|
IStyleGallery pStyleGaller = new ServerStyleGalleryClass();
|
|
|
|
|
|
|
|
|
|
IStyleGalleryStorage pStyleGalleryStorage = pStyleGaller as IStyleGalleryStorage;
|
|
|
|
|
IEnumStyleGalleryItem pEnumSyleGalleryItem = null;
|
|
|
|
|
|
|
|
|
|
IStyleGalleryItem pStyleGallerItem = null;
|
|
|
|
|
|
|
|
|
|
IStyleGalleryClass pStyleGalleryClass = null;
|
|
|
|
|
|
|
|
|
|
//使用IStyleGalleryStorage接口的AddFile方法加载ServerStyle文件
|
|
|
|
|
pStyleGalleryStorage.AddFile(path);
|
|
|
|
|
//遍历ServerGallery中的Class
|
|
|
|
|
for (int i = 0; i < pStyleGaller.ClassCount; i++)
|
|
|
|
|
{
|
|
|
|
|
pStyleGalleryClass = pStyleGaller.get_Class(i);
|
|
|
|
|
|
|
|
|
|
if (pStyleGalleryClass.Name != className)
|
|
|
|
|
continue;
|
|
|
|
|
//获取EnumStyleGalleryItem对象
|
|
|
|
|
pEnumSyleGalleryItem = pStyleGaller.get_Items(className, path, "");
|
|
|
|
|
pEnumSyleGalleryItem.Reset();
|
|
|
|
|
if (pEnumSyleGalleryItem == null)
|
|
|
|
|
continue;
|
|
|
|
|
//遍历pEnumSyleGalleryItem
|
|
|
|
|
pStyleGallerItem = pEnumSyleGalleryItem.Next();
|
|
|
|
|
|
|
|
|
|
while (pStyleGallerItem != null)
|
|
|
|
|
{
|
|
|
|
|
//获取符号
|
|
|
|
|
ISymbol pSymbol = pStyleGallerItem.Item as ISymbol;
|
|
|
|
|
if (pStyleGallerItem.Item is ISymbol)
|
|
|
|
|
{
|
|
|
|
|
ISymbol value = pStyleGallerItem.Item as ISymbol;
|
|
|
|
|
string name = pStyleGallerItem.Name;
|
|
|
|
|
if (!hashtable.ContainsKey(name))
|
|
|
|
|
{
|
|
|
|
|
hashtable.Add(name, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pStyleGallerItem = pEnumSyleGalleryItem.Next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumSyleGalleryItem);
|
|
|
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(pStyleGalleryClass);
|
|
|
|
|
|
|
|
|
|
return hashtable;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//KGIS.Common.Utility.LogAPI.Debug(ex);
|
|
|
|
|
RenderUtil.InvkeLayerRenderDescription("未找到符合的样式符合!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
internal static void FeatureLayerAutoMatch2(IFeatureLayer2 FeaLyr, object StylePath, string MatchField, int MaxMatchCount, out StringBuilder messages)
|
|
|
|
|
{
|
|
|
|
|
messages = new StringBuilder();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
messages.AppendLine("开始匹配:<" + (FeaLyr as ILayer).Name + "> " + DateTime.Now.ToString());
|
|
|
|
|
IGeoFeatureLayer geoFeatureLayer = FeaLyr as IGeoFeatureLayer;
|
|
|
|
|
if (geoFeatureLayer == null)
|
|
|
|
|
{
|
|
|
|
|
messages.AppendLine("不能对图层:<" + (FeaLyr as ILayer).Name + ">进行渲染。");
|
|
|
|
|
messages.AppendLine("=======================");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IUniqueValueRenderer uniqueValueRenderer = geoFeatureLayer.Renderer as IUniqueValueRenderer;
|
|
|
|
|
if (uniqueValueRenderer == null)
|
|
|
|
|
{
|
|
|
|
|
uniqueValueRenderer = new UniqueValueRendererClass();
|
|
|
|
|
}
|
|
|
|
|
ISymbol defaultSymbol = uniqueValueRenderer.DefaultSymbol;
|
|
|
|
|
if (defaultSymbol == null)
|
|
|
|
|
{
|
|
|
|
|
defaultSymbol = RenderUtil.GetDefaultSymbol(FeaLyr.FeatureClass.ShapeType);
|
|
|
|
|
}
|
|
|
|
|
string text = null;
|
|
|
|
|
IDisplayTable displayTable = (IDisplayTable)FeaLyr;
|
|
|
|
|
ICursor cursor = displayTable.DisplayTable.Search(null, false);
|
|
|
|
|
IDataStatistics dataStatistics = new DataStatisticsClass();
|
|
|
|
|
dataStatistics.Cursor = cursor;
|
|
|
|
|
dataStatistics.Field = MatchField;
|
|
|
|
|
dataStatistics.SampleRate = -1;
|
|
|
|
|
IEnumerator uniqueValues = dataStatistics.UniqueValues;
|
|
|
|
|
uniqueValues.Reset();
|
|
|
|
|
string className = RenderUtil.GetClassName(FeaLyr);
|
|
|
|
|
Hashtable hashtable = null;
|
|
|
|
|
if (StylePath is IDoStyleGalleryPath)
|
|
|
|
|
{
|
|
|
|
|
hashtable = RenderUtil.GetAllSymbols(StylePath as IDoStyleGalleryPath, className);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
hashtable = RenderUtil.GetAllSymbols(StylePath.ToString(), className);
|
|
|
|
|
}
|
|
|
|
|
uniqueValueRenderer.FieldCount = 1;
|
|
|
|
|
uniqueValueRenderer.RemoveAllValues();
|
|
|
|
|
uniqueValueRenderer.set_Field(0, MatchField);
|
|
|
|
|
int num = displayTable.DisplayTable.RowCount(null);
|
|
|
|
|
messages.AppendLine("共有:" + num + "个要素需要匹配。");
|
|
|
|
|
IQueryFilter queryFilter = new QueryFilterClass();
|
|
|
|
|
int num2 = 0;
|
|
|
|
|
while (uniqueValues.MoveNext())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
text = Convert.ToString(uniqueValues.Current);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
ISymbol symbol = hashtable[text] as ISymbol;
|
|
|
|
|
if (symbol == null)
|
|
|
|
|
{
|
|
|
|
|
queryFilter.WhereClause = MatchField + "='" + text + "'";
|
|
|
|
|
int num3 = displayTable.DisplayTable.RowCount(queryFilter);
|
|
|
|
|
messages.AppendLine(string.Concat(new object[]
|
|
|
|
|
{
|
|
|
|
|
MatchField,
|
|
|
|
|
"值为:",
|
|
|
|
|
text,
|
|
|
|
|
"的",
|
|
|
|
|
num3,
|
|
|
|
|
"个要素未匹配到符号,使用默认符号"
|
|
|
|
|
}));
|
|
|
|
|
uniqueValueRenderer.AddValue(text, MatchField, defaultSymbol);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
uniqueValueRenderer.AddValue(text, MatchField, symbol);
|
|
|
|
|
}
|
|
|
|
|
num2++;
|
|
|
|
|
if (num2 >= MaxMatchCount && MaxMatchCount > 0)
|
|
|
|
|
{
|
|
|
|
|
messages.AppendLine(string.Concat(new object[]
|
|
|
|
|
{
|
|
|
|
|
"总个数",
|
|
|
|
|
dataStatistics.UniqueValueCount,
|
|
|
|
|
"个,已匹配",
|
|
|
|
|
MaxMatchCount,
|
|
|
|
|
"个,没有完全匹配"
|
|
|
|
|
}));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
uniqueValueRenderer.DefaultSymbol = defaultSymbol;
|
|
|
|
|
uniqueValueRenderer.UseDefaultSymbol = true;
|
|
|
|
|
(FeaLyr as IGeoFeatureLayer).Renderer = (uniqueValueRenderer as IFeatureRenderer);
|
|
|
|
|
messages.AppendLine(string.Concat(new object[]
|
|
|
|
|
{
|
|
|
|
|
"<",
|
|
|
|
|
(FeaLyr as ILayer).Name,
|
|
|
|
|
">符号匹配结束,共匹配:",
|
|
|
|
|
num2,
|
|
|
|
|
"种符号。 ",
|
|
|
|
|
DateTime.Now.ToString()
|
|
|
|
|
}));
|
|
|
|
|
messages.AppendLine("=======================");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
internal static void FeatureLayerAutoMatch(IFeatureLayer2 FeaLyr, object StylePath, string MatchField, int MaxMatchCount)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.InvkeLayerRenderDescription("开始匹配:<" + (FeaLyr as ILayer).Name + "> " + DateTime.Now.ToString());
|
|
|
|
|
IGeoFeatureLayer geoFeatureLayer = FeaLyr as IGeoFeatureLayer;
|
|
|
|
|
if (geoFeatureLayer == null)
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.InvkeLayerRenderDescription("不能对图层:<" + (FeaLyr as ILayer).Name + ">进行渲染。");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
IUniqueValueRenderer uniqueValueRenderer = geoFeatureLayer.Renderer as IUniqueValueRenderer;
|
|
|
|
|
if (uniqueValueRenderer == null)
|
|
|
|
|
{
|
|
|
|
|
uniqueValueRenderer = new UniqueValueRendererClass();
|
|
|
|
|
}
|
|
|
|
|
ISymbol defaultSymbol = uniqueValueRenderer.DefaultSymbol;
|
|
|
|
|
if (defaultSymbol == null)
|
|
|
|
|
{
|
|
|
|
|
defaultSymbol = RenderUtil.GetDefaultSymbol(FeaLyr.FeatureClass.ShapeType);
|
|
|
|
|
}
|
|
|
|
|
string text = null;
|
|
|
|
|
IDisplayTable displayTable = (IDisplayTable)FeaLyr;
|
|
|
|
|
ICursor cursor = displayTable.DisplayTable.Search(null, false);
|
|
|
|
|
IDataStatistics dataStatistics = new DataStatisticsClass();
|
|
|
|
|
dataStatistics.Cursor = cursor;
|
|
|
|
|
dataStatistics.Field = MatchField;
|
|
|
|
|
dataStatistics.SampleRate = -1;
|
|
|
|
|
IEnumerator uniqueValues = dataStatistics.UniqueValues;
|
|
|
|
|
uniqueValues.Reset();
|
|
|
|
|
string className = RenderUtil.GetClassName(FeaLyr);
|
|
|
|
|
Hashtable hashtable = null;
|
|
|
|
|
if (StylePath is IDoStyleGalleryPath)
|
|
|
|
|
{
|
|
|
|
|
hashtable = RenderUtil.GetAllSymbols(StylePath as IDoStyleGalleryPath, className);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
hashtable = RenderUtil.GetAllSymbols(StylePath.ToString(), className);
|
|
|
|
|
}
|
|
|
|
|
uniqueValueRenderer.FieldCount = 1;
|
|
|
|
|
uniqueValueRenderer.RemoveAllValues();
|
|
|
|
|
uniqueValueRenderer.set_Field(0, MatchField);
|
|
|
|
|
int num = displayTable.DisplayTable.RowCount(null);
|
|
|
|
|
RenderUtil.InvkeLayerRenderDescription("共有:" + num + "个要素需要匹配。");
|
|
|
|
|
IQueryFilter queryFilter = new QueryFilterClass();
|
|
|
|
|
int num2 = 0;
|
|
|
|
|
while (uniqueValues.MoveNext())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
text = Convert.ToString(uniqueValues.Current);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
ISymbol symbol = hashtable[text] as ISymbol;
|
|
|
|
|
if (symbol == null)
|
|
|
|
|
{
|
|
|
|
|
queryFilter.WhereClause = MatchField + "='" + text + "'";
|
|
|
|
|
int num3 = displayTable.DisplayTable.RowCount(queryFilter);
|
|
|
|
|
RenderUtil.InvkeLayerRenderDescription(string.Concat(new object[]
|
|
|
|
|
{
|
|
|
|
|
MatchField,
|
|
|
|
|
"值为:",
|
|
|
|
|
text,
|
|
|
|
|
"的",
|
|
|
|
|
num3,
|
|
|
|
|
"个要素未匹配到符号,使用默认符号"
|
|
|
|
|
}));
|
|
|
|
|
uniqueValueRenderer.AddValue(text, MatchField, defaultSymbol);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
uniqueValueRenderer.AddValue(text, MatchField, symbol);
|
|
|
|
|
}
|
|
|
|
|
num2++;
|
|
|
|
|
if (num2 >= MaxMatchCount && MaxMatchCount > 0)
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.InvkeLayerRenderDescription(string.Concat(new object[]
|
|
|
|
|
{
|
|
|
|
|
"总个数",
|
|
|
|
|
dataStatistics.UniqueValueCount,
|
|
|
|
|
"个,已匹配",
|
|
|
|
|
MaxMatchCount,
|
|
|
|
|
"个,没有完全匹配"
|
|
|
|
|
}));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
uniqueValueRenderer.DefaultSymbol = defaultSymbol;
|
|
|
|
|
uniqueValueRenderer.UseDefaultSymbol = true;
|
|
|
|
|
(FeaLyr as IGeoFeatureLayer).Renderer = (uniqueValueRenderer as IFeatureRenderer);
|
|
|
|
|
RenderUtil.InvkeLayerRenderDescription(string.Concat(new object[]
|
|
|
|
|
{
|
|
|
|
|
"<",
|
|
|
|
|
(FeaLyr as ILayer).Name,
|
|
|
|
|
">符号匹配结束,共匹配:",
|
|
|
|
|
num2,
|
|
|
|
|
"种符号。 ",
|
|
|
|
|
DateTime.Now.ToString()
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.InvkeLayerRenderDescription("匹配异常:" + ex.Message);
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
internal static string GetClassName(IFeatureLayer2 pLayer)
|
|
|
|
|
{
|
|
|
|
|
esriGeometryType shapeType = pLayer.ShapeType;
|
|
|
|
|
switch (shapeType)
|
|
|
|
|
{
|
|
|
|
|
case esriGeometryType.esriGeometryPoint:
|
|
|
|
|
return "Marker Symbols";
|
|
|
|
|
case esriGeometryType.esriGeometryMultipoint:
|
|
|
|
|
goto IL_36;
|
|
|
|
|
case esriGeometryType.esriGeometryPolyline:
|
|
|
|
|
break;
|
|
|
|
|
case esriGeometryType.esriGeometryPolygon:
|
|
|
|
|
return "Fill Symbols";
|
|
|
|
|
default:
|
|
|
|
|
if (shapeType != esriGeometryType.esriGeometryLine)
|
|
|
|
|
{
|
|
|
|
|
goto IL_36;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return "Line Symbols";
|
|
|
|
|
IL_36:
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
internal static ISymbol GetDefaultSymbol(esriGeometryType geometryType)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ISymbol result = null;
|
|
|
|
|
IRgbColor rgbColor = new RgbColorClass();
|
|
|
|
|
rgbColor.Red = 184;
|
|
|
|
|
rgbColor.Green = 242;
|
|
|
|
|
rgbColor.Blue = 200;
|
|
|
|
|
switch (geometryType)
|
|
|
|
|
{
|
|
|
|
|
case esriGeometryType.esriGeometryPoint:
|
|
|
|
|
result = (new SimpleMarkerSymbolClass
|
|
|
|
|
{
|
|
|
|
|
Color = rgbColor,
|
|
|
|
|
Style = esriSimpleMarkerStyle.esriSMSCircle
|
|
|
|
|
} as ISymbol);
|
|
|
|
|
goto IL_B3;
|
|
|
|
|
case esriGeometryType.esriGeometryMultipoint:
|
|
|
|
|
goto IL_B3;
|
|
|
|
|
case esriGeometryType.esriGeometryPolyline:
|
|
|
|
|
break;
|
|
|
|
|
case esriGeometryType.esriGeometryPolygon:
|
|
|
|
|
result = (new SimpleFillSymbolClass
|
|
|
|
|
{
|
|
|
|
|
Color = rgbColor,
|
|
|
|
|
Style = esriSimpleFillStyle.esriSFSSolid
|
|
|
|
|
} as ISymbol);
|
|
|
|
|
goto IL_B3;
|
|
|
|
|
default:
|
|
|
|
|
if (geometryType != esriGeometryType.esriGeometryLine)
|
|
|
|
|
{
|
|
|
|
|
goto IL_B3;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
result = (new SimpleLineSymbolClass
|
|
|
|
|
{
|
|
|
|
|
Color = rgbColor,
|
|
|
|
|
Width = 1.0,
|
|
|
|
|
Style = esriSimpleLineStyle.esriSLSSolid
|
|
|
|
|
} as ISymbol);
|
|
|
|
|
IL_B3:
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
internal static ILayerFile OpenLayerFile()
|
|
|
|
|
{
|
|
|
|
|
ILayerFile layerFile = null;
|
|
|
|
|
if (RenderUtil.openFileDialog == null)
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.openFileDialog = new KGIS.Framework.Utils.Dialog.OpenFileDialog();
|
|
|
|
|
}
|
|
|
|
|
RenderUtil.openFileDialog.Filter = "图层文件(*.lyr)|*.lyr";
|
|
|
|
|
RenderUtil.openFileDialog.Title = "选择图层文件";
|
|
|
|
|
RenderUtil.openFileDialog.Multiselect = false;
|
|
|
|
|
if (!RenderUtil.openFileDialog.ShowDialog())
|
|
|
|
|
{
|
|
|
|
|
return layerFile;
|
|
|
|
|
}
|
|
|
|
|
string fileName = RenderUtil.openFileDialog.FileName;
|
|
|
|
|
if (fileName != "")
|
|
|
|
|
{
|
|
|
|
|
layerFile = new LayerFileClass();
|
|
|
|
|
layerFile.Open(fileName);
|
|
|
|
|
return layerFile;
|
|
|
|
|
}
|
|
|
|
|
return layerFile;
|
|
|
|
|
}
|
|
|
|
|
internal static void InvkeLayerRenderDescription(string desc)
|
|
|
|
|
{
|
|
|
|
|
if (RenderUtil.LayerRenderDescription != null)
|
|
|
|
|
{
|
|
|
|
|
RenderUtil.LayerRenderDescription(desc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
internal static void SetUniqueValuesToTable(IUniqueValueRenderer m_LyrRender, IStyleGalleryClass m_SymbologyStyleClass, DataTable m_SymbolTable)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DataRow dataRow = null;
|
|
|
|
|
for (int i = 0; i < m_LyrRender.ValueCount; i++)
|
|
|
|
|
{
|
|
|
|
|
string text = m_LyrRender.get_Value(i);
|
|
|
|
|
ISymbol symbol = m_LyrRender.get_Symbol(text);
|
|
|
|
|
string value = m_LyrRender.get_Label(text);
|
|
|
|
|
if (symbol == null)
|
|
|
|
|
{
|
|
|
|
|
if (dataRow != null)
|
|
|
|
|
{
|
|
|
|
|
dataRow["F_Value"] = dataRow["F_Value"] + ";" + text;
|
|
|
|
|
dataRow.AcceptChanges();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Bitmap symbolBitMap = RenderUtil.GetSymbolBitMap(40, 20, m_SymbologyStyleClass, symbol);
|
|
|
|
|
IClone clone = symbol as IClone;
|
|
|
|
|
ISymbol value2 = clone.Clone() as ISymbol;
|
|
|
|
|
dataRow = m_SymbolTable.NewRow();
|
|
|
|
|
dataRow["F_BITMAP"] = symbolBitMap;
|
|
|
|
|
dataRow["F_Value"] = text;
|
|
|
|
|
dataRow["F_Label"] = value;
|
|
|
|
|
dataRow["F_Symbol"] = value2;
|
|
|
|
|
m_SymbolTable.Rows.Add(dataRow);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
internal static void SetUniqueValuesFromTable(IUniqueValueRenderer m_LyrRender, string headName, DataTable m_SymbolTable)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < m_SymbolTable.Rows.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
DataRow dataRow = m_SymbolTable.Rows[i];
|
|
|
|
|
string text = Convert.ToString(dataRow["F_Value"]);
|
|
|
|
|
string label = (dataRow["F_Label"] == DBNull.Value) ? "" : dataRow["F_Label"].ToString();
|
|
|
|
|
ISymbol symbol = dataRow["F_Symbol"] as ISymbol;
|
|
|
|
|
string[] array = text.Split(new char[]
|
|
|
|
|
{
|
|
|
|
|
';'
|
|
|
|
|
});
|
|
|
|
|
if (array.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
m_LyrRender.AddValue(array[0], headName, symbol);
|
|
|
|
|
m_LyrRender.set_Label(array[0], label);
|
|
|
|
|
m_LyrRender.set_Symbol(array[0], symbol);
|
|
|
|
|
for (int j = 1; j < array.Length; j++)
|
|
|
|
|
{
|
|
|
|
|
string value = array.GetValue(j).ToString();
|
|
|
|
|
m_LyrRender.AddReferenceValue(value, array[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//RdbUtil.AddException(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|