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

1638 lines
70 KiB

6 months ago
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using Kingo.Plugin.ShapeToKOApp.XSDClass;
using stdole;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Kingo.Plugin.ShapeToKOApp.KoDataBase
{
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 XSDClass.Renderer GetRenderer(ESRI.ArcGIS.Carto.IFeatureRenderer renderer)
{
XSDClass.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 XSDClass.Renderer GetSimpleRenderer(ISimpleRenderer esriSimpleRenderer)
{
XSDClass.SimpleRenderer customRenderer = new XSDClass.SimpleRenderer();
customRenderer.Symbol = GetSymbol(esriSimpleRenderer.Symbol);
customRenderer.Label = esriSimpleRenderer.Label;
customRenderer.Description = esriSimpleRenderer.Description;
return customRenderer;
}
public XSDClass.Renderer GetUniqueValueRenderer(IUniqueValueRenderer esriUniqueValueRenderer)
{
XSDClass.UniqueValueRenderer customRenderer = new 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<XSDClass.UniqueValueInfo> lstUniqueValueInfo = new List<XSDClass.UniqueValueInfo>();
XSDClass.UniqueValueInfo unqiueInfo = null;
for (int i = 0; i < esriUniqueValueRenderer.ValueCount; i++)
{
unqiueInfo = new XSDClass.UniqueValueInfo();
unqiueInfo.Value = esriUniqueValueRenderer.get_Value(i);
unqiueInfo.Label = esriUniqueValueRenderer.get_Label(unqiueInfo.Value);
unqiueInfo.Description = esriUniqueValueRenderer.get_Description(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 XSDClass.Symbol GetSymbol(ESRI.ArcGIS.Display.ISymbol symbol)
{
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(XSDClass.Symbol symbol)
{
ESRI.ArcGIS.Display.ISymbol esriSymbol = null;
try
{
if (symbol is XSDClass.FSymbol)
{
XSDClass.FSymbol fsSymbol = symbol as XSDClass.FSymbol;
esriSymbol = (ISymbol)CustomFillToEsriFill(fsSymbol);
}
else if (symbol is XSDClass.LSymbol)
{
LSymbol lSymbol = symbol as LSymbol;
esriSymbol = (ISymbol)CustomLineSymbolToEsriLSymbol(lSymbol);
}
else if (symbol is 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 XSDClass.FSymbol EsriFillSymbolToCustomSymbol(ESRI.ArcGIS.Display.IFillSymbol esriSymbol)
{
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)
{
XSDClass.MultiLayerFillSymbol customMulti = new 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.NullColor)
{
customMulti.Color = new int[4];
}
else
{
if (esriMulti.Color == null)
{
customMulti.Color = GetColorArr(esriMulti.Outline.Color);
}
else
customMulti.Color = GetColorArr(esriMulti.Color);
}
symbolCustom = customMulti;
}
else
{
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.Mobile.Shape2KOTool.XSDClass.CommonMethod.GetBase64FromImage(Image.FromStream(imgStream));
symbolPicCustom.ImageData = 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 XSDClass.FSymbol EsriFillSymbolToCustomSymbolOne(ESRI.ArcGIS.Display.IFillSymbol esriSymbol)
{
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 = (XSDClass.esriMarkerFillStyle)((int)esriMarkerFill.Style);
symbolCustom = customSymbol;
}
}
else if (esriSymbol is ILineFillSymbol)
{
ILineFillSymbol esriLineFill = esriSymbol as ILineFillSymbol;
if (esriLineFill != null)
{
XSDClass.LineFSymbol symbolLineCustom = new XSDClass.LineFSymbol();
symbolLineCustom.Angle = esriLineFill.Angle;
Color color = System.Drawing.ColorTranslator.FromWin32(esriSymbol.Color.RGB);
symbolLineCustom.Color = 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)
{
XSDClass.SFSymbol symbolSimpleCustom = new SFSymbol();
Color color = System.Drawing.ColorTranslator.FromWin32(esriSymbol.Color.RGB);
symbolSimpleCustom.Color = XSDClass.CommonMethod.GetInt4ColorFromColor(color);
if (esriSymbol.Color.NullColor)
{
symbolSimpleCustom.Color = new int[4];
}
symbolSimpleCustom.Outline = EsriLSymbolToCustomLineSymbol(esriSimpleFill.Outline);
symbolSimpleCustom.Style = (XSDClass.esriSimpleFillStyle)((int)esriSimpleFill.Style);
symbolCustom = symbolSimpleCustom;
}
}
else if (esriSymbol is IPictureFillSymbol)
{
IPictureFillSymbol esriPictureFill = esriSymbol as IPictureFillSymbol;
if (esriPictureFill != null)
{
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 = 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(XSDClass.FSymbol fSymbol)
{
ESRI.ArcGIS.Display.IFillSymbol fillSymbol = null;
try
{
if (fSymbol is XSDClass.MultiLayerFillSymbol)
{
XSDClass.MultiLayerFillSymbol cutomMultiFill = fSymbol as 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(XSDClass.FSymbol fSymbol)
{
ESRI.ArcGIS.Display.IFillSymbol fillSymbol = null;
try
{
if (fSymbol is XSDClass.SFSymbol)
{
XSDClass.SFSymbol sfSymbol = fSymbol as 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 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 XSDClass.PFSymbol)
{
PFSymbol pictureFillSymbol = fSymbol as PFSymbol;
PictureFillSymbol esriPicFillSymbol = new PictureFillSymbol();
esriPicFillSymbol.Angle = pictureFillSymbol.Angle;
esriPicFillSymbol.Outline = CustomLineSymbolToEsriLSymbol(pictureFillSymbol.Outline);
Image img = XSDClass.CommonMethod.GetImageFromBase64(pictureFillSymbol.ImageData);
esriPicFillSymbol.Picture = ConvertImg.Convert(img);
esriPicFillSymbol.XScale = pictureFillSymbol.Xscale;
esriPicFillSymbol.YScale = pictureFillSymbol.Yscale;
fillSymbol = esriPicFillSymbol;
}
else if (fSymbol is 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);
throw ex;
}
return fillSymbol;
}
/// <summary>
/// 自定义线样式转ESRI线样式
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
public ILineSymbol CustomLineSymbolToEsriLSymbol(LSymbol symbol)
{
ILineSymbol lineSymbol = null;
try
{
if (symbol is XSDClass.MultiLayerLineSymbol)
{
XSDClass.MultiLayerLineSymbol multiLineSymbol = symbol as 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 = 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;
XSDClass.MultiLayerLineSymbol customSymbol = new 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 = (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 = 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 = (XSDClass.esriLineCapStyle)((int)esriSymbol.Cap);
customSymbol.Color = GetColorArr(esriSymbol.Color);
customSymbol.Join = (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 XSDClass.MultiLayerMarkerSymbol)
{
XSDClass.MultiLayerMarkerSymbol customSymbol = symbol as 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 XSDClass.SMarkerSymbol)
{
XSDClass.SMarkerSymbol customSymbol = symbol as 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 XSDClass.AMarkSymbol)
{
XSDClass.AMarkSymbol customSymbol = symbol as 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 XSDClass.PMarkSymbol)
{
XSDClass.PMarkSymbol customSymbol = symbol as 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.Mobile.Shape2KOTool.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 XSDClass.CMarkerSymbol)
{
XSDClass.CMarkerSymbol customSymbol = symbol as 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;
XSDClass.MultiLayerMarkerSymbol customSymbol = new 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;
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 = (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 = 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 =XSDClass.CommonMethod.GetBase64FromImage(Image.FromStream(imgStream));
imgRst.Dispose();
imgRst = null;
//customSymbol.ImageData = Kingo.Mobile.Shape2KOTool.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 =XSDClass.CommonMethod.GetBase64FromImage(Image.FromStream(imgStream));
//customSymbol.ImageData = Kingo.Mobile.Shape2KOTool.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 XSDClass.Renderer GetItemInfoRenderer(ESRI.ArcGIS.Carto.IFeatureRenderer renderer)
{
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 XSDClass.Renderer GetRenderer(ISimpleRenderer esriSimpleRenderer)
{
Symbol symbol = GetSymbol(esriSimpleRenderer.Symbol);
XSDClass.SimpleRenderer simpleRender = new XSDClass.SimpleRenderer();
if (symbol is FSymbol)
{
FSymbol fs = symbol as FSymbol;
if (symbol is XSDClass.MultiLayerFillSymbol)
{
XSDClass.MultiLayerFillSymbol mSymbol = symbol as 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 XSDClass.MultiLayerLineSymbol)
{
sfSymbol.Outline = (mSymbol.Outline as 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 XSDClass.Symbol GetUniqueSymbol(ISymbol esriSymbol)
{
XSDClass.SimpleRenderer simpleRender = new XSDClass.SimpleRenderer();
try
{
Symbol symbol = GetSymbol(esriSymbol);
if (symbol is FSymbol)
{
FSymbol fs = symbol as FSymbol;
if (symbol is XSDClass.MultiLayerFillSymbol)
{
XSDClass.MultiLayerFillSymbol mSymbol = symbol as 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 XSDClass.MultiLayerLineSymbol)
{
sfSymbol.Outline = (mSymbol.Outline as 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(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 XSDClass.esriSimpleFillStyle GetesriSimpleFillStyle(XSDClass.MultiLayerFillSymbol mSymbol)
{
XSDClass.esriSimpleFillStyle rstStyle = 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)
{
XSDClass.esriSimpleFillStyle tempStyle = GetLineFillStyle(mSymbol.GetLayer(i) as LineFSymbol);
switch (tempStyle)
{
case XSDClass.esriSimpleFillStyle.esriSFSBackwardDiagonal:
isExistBackwardDiagonal = true;
break;
case XSDClass.esriSimpleFillStyle.esriSFSCross:
break;
case XSDClass.esriSimpleFillStyle.esriSFSDiagonalCross:
break;
case XSDClass.esriSimpleFillStyle.esriSFSForwardDiagonal:
isExistForwardDiagonal = true;
break;
case XSDClass.esriSimpleFillStyle.esriSFSHollow:
break;
case XSDClass.esriSimpleFillStyle.esriSFSHorizontal:
isExistHorizontal = true;
break;
case XSDClass.esriSimpleFillStyle.esriSFSSolid:
break;
case XSDClass.esriSimpleFillStyle.esriSFSVertical:
isExistVertical = true;
break;
default:
break;
}
}
}
if (isExistHorizontal && isExistVertical)
{
rstStyle = XSDClass.esriSimpleFillStyle.esriSFSCross;
}
else if (isExistBackwardDiagonal && isExistForwardDiagonal)
{
rstStyle = 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 = XSDClass.esriSimpleFillStyle.esriSFSBackwardDiagonal;
}
else if (isExistForwardDiagonal)
{
rstStyle = XSDClass.esriSimpleFillStyle.esriSFSForwardDiagonal;
}
else if (isExistHorizontal)
{
rstStyle = XSDClass.esriSimpleFillStyle.esriSFSHorizontal;
}
else if (isExistVertical)
{
rstStyle = XSDClass.esriSimpleFillStyle.esriSFSVertical;
}
else
{
rstStyle = XSDClass.esriSimpleFillStyle.esriSFSSolid;
}
return rstStyle;
}
private XSDClass.esriSimpleFillStyle GetLineFillStyle(LineFSymbol symbol)
{
XSDClass.esriSimpleFillStyle rstStyle = XSDClass.esriSimpleFillStyle.esriSFSSolid;
double angle = symbol.Angle;
if (angle == 0 || Math.Abs(angle) == 180 || Math.Abs(angle) == 360)
{
rstStyle = XSDClass.esriSimpleFillStyle.esriSFSHorizontal;
}
else if (Math.Abs(angle) == 90 || Math.Abs(angle) == 270)
{
rstStyle = XSDClass.esriSimpleFillStyle.esriSFSVertical;
}
else if (angle == 45 || angle == 225 || angle == -135 || angle == -315)
{
rstStyle = XSDClass.esriSimpleFillStyle.esriSFSBackwardDiagonal;
}
else if (angle == 135 || angle == 315 || angle == -45 || angle == -225)
{
rstStyle = XSDClass.esriSimpleFillStyle.esriSFSForwardDiagonal;
}
else
{
rstStyle = 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 XSDClass.MultiLayerLineSymbol)
{
pSymbol.Outline = (pSymbol.Outline as 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;
rstSymbol = sfSymbol;
}
else if (symbol is MFSymbol)
{
MFSymbol pSymbol = symbol as MFSymbol;
if (pSymbol.Outline is XSDClass.MultiLayerLineSymbol)
{
pSymbol.Outline = (pSymbol.Outline as XSDClass.MultiLayerLineSymbol).GetLayer(0);
}
rstSymbol = pSymbol;
}
else if (symbol is SFSymbol)
{
SFSymbol pSymbol = symbol as SFSymbol;
if (pSymbol.Outline is XSDClass.MultiLayerLineSymbol)
{
pSymbol.Outline = (pSymbol.Outline as XSDClass.MultiLayerLineSymbol).GetLayer(0);
}
rstSymbol = pSymbol;
}
return rstSymbol;
}
#endregion
public stdole.IFontDisp GetIFontDisp(ESRIFont font)
{
//StdFontClass fontClass = new StdFontClass();
//fontClass.Name = font.Family;
//fontClass.Size = font.Size;
// return (stdole.IFontDisp)fontClass;
return null;
}
public ESRIFont GetESRIFont(stdole.IFontDisp font)
{
if (font == null) return new ESRIFont();
return new ESRIFont()
{
Size = (int)font.Size,
Family = font.Name
};
}
public XSDClass.Symbol EsriSymbolToCustomSymbol(ESRI.ArcGIS.Display.IFillSymbol esriSymbol)
{
if (esriSymbol == null) return null;
Symbol customSymbol = null;
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 = 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 = XSDClass.esriSimpleLineStyle.esriSLSSolid;
sfSymbol.Outline = slSymbol;
}
customSymbol = sfSymbol;
return customSymbol;
}
public ESRI.ArcGIS.Display.IColor GetColor(int[] colorInt, bool isNullColor = false)
{
ESRI.ArcGIS.Display.IColor color = null;
if (colorInt != null && colorInt.Length > 3)
{
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 XSDClass.CommonMethod.GetInt4ColorFromColor(color);
}
/// <summary>
/// 获取渲染
/// </summary>
/// <param name="customSymbol">样式</param>
/// <param name="symbolType">图形类型</param>
/// <returns></returns>
public ISimpleRenderer GetSimpleRenderer(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;
}
#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 =System.Enum.GetNames(type);
object objRst = null;
for (int i = 0; i < enumNames.Length; i++)
{
if (enumNames[i] == name)
{
objRst = System.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
}
}