年度变更建库软件5.0版本
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.

1719 lines
79 KiB

4 months ago
using System;
using System.Collections.Generic;
using System.Text;
using Kingo.Framework.LayerStyleConvert.XSDClass;
using System.Drawing;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
namespace Kingo.Framework.LayerStyleConvert.Common
{
public class SymbolConvert
{
public int hdc = 0;
private static SymbolConvert _instance = null;
static object lockObj = new object();
public static SymbolConvert Instance()
{
lock (lockObj)
{
if (_instance == null)
_instance = new SymbolConvert();
}
return _instance;
}
public Renderer GetRenderer(ESRI.ArcGIS.Carto.IFeatureRenderer renderer)
{
Renderer customRenderer = null;
if (renderer is ISimpleRenderer)
{
customRenderer = GetSimpleRenderer(renderer as ISimpleRenderer);
}
else if (renderer is IUniqueValueRenderer)
{
customRenderer = GetUniqueValueRenderer(renderer as IUniqueValueRenderer);
}
return customRenderer;
}
public Renderer GetSimpleRenderer(ISimpleRenderer esriSimpleRenderer)
{
Kingo.Framework.LayerStyleConvert.XSDClass.SimpleRenderer customRenderer = new Kingo.Framework.LayerStyleConvert.XSDClass.SimpleRenderer();
customRenderer.Symbol = GetSymbol(esriSimpleRenderer.Symbol);
customRenderer.Label = esriSimpleRenderer.Label;
customRenderer.Description = esriSimpleRenderer.Description;
return customRenderer;
}
public Renderer GetUniqueValueRenderer(IUniqueValueRenderer esriUniqueValueRenderer)
{
Kingo.Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer customRenderer = new Kingo.Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer();
customRenderer.DefaultSymbol = GetSymbol(esriUniqueValueRenderer.DefaultSymbol);
customRenderer.DefaultLabel = esriUniqueValueRenderer.DefaultLabel;
customRenderer.Field1 = esriUniqueValueRenderer.get_Field(0);
if (esriUniqueValueRenderer.FieldCount == 2)
customRenderer.Field2 = esriUniqueValueRenderer.get_Field(1);
if (esriUniqueValueRenderer.FieldCount == 3)
customRenderer.Field3 = esriUniqueValueRenderer.get_Field(2);
customRenderer.FieldDelimiter = esriUniqueValueRenderer.FieldDelimiter;
List< Kingo.Framework.LayerStyleConvert.XSDClass.UniqueValueInfo> lstUniqueValueInfo = new List<Kingo.Framework.LayerStyleConvert.XSDClass.UniqueValueInfo>();
Kingo.Framework.LayerStyleConvert.XSDClass.UniqueValueInfo unqiueInfo = null;
for (int i = 0; i < esriUniqueValueRenderer.ValueCount; i++)
{
unqiueInfo = new Kingo.Framework.LayerStyleConvert.XSDClass.UniqueValueInfo();
unqiueInfo.Value = esriUniqueValueRenderer.get_Value(i);
unqiueInfo.Label = esriUniqueValueRenderer.get_Label(unqiueInfo.Value);
unqiueInfo.Description = esriUniqueValueRenderer.get_Description(unqiueInfo.Value);
//unqiueInfo.Symbol = GetSymbol(esriUniqueValueRenderer.get_Symbol(unqiueInfo.Value));
unqiueInfo.Symbol = GetUniqueSymbol(esriUniqueValueRenderer.get_Symbol(unqiueInfo.Value));
lstUniqueValueInfo.Add(unqiueInfo);
}
customRenderer.UniqueValueInfos = lstUniqueValueInfo;
return customRenderer;
}
/// <summary>
/// ESRI样式转为自定义样式
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public Kingo.Framework.LayerStyleConvert.XSDClass.Symbol GetSymbol(ESRI.ArcGIS.Display.ISymbol symbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.Symbol symbolCustom = null;
try
{
if (symbol == null) return null;
//面
if (symbol is IFillSymbol)
{
symbolCustom = EsriFillSymbolToCustomSymbol(symbol as IFillSymbol);
}
//线
else if (symbol is ILineSymbol)
{
symbolCustom = EsriLSymbolToCustomLineSymbol(symbol as ILineSymbol);
}
//点
else if (symbol is IMarkerSymbol)
{
symbolCustom = EsriMarkerSymbolToCustomMSymbol(symbol as IMarkerSymbol);
}
}
catch (Exception ex)
{
// LogAPI.Debug("ESRI样式转为自定义样式失败:" + ex);
throw ex;
}
return symbolCustom;
}
private Bitmap PreViewMarkerSymbol(ISymbol pSymbol, int width, int height)
{
Bitmap img = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
try
{
IStyleGalleryClass pStyleGalleryClass = new MarkerSymbolStyleGalleryClass();
Graphics gc = Graphics.FromImage(img);
//SystemColors.Window
IntPtr hdc = gc.GetHdc();
ESRI.ArcGIS.esriSystem.tagRECT rect = new ESRI.ArcGIS.esriSystem.tagRECT();
rect.left = 0;
rect.top = 0;
rect.right = width;
rect.bottom = height;
pStyleGalleryClass.Preview(pSymbol, hdc.ToInt32(), ref rect);
//gc.Save();
gc.ReleaseHdc(hdc);
gc.Dispose();
return img;
}
catch (Exception ex)
{
// LogAPI.Debug("预览标记符号失败:" + ex);
throw ex;
}
finally
{
//img.Dispose();
//img = null;
}
}
private Bitmap PreViewFillSymbol(ISymbol pSymbol, int width, int height)
{
Bitmap img = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
try
{
IStyleGalleryClass pStyleGalleryClass = new FillSymbolStyleGalleryClass();
Graphics gc = Graphics.FromImage(img);
//SystemColors.Window
IntPtr hdc = gc.GetHdc();
ESRI.ArcGIS.esriSystem.tagRECT rect = new ESRI.ArcGIS.esriSystem.tagRECT();
rect.left = 0;
rect.top = 0;
rect.right = width;
rect.bottom = height;
pStyleGalleryClass.Preview(pSymbol, hdc.ToInt32(), ref rect);
//gc.Save();
gc.ReleaseHdc(hdc);
gc.Dispose();
img.MakeTransparent(Color.FromArgb(SystemColors.Window.ToArgb()));
img.Save("E:\\preview.png");
return img.Clone(new Rectangle(4, 4, width - 6, height - 6), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
}
catch (Exception ex)
{
// LogAPI.Debug("预览填充符号失败:" + ex);
throw ex;
}
finally
{
img.Dispose();
img = null;
}
}
private Bitmap PreViewLineSymbol(ISymbol pSymbol, int width, int height)
{
Bitmap img = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
try
{
IStyleGalleryClass pStyleGalleryClass = new LineSymbolStyleGalleryClassClass();
Graphics gc = Graphics.FromImage(img);
//SystemColors.Window
IntPtr hdc = gc.GetHdc();
ESRI.ArcGIS.esriSystem.tagRECT rect = new ESRI.ArcGIS.esriSystem.tagRECT();
rect.left = 0;
rect.top = 0;
rect.right = width;
rect.bottom = height;
pStyleGalleryClass.Preview(pSymbol, hdc.ToInt32(), ref rect);
//gc.Save();
gc.ReleaseHdc(hdc);
gc.Dispose();
return img;
}
catch (Exception ex)
{
// LogAPI.Debug("预览线符号失败:" + ex);
throw ex;
}
finally
{
img.Dispose();
img = null;
}
}
/// <summary>
/// 自定义样式转换为ESRI样式
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public ESRI.ArcGIS.Display.ISymbol CustomSymbolToEsriSymbol(Kingo.Framework.LayerStyleConvert.XSDClass.Symbol symbol)
{
ESRI.ArcGIS.Display.ISymbol esriSymbol = null;
try
{
if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.FSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.FSymbol fsSymbol = symbol as Kingo.Framework.LayerStyleConvert.XSDClass.FSymbol;
esriSymbol = (ISymbol)CustomFillToEsriFill(fsSymbol);
}
else if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.LSymbol)
{
LSymbol lSymbol = symbol as LSymbol;
esriSymbol = (ISymbol)CustomLineSymbolToEsriLSymbol(lSymbol);
}
else if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.MSymbol)
{
MSymbol mSymbol = symbol as MSymbol;
esriSymbol = (ISymbol)CustomMarkerSymbolToEsriMSymbol(mSymbol);
}
}
catch (Exception ex)
{
// LogAPI.Debug("自定义样式转换为ESRI样式失败:" + ex);
throw ex;
}
return esriSymbol;
}
/// <summary>
/// Arcgis填充样式转换为自定义样式格式
/// </summary>
/// <param name="esriSymbol"></param>
/// <returns></returns>
public Kingo.Framework.LayerStyleConvert.XSDClass.FSymbol EsriFillSymbolToCustomSymbol(ESRI.ArcGIS.Display.IFillSymbol esriSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.FSymbol symbolCustom = null;
try
{
if (esriSymbol is ESRI.ArcGIS.Display.MultiLayerFillSymbol)
{
ESRI.ArcGIS.Display.MultiLayerFillSymbol esriMulti = esriSymbol as ESRI.ArcGIS.Display.MultiLayerFillSymbol;
if (esriMulti != null)
{
if (esriMulti.LayerCount == 1)
{
Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol customMulti = new Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol();
int[] color = null;
for (int i = 0; i < esriMulti.LayerCount; i++)
{
FSymbol symbolTemp = EsriFillSymbolToCustomSymbolOne(esriMulti.get_Layer(i));
if (symbolTemp == null) continue;
customMulti.AddLayerFillSymbol(symbolTemp);
}
customMulti.Outline = EsriLSymbolToCustomLineSymbol(esriMulti.Outline);
if (esriMulti.Color != null && esriMulti.Color.NullColor)
{
customMulti.Color[3] = 0;// new int[4];
}
else
{
if (esriMulti.Color == null)
{
customMulti.Color = GetColorArr(esriMulti.Outline.Color);
}
else
customMulti.Color = GetColorArr(esriMulti.Color);
}
symbolCustom = customMulti;
}
else
{
Kingo.Framework.LayerStyleConvert.XSDClass.PFSymbol symbolPicCustom = new PFSymbol();
symbolPicCustom.Outline = EsriLSymbolToCustomLineSymbol(esriMulti.Outline);
symbolPicCustom.Xscale = 1;
symbolPicCustom.Yscale = 1;
Bitmap imgRst = PreViewFillSymbol((ISymbol)esriSymbol, 70, 70);
//SetImagesPix(imgRst);
//imgRst.Save("E:\\imgrst.bmp");
//imgRst=(Bitmap) Bitmap.FromFile("E:\\imgrst1.bmp");
if (imgRst != null)
{
//System.IO.MemoryStream imgStream = new System.IO.MemoryStream();
//imgRst.Save(imgStream, System.Drawing.Imaging.ImageFormat.Bmp);
//symbolPicCustom.ImageData = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetBase64FromImage(Image.FromStream(imgStream));
symbolPicCustom.ImageData = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetBase64FromImage(imgRst);
symbolPicCustom.Height = imgRst.Height;
symbolPicCustom.Width = imgRst.Width;
imgRst.Dispose();
imgRst = null;
}
symbolCustom = symbolPicCustom;
}
}
}
else
{
symbolCustom = EsriFillSymbolToCustomSymbolOne(esriSymbol);
}
}
catch (Exception ex)
{
// LogAPI.Debug("Arcgis填充样式转换为自定义样式失败:" + ex);
throw ex;
}
return symbolCustom;
}
private Kingo.Framework.LayerStyleConvert.XSDClass.FSymbol EsriFillSymbolToCustomSymbolOne(ESRI.ArcGIS.Display.IFillSymbol esriSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.FSymbol symbolCustom = null;
try
{
if (esriSymbol is IMarkerFillSymbol)
{
IMarkerFillSymbol esriMarkerFill = esriSymbol as IMarkerFillSymbol;
if (esriMarkerFill != null)
{
MFSymbol customSymbol = new MFSymbol();
customSymbol.Color = GetColorArr(esriMarkerFill.Color);
customSymbol.GridAngle = esriMarkerFill.GridAngle;
customSymbol.MarkerSymbol = EsriMarkerSymbolToCustomMSymbol(esriMarkerFill.MarkerSymbol);
customSymbol.Outline = EsriLSymbolToCustomLineSymbol(esriMarkerFill.Outline);
customSymbol.Style = (Kingo.Framework.LayerStyleConvert.XSDClass.esriMarkerFillStyle)((int)esriMarkerFill.Style);
symbolCustom = customSymbol;
}
}
else if (esriSymbol is ILineFillSymbol)
{
ILineFillSymbol esriLineFill = esriSymbol as ILineFillSymbol;
if (esriLineFill != null)
{
Kingo.Framework.LayerStyleConvert.XSDClass.LineFSymbol symbolLineCustom = new Kingo.Framework.LayerStyleConvert.XSDClass.LineFSymbol();
symbolLineCustom.Angle = esriLineFill.Angle;
Color color = System.Drawing.ColorTranslator.FromWin32(esriSymbol.Color.RGB);
symbolLineCustom.Color = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetInt4ColorFromColor(color);
symbolLineCustom.LineSymbol = EsriLSymbolToCustomLineSymbol(esriLineFill.LineSymbol);
symbolLineCustom.Offset = esriLineFill.Offset;
symbolLineCustom.Outline = EsriLSymbolToCustomLineSymbol(esriLineFill.Outline);
symbolLineCustom.Separation = esriLineFill.Separation;
symbolCustom = symbolLineCustom;
}
}
else if (esriSymbol is ISimpleFillSymbol)
{
ISimpleFillSymbol esriSimpleFill = esriSymbol as ISimpleFillSymbol;
if (esriSimpleFill != null)
{
Kingo.Framework.LayerStyleConvert.XSDClass.SFSymbol symbolSimpleCustom = new SFSymbol();
Color color = System.Drawing.ColorTranslator.FromWin32(esriSymbol.Color.RGB);
symbolSimpleCustom.Color = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetInt4ColorFromColor(color);
if (esriSymbol.Color.NullColor)
{
symbolSimpleCustom.Color[3] = 0;
//symbolSimpleCustom.Color = new int[4];
}
symbolSimpleCustom.Outline = EsriLSymbolToCustomLineSymbol(esriSimpleFill.Outline);
symbolSimpleCustom.Style = (Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle)((int)esriSimpleFill.Style);
symbolCustom = symbolSimpleCustom;
}
}
else if (esriSymbol is IPictureFillSymbol)
{
IPictureFillSymbol esriPictureFill = esriSymbol as IPictureFillSymbol;
if (esriPictureFill != null)
{
Kingo.Framework.LayerStyleConvert.XSDClass.PFSymbol symbolPicCustom = new PFSymbol();
symbolPicCustom.Angle = (int)esriPictureFill.Angle;
System.Drawing.Image image = System.Drawing.Image.FromHbitmap(new System.IntPtr(esriPictureFill.Picture.Handle));
symbolPicCustom.ImageData = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetBase64FromImage(image);
symbolPicCustom.Height = image.Height;
symbolPicCustom.Width = image.Width;
symbolPicCustom.Outline = EsriLSymbolToCustomLineSymbol(esriPictureFill.Outline);
symbolPicCustom.Xscale = (int)esriPictureFill.XScale;
symbolPicCustom.Yscale = (int)esriPictureFill.YScale;
symbolCustom = symbolPicCustom;
image.Dispose();
}
}
}
catch (Exception ex)
{
// LogAPI.Debug("ESRI样式转换为自定义样式失败:" + ex);
throw ex;
}
return symbolCustom;
}
/// <summary>
/// 自定义填充样式转换为ESRI填充样式
/// </summary>
/// <param name="fSymbol"></param>
/// <returns></returns>
public ESRI.ArcGIS.Display.IFillSymbol CustomFillToEsriFill(Kingo.Framework.LayerStyleConvert.XSDClass.FSymbol fSymbol)
{
ESRI.ArcGIS.Display.IFillSymbol fillSymbol = null;
try
{
if (fSymbol is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol cutomMultiFill = fSymbol as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol;
if (cutomMultiFill == null || cutomMultiFill.lstFSymbol == null || cutomMultiFill.lstFSymbol.Count <= 0) return null;
ESRI.ArcGIS.Display.IMultiLayerFillSymbol mulLayer = new ESRI.ArcGIS.Display.MultiLayerFillSymbol();
for (int i = cutomMultiFill.lstFSymbol.Count - 1; i >= 0; i--)
{
ESRI.ArcGIS.Display.IFillSymbol fillSymbolTemp = CustomFillToEsriFillOne(cutomMultiFill.GetLayer(i));
if (fillSymbolTemp != null)
{
mulLayer.AddLayer(fillSymbolTemp);
}
}
//mulLayer.Color = GetColor(cutomMultiFill.Color, true);
//mulLayer.Color.Transparency = 0;
//mulLayer.Color.NullColor = true;
mulLayer.Outline = CustomLineSymbolToEsriLSymbol(fSymbol.Outline);
fillSymbol = (ESRI.ArcGIS.Display.IFillSymbol)mulLayer;
}
else
{
fillSymbol = CustomFillToEsriFillOne(fSymbol);
}
}
catch (Exception ex)
{
//LogAPI.Debug("自定义填充样式转换为ESRI填充样式失败:" + ex);
throw ex;
}
return fillSymbol;
}
private ESRI.ArcGIS.Display.IFillSymbol CustomFillToEsriFillOne(Kingo.Framework.LayerStyleConvert.XSDClass.FSymbol fSymbol)
{
ESRI.ArcGIS.Display.IFillSymbol fillSymbol = null;
try
{
if (fSymbol is Kingo.Framework.LayerStyleConvert.XSDClass.SFSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.SFSymbol sfSymbol = fSymbol as Kingo.Framework.LayerStyleConvert.XSDClass.SFSymbol;
ESRI.ArcGIS.Display.SimpleFillSymbol simplefillSymbol = new SimpleFillSymbol();
simplefillSymbol.Color = GetColor(sfSymbol.Color);
simplefillSymbol.Outline = CustomLineSymbolToEsriLSymbol(sfSymbol.Outline);
simplefillSymbol.Style = (ESRI.ArcGIS.Display.esriSimpleFillStyle)((int)sfSymbol.Style);
fillSymbol = simplefillSymbol;
}
else if (fSymbol is Kingo.Framework.LayerStyleConvert.XSDClass.LineFSymbol)
{
LineFSymbol lineFillSymbol = fSymbol as LineFSymbol;
LineFillSymbol esriLinefillSymbol = new LineFillSymbol();
esriLinefillSymbol.Angle = lineFillSymbol.Angle;
esriLinefillSymbol.Color = GetColor(lineFillSymbol.Color);
esriLinefillSymbol.LineSymbol = CustomLineSymbolToEsriLSymbol(lineFillSymbol.LineSymbol);
esriLinefillSymbol.Offset = lineFillSymbol.Offset;
esriLinefillSymbol.Outline = CustomLineSymbolToEsriLSymbol(lineFillSymbol.Outline);
esriLinefillSymbol.Separation = lineFillSymbol.Separation;
fillSymbol = esriLinefillSymbol;
}
else if (fSymbol is Kingo.Framework.LayerStyleConvert.XSDClass.PFSymbol)
{
PFSymbol pictureFillSymbol = fSymbol as PFSymbol;
PictureFillSymbol esriPicFillSymbol = new PictureFillSymbol();
esriPicFillSymbol.Angle = pictureFillSymbol.Angle;
esriPicFillSymbol.Outline = CustomLineSymbolToEsriLSymbol(pictureFillSymbol.Outline);
Image img = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetImageFromBase64(pictureFillSymbol.ImageData);
esriPicFillSymbol.Picture = ConvertImg.Convert(img);
esriPicFillSymbol.XScale = pictureFillSymbol.Xscale;
esriPicFillSymbol.YScale = pictureFillSymbol.Yscale;
fillSymbol = esriPicFillSymbol;
}
else if (fSymbol is Kingo.Framework.LayerStyleConvert.XSDClass.MFSymbol)
{
MFSymbol customSymbol = fSymbol as MFSymbol;
MarkerFillSymbol esriMarkerFillSymbol = new MarkerFillSymbol();
esriMarkerFillSymbol.Color = GetColor(customSymbol.Color);
esriMarkerFillSymbol.GridAngle = customSymbol.GridAngle;
esriMarkerFillSymbol.MarkerSymbol = CustomMarkerSymbolToEsriMSymbol(customSymbol.MarkerSymbol);
esriMarkerFillSymbol.Outline = CustomLineSymbolToEsriLSymbol(customSymbol.Outline);
esriMarkerFillSymbol.Style = (ESRI.ArcGIS.Display.esriMarkerFillStyle)((int)customSymbol.Style);
fillSymbol = esriMarkerFillSymbol;
}
}
catch (Exception ex)
{
// LogAPI.Debug("自定义填充样式转换为ESRI填充样式失败:" + ex);
}
return fillSymbol;
}
/// <summary>
/// 自定义线样式转ESRI线样式
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public ILineSymbol CustomLineSymbolToEsriLSymbol(LSymbol symbol)
{
ILineSymbol lineSymbol = null;
try
{
if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol multiLineSymbol = symbol as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol;
if (multiLineSymbol == null || multiLineSymbol.lstLSymbol == null)
return null;
ESRI.ArcGIS.Display.MultiLayerLineSymbol esriLineSymbol = new ESRI.ArcGIS.Display.MultiLayerLineSymbol();
for (int i = 0; i < multiLineSymbol.lstLSymbol.Count; i++)
{
ILineSymbol lineSymbolTemp = CustomLineSymbolToEsriLSymbolOne(multiLineSymbol.GetLayer(i));
if (lineSymbolTemp != null)
esriLineSymbol.AddLayer(lineSymbolTemp);
}
lineSymbol = esriLineSymbol;
if (symbol.Color != null)
lineSymbol.Color = GetColor(symbol.Color);
lineSymbol.Width = multiLineSymbol.Width;
}
else
{
lineSymbol = CustomLineSymbolToEsriLSymbolOne(symbol);
}
}
catch (Exception ex)
{
// LogAPI.Debug("自定义线样式转ESRI线样式:" + ex);
throw ex;
}
return lineSymbol;
}
private ILineSymbol CustomLineSymbolToEsriLSymbolOne(LSymbol symbol)
{
ILineSymbol lineSymbol = null;
try
{
if (symbol is SLSymbol)
{
SLSymbol customSymbol = symbol as SLSymbol;
ISimpleLineSymbol esriSymbol = new SimpleLineSymbolClass();
esriSymbol.Color = GetColor(customSymbol.Color);
esriSymbol.Style = (ESRI.ArcGIS.Display.esriSimpleLineStyle)((int)customSymbol.Style);
esriSymbol.Width = customSymbol.Width;
lineSymbol = esriSymbol;
}
else if (symbol is MarkLSymbol)
{
MarkLSymbol customSymbol = symbol as MarkLSymbol;
IMarkerLineSymbol esriSymbol = new MarkerLineSymbolClass();
esriSymbol.Color = GetColor(customSymbol.Color);
esriSymbol.MarkerSymbol = CustomMarkerSymbolToEsriMSymbol(customSymbol.MarkerSymbol);
esriSymbol.Width = customSymbol.Width;
lineSymbol = esriSymbol;
}
else if (symbol is PictureLSymbol)
{
PictureLSymbol customSymbol = symbol as PictureLSymbol;
IPictureLineSymbol esriSymbol = new PictureLineSymbolClass();
esriSymbol.BackgroundColor = GetColor(customSymbol.BackgroundColor);
esriSymbol.BitmapTransparencyColor = GetColor(customSymbol.BitmapTransparencyColor);
esriSymbol.Color = GetColor(customSymbol.Color);
esriSymbol.Offset = customSymbol.Offset;
Image img = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetImageFromBase64(customSymbol.ImgData);
esriSymbol.Picture = ConvertImg.Convert(img);
esriSymbol.Rotate = customSymbol.Rotate;
esriSymbol.SwapForeGroundBackGroundColor = customSymbol.SwapForeGroundBackGroundColor;
esriSymbol.Width = customSymbol.Width;
esriSymbol.XScale = customSymbol.XScale;
esriSymbol.YScale = customSymbol.YScale;
lineSymbol = esriSymbol;
}
else if (symbol is HashLSymbol)
{
HashLSymbol customSymbol = symbol as HashLSymbol;
IHashLineSymbol esriSymbol = new HashLineSymbolClass();
esriSymbol.Angle = customSymbol.Angle;
esriSymbol.Color = GetColor(customSymbol.Color);
esriSymbol.HashSymbol = CustomLineSymbolToEsriLSymbol(customSymbol.HashSymbol);
esriSymbol.Width = customSymbol.Width;
lineSymbol = esriSymbol;
}
else if (symbol is CLSymbol)
{
CLSymbol customSymbol = symbol as CLSymbol;
ICartographicLineSymbol esriSymbol = new CartographicLineSymbolClass();
esriSymbol.Cap = (ESRI.ArcGIS.Display.esriLineCapStyle)((int)customSymbol.Cap);
esriSymbol.Color = GetColor(customSymbol.Color);
esriSymbol.Join = (ESRI.ArcGIS.Display.esriLineJoinStyle)((int)customSymbol.Join);
esriSymbol.MiterLimit = customSymbol.MiterLimit;
esriSymbol.Width = customSymbol.Width;
lineSymbol = esriSymbol;
}
}
catch (Exception ex)
{
//LogAPI.Debug("自定义线样式转ESRI线样式:" + ex);
throw ex;
}
return lineSymbol;
}
/// <summary>
/// ESRI线样式转自定义线样式
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public LSymbol EsriLSymbolToCustomLineSymbol(ILineSymbol symbol)
{
LSymbol newSymbol = null;
try
{
if (symbol is ESRI.ArcGIS.Display.MultiLayerLineSymbol)
{
ESRI.ArcGIS.Display.MultiLayerLineSymbol esriSymbol = symbol as ESRI.ArcGIS.Display.MultiLayerLineSymbol;
Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol customSymbol = new Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol();
if (esriSymbol.LayerCount > 0)
{
int[] colors = null;
for (int i = esriSymbol.LayerCount - 1; i >= 0; i--)
{
LSymbol lsymbolTemp = EsriLSymbolToCustomLineSymbolOne(esriSymbol.get_Layer(i));
if (lsymbolTemp == null) continue;
customSymbol.AddLayerFillSymbol(lsymbolTemp);
}
customSymbol.Color = GetColorArr(esriSymbol.Color);
customSymbol.Width = esriSymbol.Width;
newSymbol = customSymbol.lstLSymbol[0];
newSymbol.Color = GetColorArr(esriSymbol.Color);
newSymbol.Width = esriSymbol.Width;
}
}
else
{
newSymbol = EsriLSymbolToCustomLineSymbolOne(symbol);
}
}
catch (Exception ex)
{
// LogAPI.Debug("ESRI线样式转自定义线样式失败:" + ex);
throw ex;
}
return newSymbol;
}
private LSymbol EsriLSymbolToCustomLineSymbolOne(ILineSymbol symbol)
{
LSymbol newSymbol = null;
try
{
if (symbol is ISimpleLineSymbol)
{
ISimpleLineSymbol esriSymbol = symbol as ISimpleLineSymbol;
SLSymbol customSymbol = new SLSymbol();
customSymbol.Color = GetColorArr(esriSymbol.Color);
customSymbol.Style = (Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleLineStyle)((int)esriSymbol.Style);
customSymbol.Width = esriSymbol.Width;
newSymbol = customSymbol;
}
else if (symbol is IMarkerLineSymbol)
{
IMarkerLineSymbol esriSymbol = symbol as IMarkerLineSymbol;
MarkLSymbol customSymbol = new MarkLSymbol();
customSymbol.Color = GetColorArr(esriSymbol.Color);
customSymbol.MarkerSymbol = EsriMarkerSymbolToCustomMSymbol(esriSymbol.MarkerSymbol);
customSymbol.Width = esriSymbol.Width;
newSymbol = customSymbol;
}
else if (symbol is IHashLineSymbol)
{
IHashLineSymbol esriSymbol = symbol as IHashLineSymbol;
HashLSymbol customSymbol = new HashLSymbol();
customSymbol.Angle = esriSymbol.Angle;
customSymbol.Color = GetColorArr(esriSymbol.Color);
customSymbol.HashSymbol = EsriLSymbolToCustomLineSymbol(esriSymbol.HashSymbol);
customSymbol.Width = esriSymbol.Width;
newSymbol = customSymbol;
}
else if (symbol is IPictureLineSymbol)
{
IPictureLineSymbol esriSymbol = symbol as IPictureLineSymbol;
PictureLSymbol customSymbol = new PictureLSymbol();
customSymbol.BackgroundColor = GetColorArr(esriSymbol.BackgroundColor);
customSymbol.BitmapTransparencyColor = GetColorArr(esriSymbol.BitmapTransparencyColor);
customSymbol.Color = GetColorArr(esriSymbol.Color);
Bitmap bitmap = PreViewLineSymbol((ISymbol)symbol, 100, 2);
if (bitmap != null)
{
System.IO.MemoryStream imgStream = new System.IO.MemoryStream();
bitmap.Save("E:\\LineSymbol.png");
bitmap.Save(imgStream, System.Drawing.Imaging.ImageFormat.Png);
customSymbol.ImgData = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetBase64FromImage(Image.FromStream(imgStream));
bitmap.Dispose();
bitmap = null;
}
customSymbol.Offset = esriSymbol.Offset;
customSymbol.Rotate = esriSymbol.Rotate;
customSymbol.SwapForeGroundBackGroundColor = esriSymbol.SwapForeGroundBackGroundColor;
customSymbol.Width = esriSymbol.Width;
customSymbol.XScale = esriSymbol.XScale;
customSymbol.YScale = esriSymbol.YScale;
newSymbol = customSymbol;
}
else if (symbol is ICartographicLineSymbol)
{
ICartographicLineSymbol esriSymbol = symbol as ICartographicLineSymbol;
CLSymbol customSymbol = new CLSymbol();
customSymbol.Cap = (Kingo.Framework.LayerStyleConvert.XSDClass.esriLineCapStyle)((int)esriSymbol.Cap);
customSymbol.Color = GetColorArr(esriSymbol.Color);
customSymbol.Join = (Kingo.Framework.LayerStyleConvert.XSDClass.esriLineJoinStyle)((int)esriSymbol.Join);
customSymbol.MiterLimit = esriSymbol.MiterLimit;
customSymbol.Width = esriSymbol.Width;
newSymbol = customSymbol;
}
}
catch (Exception ex)
{
// LogAPI.Debug("ESRI线样式转自定义线样式失败:" + ex);
throw ex;
}
return newSymbol;
}
/// <summary>
/// 自定义点样式转换为ESRI点样式
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public IMarkerSymbol CustomMarkerSymbolToEsriMSymbol(MSymbol symbol)
{
IMarkerSymbol markerSymbol = null;
try
{
if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerMarkerSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerMarkerSymbol customSymbol = symbol as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerMarkerSymbol;
if (customSymbol == null || customSymbol.LayerCount <= 0) return null;
IMultiLayerMarkerSymbol esriSymbol = new ESRI.ArcGIS.Display.MultiLayerMarkerSymbolClass();
for (int i = 0; i < customSymbol.LayerCount; i++)
{
IMarkerSymbol symbolTemp = CustomMarkerSymbolToEsriMSymbolOne(customSymbol.GetLayer(i));
if (symbolTemp == null) continue;
esriSymbol.AddLayer(symbolTemp);
}
markerSymbol = esriSymbol;
}
else
{
markerSymbol = CustomMarkerSymbolToEsriMSymbolOne(symbol);
}
}
catch (Exception ex)
{
//LogAPI.Debug("自定义点样式转换为ESRI点样式失败:" + ex);
throw ex;
}
return markerSymbol;
}
private IMarkerSymbol CustomMarkerSymbolToEsriMSymbolOne(MSymbol symbol)
{
IMarkerSymbol markerSymbol = null;
try
{
if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.SMarkerSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.SMarkerSymbol customSymbol = symbol as Kingo.Framework.LayerStyleConvert.XSDClass.SMarkerSymbol;
if (customSymbol == null) return null;
ISimpleMarkerSymbol esriSymbol = new SimpleMarkerSymbolClass();
esriSymbol.Angle = customSymbol.Angle;
esriSymbol.Color = GetColor(customSymbol.Color);
esriSymbol.Outline = customSymbol.outline == null;
if (customSymbol.outline != null)
{
esriSymbol.OutlineColor = GetColor(customSymbol.outline.Color);
esriSymbol.OutlineSize = customSymbol.outline.Width;
}
esriSymbol.Size = customSymbol.Size;
esriSymbol.Style = (ESRI.ArcGIS.Display.esriSimpleMarkerStyle)((int)customSymbol.Style);
esriSymbol.XOffset = customSymbol.XOffset;
esriSymbol.YOffset = customSymbol.YOffset;
markerSymbol = esriSymbol;
}
else if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.AMarkSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.AMarkSymbol customSymbol = symbol as Kingo.Framework.LayerStyleConvert.XSDClass.AMarkSymbol;
if (customSymbol == null) return null;
IArrowMarkerSymbol esriSymbol = new ArrowMarkerSymbolClass();
esriSymbol.Angle = customSymbol.Angle;
esriSymbol.Color = GetColor(customSymbol.Color);
esriSymbol.Length = customSymbol.Length;
esriSymbol.Size = customSymbol.Size;
esriSymbol.Style = (ESRI.ArcGIS.Display.esriArrowMarkerStyle)((int)customSymbol.Style);
esriSymbol.Width = customSymbol.Width;
esriSymbol.XOffset = customSymbol.XOffset;
esriSymbol.YOffset = customSymbol.YOffset;
markerSymbol = esriSymbol;
}
else if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.PMarkSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.PMarkSymbol customSymbol = symbol as Kingo.Framework.LayerStyleConvert.XSDClass.PMarkSymbol;
if (customSymbol == null) return null;
IPictureMarkerSymbol esriSymbol = new PictureMarkerSymbolClass();
esriSymbol.Angle = customSymbol.Angle;
//esriSymbol.BackgroundColor = GetColor(customSymbol.BackgroundColor);
//esriSymbol.BitmapTransparencyColor = GetColor(customSymbol.BitmapTransparencyColor);
//esriSymbol.Color = GetColor(customSymbol.Color);
//esriSymbol.Picture = ConvertImg.Convert(Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetImageFromBase64(customSymbol.Picture));
//esriSymbol.Size = customSymbol.Size;
//esriSymbol.SwapForeGroundBackGroundColor = customSymbol.SwapForeGroundBackGroundColor;
esriSymbol.XOffset = customSymbol.XOffset;
esriSymbol.YOffset = customSymbol.YOffset;
markerSymbol = esriSymbol;
}
else if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.CMarkerSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.CMarkerSymbol customSymbol = symbol as Kingo.Framework.LayerStyleConvert.XSDClass.CMarkerSymbol;
if (customSymbol == null) return null;
ICharacterMarkerSymbol esriSymbol = new CharacterMarkerSymbolClass();
esriSymbol.Angle = customSymbol.Angle;
esriSymbol.CharacterIndex = customSymbol.CharacterIndex;
esriSymbol.Color = GetColor(customSymbol.Color);
esriSymbol.Font = GetIFontDisp(customSymbol.Font);
esriSymbol.Size = customSymbol.Size;
esriSymbol.XOffset = customSymbol.XOffset;
esriSymbol.YOffset = customSymbol.YOffset;
markerSymbol = esriSymbol;
}
}
catch (Exception ex)
{
//LogAPI.Debug("自定义点样式转换为ESRI点样式失败:" + ex);
throw ex;
}
return markerSymbol;
}
/// <summary>
/// ESRI点样式转自定义点样式
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public MSymbol EsriMarkerSymbolToCustomMSymbol(IMarkerSymbol symbol)
{
MSymbol markerSymbol = null;
try
{
if (symbol is ESRI.ArcGIS.Display.MultiLayerMarkerSymbol)
{
ESRI.ArcGIS.Display.MultiLayerMarkerSymbol esriSymbol = symbol as ESRI.ArcGIS.Display.MultiLayerMarkerSymbol;
if (esriSymbol == null) return null;
Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerMarkerSymbol customSymbol = new Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerMarkerSymbol();
for (int i = 0; i < esriSymbol.LayerCount; i++)
{
MSymbol symbolTemp = EsriMarkerSymbolToCustomMSymbolOne(esriSymbol.get_Layer(i));
if (symbolTemp == null) continue;
customSymbol.AddLayerMarkerSymbol(symbolTemp);
}
markerSymbol = customSymbol.lstMSymbol[0];
}
else
{
markerSymbol = EsriMarkerSymbolToCustomMSymbolOne(symbol);
}
}
catch (Exception ex)
{
//LogAPI.Debug("ESRI点样式转自定义点样式失败:" + ex);
throw ex;
}
return markerSymbol;
}
private MSymbol EsriMarkerSymbolToCustomMSymbolOne(IMarkerSymbol symbol)
{
MSymbol markerSymbol = null;
try
{
if (symbol is ESRI.ArcGIS.Display.ISimpleMarkerSymbol)
{
ESRI.ArcGIS.Display.ISimpleMarkerSymbol esriSymbol = symbol as ESRI.ArcGIS.Display.ISimpleMarkerSymbol;
if (esriSymbol == null) return null;
Kingo.Framework.LayerStyleConvert.XSDClass.SMarkerSymbol customSymbol = new SMarkerSymbol();
customSymbol.Angle = esriSymbol.Angle;
customSymbol.Color = GetColorArr(esriSymbol.Color);
customSymbol.outline = new OutLine()
{
Color = GetColorArr(esriSymbol.OutlineColor),
Width = (int)esriSymbol.OutlineSize
};
customSymbol.Size = esriSymbol.Size;
customSymbol.Style = (Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleMarkerStyle)((int)esriSymbol.Style);
customSymbol.XOffset = esriSymbol.XOffset;
customSymbol.YOffset = esriSymbol.YOffset;
markerSymbol = customSymbol;
}
else if (symbol is ESRI.ArcGIS.Display.IArrowMarkerSymbol)
{
ESRI.ArcGIS.Display.IArrowMarkerSymbol esriSymbol = symbol as ESRI.ArcGIS.Display.IArrowMarkerSymbol;
if (esriSymbol == null) return null;
//AMarkSymbol customSymbol = new AMarkSymbol();
//customSymbol.Angle = esriSymbol.Angle;
//customSymbol.Color = GetColorArr(esriSymbol.Color);
//customSymbol.Length = esriSymbol.Length;
//customSymbol.Size = esriSymbol.Size;
//customSymbol.Style = (Shape2KOTool.XSDClass.esriArrowMarkerStyle)((int)esriSymbol.Style);
//customSymbol.Width = esriSymbol.Width;
//customSymbol.XOffset = esriSymbol.XOffset;
//customSymbol.YOffset = esriSymbol.YOffset;
//markerSymbol = customSymbol;
PMarkSymbol customSymbol = new PMarkSymbol();
//customSymbol.Angle = esriSymbol.Angle;
customSymbol.Angle = 0;
customSymbol.ContentType = "image/png";
customSymbol.Height = esriSymbol.Size;
customSymbol.Width = esriSymbol.Size;
customSymbol.Size = esriSymbol.Size;
customSymbol.XOffset = esriSymbol.XOffset;
customSymbol.YOffset = esriSymbol.YOffset;
Bitmap imgRst = PreViewMarkerSymbol((ISymbol)symbol, Convert.ToInt32(esriSymbol.Size * 2), Convert.ToInt32(esriSymbol.Size * 2));
SetImagesPix(imgRst);
//for (int i = 0; i < imgRst.Width; i++)
//{
// for (int j = 0; j < imgRst.Height; j++)
// {
// Color color = imgRst.GetPixel(i, j);
// if (color.ToArgb() == SystemColors.Window.ToArgb())
// {
// imgRst.SetPixel(i, j, new Color() { });
// }
// }
//}
if (imgRst != null)
{
System.IO.MemoryStream imgStream = new System.IO.MemoryStream();
imgRst.Save(imgStream, System.Drawing.Imaging.ImageFormat.Png);
customSymbol.ImageData = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetBase64FromImage(Image.FromStream(imgStream));
imgRst.Dispose();
imgRst = null;
}
markerSymbol = customSymbol;
}
else if (symbol is ESRI.ArcGIS.Display.IPictureMarkerSymbol)
{
ESRI.ArcGIS.Display.IPictureMarkerSymbol esriSymbol = symbol as ESRI.ArcGIS.Display.IPictureMarkerSymbol;
if (esriSymbol == null) return null;
PMarkSymbol customSymbol = new PMarkSymbol();
customSymbol.Angle = esriSymbol.Angle;
customSymbol.ContentType = "image/png";
customSymbol.Height = esriSymbol.Size;
customSymbol.Width = esriSymbol.Size;
customSymbol.Size = esriSymbol.Size;
customSymbol.XOffset = esriSymbol.XOffset;
customSymbol.YOffset = esriSymbol.YOffset;
Bitmap imgRst = PreViewMarkerSymbol((ISymbol)symbol, Convert.ToInt32(esriSymbol.Size), Convert.ToInt32(esriSymbol.Size));
if (imgRst != null)
{
SetImagesPix(imgRst);
System.IO.MemoryStream imgStream = new System.IO.MemoryStream();
imgRst.Save(imgStream, System.Drawing.Imaging.ImageFormat.Png);
customSymbol.ImageData = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetBase64FromImage(Image.FromStream(imgStream));
imgRst.Dispose();
imgRst = null;
//customSymbol.ImageData = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetBase64FromImage(imgRst);
}
markerSymbol = customSymbol;
}
else if (symbol is ESRI.ArcGIS.Display.ICharacterMarkerSymbol)
{
ESRI.ArcGIS.Display.ICharacterMarkerSymbol esriSymbol = symbol as ESRI.ArcGIS.Display.ICharacterMarkerSymbol;
if (esriSymbol == null) return null;
//CMarkerSymbol customSymbol = new CMarkerSymbol();
//customSymbol.Angle = esriSymbol.Angle;
//customSymbol.CharacterIndex = esriSymbol.CharacterIndex;
//customSymbol.Color = GetColorArr(esriSymbol.Color);
//customSymbol.Font = GetESRIFont(esriSymbol.Font);
//customSymbol.Size = esriSymbol.Size;
//customSymbol.XOffset = esriSymbol.XOffset;
//customSymbol.YOffset = esriSymbol.YOffset;
PMarkSymbol customSymbol = new PMarkSymbol();
//customSymbol.Angle = esriSymbol.Angle;
customSymbol.ContentType = "image/png";
customSymbol.Height = esriSymbol.Size;
customSymbol.Width = esriSymbol.Size;
customSymbol.Size = esriSymbol.Size;
customSymbol.XOffset = esriSymbol.XOffset;
customSymbol.YOffset = esriSymbol.YOffset;
Bitmap imgRst = PreViewMarkerSymbol((ISymbol)symbol, Convert.ToInt32(esriSymbol.Size), Convert.ToInt32(esriSymbol.Size));
if (imgRst != null)
{
SetImagesPix(imgRst);
System.IO.MemoryStream imgStream = new System.IO.MemoryStream();
imgRst.Save("E:\\tempSymbol.png", System.Drawing.Imaging.ImageFormat.Png);
imgRst.Save(imgStream, System.Drawing.Imaging.ImageFormat.Png);
customSymbol.ImageData = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetBase64FromImage(Image.FromStream(imgStream));
//customSymbol.ImageData = Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetBase64FromImage(imgRst);
markerSymbol = customSymbol;
imgRst.Dispose();
imgRst = null;
}
}
}
catch (Exception ex)
{
// LogAPI.Debug("ESRI点样式转自定义点样式失败:" + ex);
throw ex;
}
return markerSymbol;
}
private void SetImagesPix(Bitmap imgRst)
{
for (int i = 0; i < imgRst.Width; i++)
{
for (int j = 0; j < imgRst.Height; j++)
{
Color color = imgRst.GetPixel(i, j);
if (color.ToArgb() == SystemColors.Window.ToArgb())
{
imgRst.SetPixel(i, j, new Color() { });
}
}
}
}
#region 获取ItemInfoDrawingInfo
public Kingo.Framework.LayerStyleConvert.XSDClass.Renderer GetItemInfoRenderer(ESRI.ArcGIS.Carto.IFeatureRenderer renderer)
{
Kingo.Framework.LayerStyleConvert.XSDClass.Renderer customRenderer = null;
if (renderer is ISimpleRenderer)
{
customRenderer = GetRenderer(renderer as ISimpleRenderer);
}
else if (renderer is IUniqueValueRenderer)
{
customRenderer = GetUniqueValueRenderer(renderer as IUniqueValueRenderer);
}
return customRenderer;
}
public Kingo.Framework.LayerStyleConvert.XSDClass.Renderer GetRenderer(ISimpleRenderer esriSimpleRenderer)
{
Symbol symbol = GetSymbol(esriSimpleRenderer.Symbol);
Kingo.Framework.LayerStyleConvert.XSDClass.SimpleRenderer simpleRender = new Kingo.Framework.LayerStyleConvert.XSDClass.SimpleRenderer();
if (symbol is FSymbol)
{
FSymbol fs = symbol as FSymbol;
if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol mSymbol = symbol as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol;
if (mSymbol.LayerCount > 1)
{
SFSymbol sfSymbol = new SFSymbol();
sfSymbol.Style = GetesriSimpleFillStyle(mSymbol);
sfSymbol.Color = GetLineColor(mSymbol.GetLayer(mSymbol.LayerCount - 1));
if (mSymbol.Outline is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol)
{
sfSymbol.Outline = (mSymbol.Outline as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol).GetLayer(0);
}
else
sfSymbol.Outline = mSymbol.Outline;
simpleRender.Symbol = sfSymbol;
}
else
{
simpleRender.Symbol = GetItemInfoSymbol(mSymbol.GetLayer(0));
}
}
else
{
simpleRender.Symbol = symbol;
}
}
else if (symbol is LSymbol)
{
simpleRender.Symbol = symbol;
}
else if (symbol is MSymbol)
{
simpleRender.Symbol = symbol;
}
simpleRender.Label = esriSimpleRenderer.Label;
simpleRender.Description = esriSimpleRenderer.Description;
return simpleRender;
}
public Kingo.Framework.LayerStyleConvert.XSDClass.Symbol GetUniqueSymbol(ISymbol esriSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.SimpleRenderer simpleRender = new Kingo.Framework.LayerStyleConvert.XSDClass.SimpleRenderer();
try
{
Symbol symbol = GetSymbol(esriSymbol);
if (symbol is FSymbol)
{
FSymbol fs = symbol as FSymbol;
if (symbol is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol mSymbol = symbol as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol;
if (mSymbol.LayerCount > 1)
{
SFSymbol sfSymbol = new SFSymbol();
sfSymbol.Style = GetesriSimpleFillStyle(mSymbol);
sfSymbol.Color = GetLineColor(mSymbol.GetLayer(mSymbol.LayerCount - 1));
if (mSymbol.Outline is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol)
{
sfSymbol.Outline = (mSymbol.Outline as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol).GetLayer(0);
}
else
sfSymbol.Outline = mSymbol.Outline;
simpleRender.Symbol = sfSymbol;
}
else
{
simpleRender.Symbol = GetItemInfoSymbol(mSymbol.GetLayer(0));
}
}
else
{
simpleRender.Symbol = symbol;
}
}
else if (symbol is LSymbol)
{
simpleRender.Symbol = symbol;
}
else if (symbol is MSymbol)
{
simpleRender.Symbol = symbol;
}
//simpleRender.Label = esriSimpleRenderer.Label;
//simpleRender.Description = esriSimpleRenderer.Description;
}
catch (Exception ex)
{
//LogAPI.Debug("获取唯一符号失败:" + ex);
throw ex;
}
return simpleRender.Symbol;
}
private int[] GetLineColor(Kingo.Framework.LayerStyleConvert.XSDClass.FSymbol fSymbol)
{
int[] color = new int[4];
if (fSymbol is LineFSymbol)
{
color = (fSymbol as LineFSymbol).Color;
}
else if (fSymbol is PFSymbol)
{
}
else if (fSymbol is MFSymbol)
{
color = (fSymbol as MFSymbol).Color;
}
else if (fSymbol is SFSymbol)
{
color = (fSymbol as SFSymbol).Color;
}
return color;
}
private Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle GetesriSimpleFillStyle(Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerFillSymbol mSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSSolid;
//if (mSymbol.LayerCount >= 2)
//{
bool isExistHorizontal = false, isExistVertical = false, isExistBackwardDiagonal = false, isExistForwardDiagonal = false;
for (int i = 0; i < mSymbol.LayerCount; i++)
{
if (mSymbol.GetLayer(i) is LineFSymbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle tempStyle = GetLineFillStyle(mSymbol.GetLayer(i) as LineFSymbol);
switch (tempStyle)
{
case Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSBackwardDiagonal:
isExistBackwardDiagonal = true;
break;
case Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSCross:
break;
case Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSDiagonalCross:
break;
case Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSForwardDiagonal:
isExistForwardDiagonal = true;
break;
case Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSHollow:
break;
case Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSHorizontal:
isExistHorizontal = true;
break;
case Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSSolid:
break;
case Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSVertical:
isExistVertical = true;
break;
default:
break;
}
}
}
if (isExistHorizontal && isExistVertical)
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSCross;
}
else if (isExistBackwardDiagonal && isExistForwardDiagonal)
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSDiagonalCross;
}
else if (mSymbol.GetLayer(mSymbol.LayerCount - 1) is LineFSymbol)
{
rstStyle = GetLineFillStyle(mSymbol.GetLayer(mSymbol.LayerCount - 1) as LineFSymbol);
}
else if (isExistBackwardDiagonal)
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSBackwardDiagonal;
}
else if (isExistForwardDiagonal)
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSForwardDiagonal;
}
else if (isExistHorizontal)
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSHorizontal;
}
else if (isExistVertical)
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSVertical;
}
else
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSSolid;
}
//}
//else
//{
// LineFSymbol lastFSymbol = null;
// bool isExistLine = false;
// for (int i = 0; i < mSymbol.LayerCount; i++)
// {
// if (mSymbol.GetLayer(i) is LineFSymbol)
// {
// isExistLine = true;
// lastFSymbol = mSymbol.GetLayer(i) as LineFSymbol;
// }
// }
// if (isExistLine)
// {
// rstStyle = GetLineFillStyle(lastFSymbol);
// }
// else
// {
// rstStyle = Shape2KOTool.XSDClass.esriSimpleFillStyle.esriSFSSolid;
// }
//}
return rstStyle;
}
private Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle GetLineFillStyle(LineFSymbol symbol)
{
Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSSolid;
double angle = symbol.Angle;
if (angle == 0 || Math.Abs(angle) == 180 || Math.Abs(angle) == 360)
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSHorizontal;
}
else if (Math.Abs(angle) == 90 || Math.Abs(angle) == 270)
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSVertical;
}
else if (angle == 45 || angle == 225 || angle == -135 || angle == -315)
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSBackwardDiagonal;
}
else if (angle == 135 || angle == 315 || angle == -45 || angle == -225)
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSForwardDiagonal;
}
else
{
rstStyle = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSSolid;
}
return rstStyle;
}
private Symbol GetItemInfoSymbol(FSymbol symbol)
{
Symbol rstSymbol = null;
if (symbol is PFSymbol)
{
PFSymbol pSymbol = symbol as PFSymbol;
if (pSymbol.Outline is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol)
{
pSymbol.Outline = (pSymbol.Outline as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol).GetLayer(0);
}
rstSymbol = pSymbol;
}
else if (symbol is LineFSymbol)
{
SFSymbol sfSymbol = new SFSymbol();
LineFSymbol pSymbol = symbol as LineFSymbol;
sfSymbol.Style = GetLineFillStyle(pSymbol);
sfSymbol.Color = pSymbol.Color;
sfSymbol.Outline = pSymbol.Outline;
//if (pSymbol.Outline is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol)
//{
// pSymbol.Outline = (pSymbol.Outline as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol).GetLayer(0);
// sfSymbol.Outline = (pSymbol.Outline as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol).GetLayer(0);
//}
rstSymbol = sfSymbol;
}
else if (symbol is MFSymbol)
{
MFSymbol pSymbol = symbol as MFSymbol;
if (pSymbol.Outline is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol)
{
pSymbol.Outline = (pSymbol.Outline as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol).GetLayer(0);
}
rstSymbol = pSymbol;
}
else if (symbol is SFSymbol)
{
SFSymbol pSymbol = symbol as SFSymbol;
if (pSymbol.Outline is Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol)
{
pSymbol.Outline = (pSymbol.Outline as Kingo.Framework.LayerStyleConvert.XSDClass.MultiLayerLineSymbol).GetLayer(0);
}
rstSymbol = pSymbol;
}
return rstSymbol;
}
#endregion
public stdole.IFontDisp GetIFontDisp(ESRIFont font)
{
stdole.StdFontClass fontClass = new stdole.StdFontClass();
fontClass.Name = font.Family;
fontClass.Size = font.Size;
//fontClass.Weight =Convert. font.Weight;
return (stdole.IFontDisp)fontClass;
}
public ESRIFont GetESRIFont(stdole.IFontDisp font)
{
if (font == null) return new ESRIFont();
return new ESRIFont()
{
Size = (int)font.Size,
Family = font.Name
};
}
public Kingo.Framework.LayerStyleConvert.XSDClass.Symbol EsriSymbolToCustomSymbol(ESRI.ArcGIS.Display.IFillSymbol esriSymbol)
{
if (esriSymbol == null) return null;
Symbol customSymbol = null;
//if (esriSymbol is ESRI.ArcGIS.Display.SimpleFillSymbolClass)
//{
// ESRI.ArcGIS.Display.IFillSymbol fillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
SFSymbol sfSymbol = new SFSymbol();
Color color = System.Drawing.ColorTranslator.FromWin32(esriSymbol.Color.RGB);
sfSymbol.Color = new int[] { color.A, color.R, color.G, color.B };
sfSymbol.Style = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleFillStyle.esriSFSSolid;
if (esriSymbol.Outline != null)
{
SLSymbol slSymbol = new SLSymbol();
color = ColorTranslator.FromWin32(esriSymbol.Outline.Color.RGB);
slSymbol.Color = new int[] { color.A, color.R, color.G, color.B };
slSymbol.Width = esriSymbol.Outline.Width;
slSymbol.Style = Kingo.Framework.LayerStyleConvert.XSDClass.esriSimpleLineStyle.esriSLSSolid;
sfSymbol.Outline = slSymbol;
}
customSymbol = sfSymbol;
//}
return customSymbol;
}
public Image GetSymbolImg()
{
return null;
//stdole.IPictureDisp picture = this.axSymbologyControl.GetStyleClass(this.axSymbologyControl.StyleClass).PreviewItem(pStyleGalleryItem, this.picView.Width, this.picView.Height);
//System.Drawing.Image image = System.Drawing.Image.FromHbitmap(new System.IntPtr(picture.Handle));
//this.picView.Image = image;
}
public ESRI.ArcGIS.Display.IColor GetColor(int[] colorInt, bool isNullColor = false)
{
ESRI.ArcGIS.Display.IColor color = null;
if (colorInt != null && colorInt.Length > 3)
{
if (colorInt[3] == 0)
isNullColor = true;
color = new ESRI.ArcGIS.Display.RgbColorClass()
{
Red = colorInt[0],
Green = colorInt[1],
Blue = colorInt[2],
NullColor = isNullColor
};
}
return color;
}
public int[] GetColorArr(ESRI.ArcGIS.Display.IColor colorArc)
{
if (colorArc == null) return new int[4];
Color color = System.Drawing.ColorTranslator.FromWin32(colorArc.RGB);
return Kingo.Framework.LayerStyleConvert.XSDClass.CommonMethod.GetInt4ColorFromColor(color);
}
/// <summary>
/// 获取渲染
/// </summary>
/// <param name="customSymbol">样式</param>
/// <param name="symbolType">图形类型</param>
/// <returns></returns>
public ISimpleRenderer GetSimpleRenderer(Kingo.Framework.LayerStyleConvert.XSDClass.Symbol customSymbol, SymbolTypeEnum symbolType)
{
ISymbol symbolDefault = null;
if (customSymbol == null)
symbolDefault = GetDefaultSymbol(symbolType);
else
symbolDefault = CustomSymbolToEsriSymbol(customSymbol) as ISymbol;
// }
//简单填充符号
ISimpleRenderer simpleRender = new SimpleRendererClass();
simpleRender.Symbol = symbolDefault as ISymbol;
simpleRender.Label = "";
simpleRender.Description = "简单渲染";
return simpleRender;
}
/// <summary>
/// 获取唯一值图层渲染
/// </summary>
/// <param name="rander"></param>
/// <param name="symbolType"></param>
/// <returns></returns>
public IUniqueValueRenderer GetUniqueValueRenderer(Kingo.Framework.LayerStyleConvert.XSDClass.Renderer rander, SymbolTypeEnum symbolType)
{
Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer uniqueRaner = (rander as Framework.LayerStyleConvert.XSDClass.UniqueValueRenderer);
Symbol customSymbol = uniqueRaner.DefaultSymbol;
ISymbol symbolDefault = null;
if (customSymbol == null)
symbolDefault = GetDefaultSymbol(symbolType);
else
symbolDefault = CustomSymbolToEsriSymbol(customSymbol) as ISymbol;
//填充符号
IUniqueValueRenderer uniqueValueRender = new UniqueValueRendererClass();
uniqueValueRender.UseDefaultSymbol = false;
uniqueValueRender.DefaultSymbol= symbolDefault as ISymbol;
uniqueValueRender.DefaultLabel = uniqueRaner.DefaultLabel;
uniqueValueRender.FieldCount = 1;
uniqueValueRender.set_Field(0, uniqueRaner.Field1);
//uniqueValueRender.set_Field(1, uniqueRaner.Field2);
//uniqueValueRender.set_Field(2, uniqueRaner.Field3);
uniqueValueRender.FieldDelimiter = uniqueRaner.FieldDelimiter;
for (int i = 0; i < uniqueRaner.UniqueValueInfos.Count; i++)
{
Kingo.Framework.LayerStyleConvert.XSDClass.UniqueValueInfo unqiueInfo = uniqueRaner.UniqueValueInfos[i];
uniqueValueRender.AddValue(unqiueInfo.Value, "", CustomSymbolToEsriSymbol(unqiueInfo.Symbol));
uniqueValueRender.Label[unqiueInfo.Value] = unqiueInfo.Label;
uniqueValueRender.Description[unqiueInfo.Value] = unqiueInfo.Description;
}
return uniqueValueRender;
}
#region 默认样式
public ISymbol GetDefaultSymbol(SymbolTypeEnum symbolType)
{
if (symbolType == SymbolTypeEnum.Point)
{
return DefaultMarkerSymbol() as ISymbol;
}
else if (symbolType == SymbolTypeEnum.Line)
{
return DefaultLineSymbol() as ISymbol;
}
else
{
return DefaultFillSymbol() as ISymbol;
}
}
/// <summary>
/// 获取默认填充样式
/// </summary>
/// <returns></returns>
public IFillSymbol DefaultFillSymbol()
{
ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
simpleFillSymbol.Style = ESRI.ArcGIS.Display.esriSimpleFillStyle.esriSFSSolid;
simpleFillSymbol.Color = getRGB(0, 255, 255);
//创建边线符号
ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
simpleLineSymbol.Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid;
simpleLineSymbol.Color = getRGB(255, 0, 0);
simpleFillSymbol.Outline = simpleLineSymbol;
return simpleFillSymbol;
}
/// <summary>
/// 获取默认线样式
/// </summary>
/// <returns></returns>
public ILineSymbol DefaultLineSymbol()
{
ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
simpleLineSymbol.Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid;
simpleLineSymbol.Color = getRGB(255, 0, 0);
return simpleLineSymbol;
}
/// <summary>
/// 获取默认点样式
/// </summary>
/// <returns></returns>
public IMarkerSymbol DefaultMarkerSymbol()
{
IMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass();
markerSymbol.Angle = 0;
markerSymbol.Color = getRGB(255, 0, 0);
markerSymbol.Size = 4;
return markerSymbol;
}
private IRgbColor getRGB(int r, int g, int b)
{
IRgbColor pColor;
pColor = new RgbColorClass();
pColor.Red = r;
pColor.Green = g;
pColor.Blue = b;
return pColor;
}
#endregion
#region 标注样式
/// <summary>
///标注ESRI样式转自定义样式
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public TSSymbol EsriTextSymbolToCustomTSSymbol(ESRI.ArcGIS.Display.ISymbol symbol)
{
TSSymbol customSymbol = new TSSymbol();
try
{
ESRI.ArcGIS.Display.TextSymbol textSymbol = symbol as ESRI.ArcGIS.Display.TextSymbol;
if (textSymbol == null) return customSymbol;
customSymbol.Angle = (int)textSymbol.Angle;
customSymbol.Color = GetColorArr(textSymbol.Color);
customSymbol.Font = GetESRIFont(textSymbol.Font);
customSymbol.Kerning = textSymbol.Kerning;
customSymbol.RightToLeft = textSymbol.RightToLeft;
customSymbol.HorizontalAlignment = textSymbol.HorizontalAlignment.ToString();
customSymbol.VerticalAlignment = textSymbol.VerticalAlignment.ToString();
customSymbol.Xoffset = (int)textSymbol.ShadowXOffset;
customSymbol.Yoffset = (int)textSymbol.ShadowYOffset;
customSymbol.HaloSize = textSymbol.Size.ToString();
}
catch (Exception ex)
{
throw ex;
}
return customSymbol;
}
/// <summary>
/// 标注自定义样式转ESRI样式
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public ESRI.ArcGIS.Display.TextSymbol CustomTSSymbolToEsriTextSymbol(TSSymbol symbol)
{
ESRI.ArcGIS.Display.TextSymbol esriSymbol = new TextSymbol();
try
{
esriSymbol.Angle = symbol.Angle;
esriSymbol.Color = GetColor(symbol.Color);
esriSymbol.Font = GetIFontDisp(symbol.Font);
esriSymbol.Kerning = symbol.Kerning;
esriSymbol.RightToLeft = symbol.RightToLeft;
esriSymbol.ShadowXOffset = symbol.Xoffset;
esriSymbol.ShadowYOffset = symbol.Yoffset;
object obj = GetesriTextHorizontalAlignmentByName(typeof(esriTextHorizontalAlignment), symbol.HorizontalAlignment);
esriSymbol.HorizontalAlignment = obj == null ? esriTextHorizontalAlignment.esriTHACenter : (esriTextHorizontalAlignment)obj;
obj = GetesriTextHorizontalAlignmentByName(typeof(esriTextVerticalAlignment), symbol.VerticalAlignment);
esriSymbol.VerticalAlignment = obj == null ? esriTextVerticalAlignment.esriTVACenter : (esriTextVerticalAlignment)obj;
}
catch (Exception ex)
{
throw ex;
}
return esriSymbol;
}
private object GetesriTextHorizontalAlignmentByName(Type type, string name)
{
string[] enumNames = Enum.GetNames(type);
object objRst = null;
for (int i = 0; i < enumNames.Length; i++)
{
if (enumNames[i] == name)
{
objRst = Enum.Parse(type, name, true);
break;
}
}
return objRst;
}
#endregion
}
public class ConvertImg : System.Windows.Forms.AxHost
{
private ConvertImg()
: base(null)
{
}
public static stdole.IPictureDisp Convert(System.Drawing.Image image)
{
return (stdole.IPictureDisp)System.
Windows.Forms.AxHost
.GetIPictureDispFromPicture(image);
}
public static Image IPictureDispToImage(stdole.IPictureDisp pictureDisp)
{
return GetPictureFromIPictureDisp(pictureDisp);
}
}
/// <summary>
/// 图形类型
/// </summary>
public enum SymbolTypeEnum
{
Point = 0,
Line = 1,
Fill = 2
}
}