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

625 lines
22 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Mask;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Display;
using KGIS.Plugin.LayerProperty.Interface;
using KGIS.Plugin.LayerProperty.Utils;
namespace KGIS.Plugin.LayerProperty.View.UC_Controls
{
public class UCRasterStretchRenderer : XtraUserControl, IPropertyPage
{
private List<IPropertyPage> ucList;
private ISymbol m_SelectSymbol;
private IRasterRenderer m_CurrentRenderer;
private IRasterLayer m_CurrentLayer;
private IRasterStretchColorRampRenderer m_LyrRenderer;
private IPropertyPage m_UCRasterStretchSet;
private bool hasInitColorRamp;
private System.EventHandler editorChanged;
private bool isDirty;
private IContainer components;
private LabelControl labelControl1;
private UCColorRamps ucColorRamps1;
private LabelControl labelControl2;
private ComboBoxEdit cboBands;
private LabelControl labelControl3;
private LabelControl lblHigh;
private LabelControl labelControl5;
private TextEdit txtHigh;
private TextEdit txtMedium;
private LabelControl lblLow;
private TextEdit txtLow;
private PanelControl panelControl1;
private LabelControl labelControl6;
private CheckEdit chkDisplayBackground;
private ColorEdit colorEdit1;
private LabelControl labelControl9;
private TextEdit textEdit3;
private CheckEdit chkUseHillShade;
private LabelControl labelControl10;
private TextEdit txtZScale;
private LabelControl labelControl11;
private ColorEdit colorEdit2;
private PictureEdit pnlCtrl;
event System.EventHandler IPropertyPage.EditorChanged
{
add
{
this.editorChanged = (System.EventHandler)Delegate.Combine(this.editorChanged, value);
}
remove
{
this.editorChanged = (System.EventHandler)Delegate.Remove(this.editorChanged, value);
}
}
public bool IsPageDirty
{
get
{
return this.isDirty;
}
set
{
this.isDirty = value;
}
}
public UCRasterStretchRenderer()
{
this.InitializeComponent();
this.ucList = new List<IPropertyPage>();
}
private ISymbol GetSymbolByColorRamp(IColorRamp pColorRamp)
{
return new ColorRampSymbolClass
{
ColorRamp = pColorRamp
} as ISymbol;
}
private void ucColorRamps1_SelectIndexChanged(IColorRamp pColorRamp, string name)
{
this.m_SelectSymbol = this.GetSymbolByColorRamp(pColorRamp);
this.RefreshSymbolPic();
this.InvokeEditValueChanged(null, null);
}
private int GetBandIndex(string band)
{
if (band != null)
{
if (band == "Band_1")
{
return 0;
}
if (band == "Band_2")
{
return 1;
}
}
return 2;
}
private string GetBand(int index)
{
switch (index)
{
case 0:
return "Band_1";
case 1:
return "Band_2";
default:
return "Band_3";
}
}
public void InitForm()
{
if (this.m_CurrentLayer == null)
{
return;
}
this.InitColorRamp();
this.GetColorInfo();
this.AddRasterStretchSet();
}
private void InitColorRamp()
{
if (!this.hasInitColorRamp)
{
this.ucColorRamps1.InitColorRamp();
}
this.hasInitColorRamp = true;
this.m_LyrRenderer = (this.m_CurrentLayer.Renderer as IRasterStretchColorRampRenderer);
this.m_CurrentRenderer = this.m_CurrentLayer.Renderer;
IRasterBandCollection rasterBandCollection = this.m_CurrentLayer.Raster as IRasterBandCollection;
if (rasterBandCollection.Count < 3)
{
this.cboBands.SelectedIndex = 0;
this.cboBands.Enabled = false;
}
else
{
this.cboBands.Enabled = true;
}
IRasterStretch rasterStretch = null;
if (this.m_LyrRenderer == null)
{
this.m_LyrRenderer = new RasterStretchColorRampRendererClass();
this.m_LyrRenderer.BandIndex = 0;
this.m_LyrRenderer.LabelHigh = "High : 255";
this.m_LyrRenderer.LabelLow = "Low : 0";
this.m_LyrRenderer.LabelMedium = "";
rasterStretch = (this.m_LyrRenderer as IRasterStretch);
rasterStretch.Invert = false;
rasterStretch.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
rasterStretch.StandardDeviationsParam = 2.0;
((IRasterRenderer)this.m_LyrRenderer).Update();
}
if (this.m_LyrRenderer.ColorRamp == null)
{
this.ucColorRamps1.InitColorRamp("Black to White");
}
else
{
this.ucColorRamps1.InitColorRamp(this.m_LyrRenderer.ColorRamp.Name);
}
IColorRamp selectColorRamp = this.ucColorRamps1.GetSelectColorRamp();
this.m_SelectSymbol = this.GetSymbolByColorRamp(selectColorRamp);
this.m_LyrRenderer.ColorRamp = selectColorRamp;
if (rasterStretch == null)
{
rasterStretch = (this.m_LyrRenderer as IRasterStretch);
}
this.txtHigh.Text = this.m_LyrRenderer.LabelHigh;
this.txtMedium.Text = this.m_LyrRenderer.LabelMedium;
this.txtLow.Text = this.m_LyrRenderer.LabelLow;
this.lblHigh.Text = "255";
this.lblLow.Text = "0";
if (this.cboBands.Enabled)
{
this.cboBands.SelectedItem = this.GetBand(this.m_LyrRenderer.BandIndex);
}
this.RefreshSymbolPic();
}
private void AddRasterStretchSet()
{
if (this.m_UCRasterStretchSet == null)
{
this.m_UCRasterStretchSet = new UCRasterStretchSet();
}
this.m_UCRasterStretchSet.Dock = DockStyle.Fill;
this.m_UCRasterStretchSet.EditorChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.panelControl1.Controls.Add(this.m_UCRasterStretchSet as UserControl);
this.m_UCRasterStretchSet.InitUC(this.m_CurrentLayer);
this.AddUc(this.m_UCRasterStretchSet);
}
private void AddUc(IPropertyPage uc)
{
if (!this.ucList.Contains(uc))
{
this.ucList.Add(uc);
}
}
public void SetStretchRenderer()
{
if (this.m_LyrRenderer == null)
{
return;
}
IColorRamp selectColorRamp = this.ucColorRamps1.GetSelectColorRamp();
bool flag = false;
selectColorRamp.Size = 255;
selectColorRamp.CreateRamp(out flag);
IAlgorithmicColorRamp algorithmicColorRamp = new AlgorithmicColorRampClass();
IColor fromColor = selectColorRamp.get_Color(0);
IColor toColor = selectColorRamp.get_Color(254);
algorithmicColorRamp.Size = 255;
algorithmicColorRamp.FromColor = fromColor;
algorithmicColorRamp.ToColor = toColor;
algorithmicColorRamp.CreateRamp(out flag);
this.m_LyrRenderer.BandIndex = this.GetBandIndex(this.cboBands.Text);
this.m_LyrRenderer.ColorRamp = algorithmicColorRamp;
this.m_LyrRenderer.LabelHigh = this.txtHigh.Text;
this.m_LyrRenderer.LabelLow = this.txtLow.Text;
this.m_LyrRenderer.LabelMedium = this.txtMedium.Text;
this.m_CurrentRenderer = (this.m_LyrRenderer as IRasterRenderer);
this.m_CurrentRenderer.Raster = this.m_CurrentLayer.Raster;
this.m_CurrentRenderer.Update();
}
private void RefreshSymbolPic()
{
if (this.m_SelectSymbol == null)
{
return;
}
Bitmap bitmap = StyleGalleryItemView.SymbolToBitmap(this.pnlCtrl.Width, this.pnlCtrl.Height, this.m_SelectSymbol);
bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);
this.pnlCtrl.Image = bitmap;
}
private void GetColorInfo()
{
if (this.m_CurrentRenderer != null)
{
try
{
IRasterStretch2 rasterStretch = this.m_CurrentRenderer as IRasterStretch2;
this.chkDisplayBackground.Checked = rasterStretch.Background;
if (rasterStretch.BackgroundValue is double[])
{
this.textEdit3.Text = "0";
}
else
{
this.textEdit3.Text = rasterStretch.BackgroundValue.ToString();
}
//王欢 绑定背景颜色 2018-12-17
this.colorEdit1.Color = GetTransparent(rasterStretch.BackgroundColor, rasterStretch.BackgroundColor.NullColor);
IRasterDisplayProps rasterDisplayProps = this.m_CurrentRenderer as IRasterDisplayProps;
//王欢 绑定背景颜色 2018-12-17
this.colorEdit2.Color = GetTransparent(rasterDisplayProps.NoDataColor, rasterDisplayProps.NoDataColor.NullColor);
IHillShadeInfo hillShadeInfo = this.m_CurrentRenderer as IHillShadeInfo;
if (hillShadeInfo != null)
{
this.txtZScale.Text = hillShadeInfo.ZScale.ToString();
this.chkUseHillShade.Checked = hillShadeInfo.UseHillShade;
}
}
catch
{
}
}
}
private void SetColorInfo()
{
if (this.m_CurrentRenderer != null)
{
try
{
IRasterStretch2 rasterStretch = this.m_CurrentRenderer as IRasterStretch2;
rasterStretch.Background = this.chkDisplayBackground.Checked;
//没有用到 王欢 2018-12-15
//double[] array = new double[]
//{
// 0.0,
// 0.0,
// Convert.ToDouble(this.textEdit3.Text)
//};
//设置透明 王欢 2018-12-17
rasterStretch.BackgroundColor = SetTransparent(this.colorEdit1.Color);
IRasterDisplayProps rasterDisplayProps = this.m_CurrentRenderer as IRasterDisplayProps;
//设置透明 王欢 2018-12-17
rasterDisplayProps.NoDataColor = SetTransparent(this.colorEdit2.Color);
if (this.chkUseHillShade.Checked)
{
IHillShadeInfo hillShadeInfo = this.m_CurrentRenderer as IHillShadeInfo;
if (hillShadeInfo != null)
{
hillShadeInfo.ZScale = Convert.ToDouble(this.txtZScale.Text);
hillShadeInfo.UseHillShade = this.chkUseHillShade.Checked;
}
}
}
catch
{
}
}
}
/// <summary>
/// 无颜色背景
/// </summary>
/// <returns>王欢 2018-12-17</returns>
private IColor SetTransparent(Color pcolor)
{
IRgbColor rgb = new RgbColorClass();
if (pcolor == Color.Transparent)
{
rgb.NullColor = true;
}
else
{
rgb.RGB = pcolor.B * 65536 + pcolor.G * 256 + pcolor.R;
}
return rgb as IColor;
}
/// <summary>
/// IRgbColor 转 color
/// </summary>
/// <param name="irgbcolor"></param>
/// <param name="flag"></param>
/// <returns>王欢 2018-12-17</returns>
private Color GetTransparent(object irgbcolor, bool flag = false)
{
IRgbColor rgb = new RgbColorClass();
rgb = irgbcolor as IRgbColor;
if (irgbcolor != null && flag != true)
{
return ColorTranslator.FromOle(rgb.RGB);
}
else
{
return Color.Transparent;
}
}
public void InitUC(object property)
{
this.m_CurrentLayer = (property as IRasterLayer);
if (this.m_CurrentLayer == null)
{
return;
}
this.InitForm();
}
public bool CanWrite2Prop()
{
return true;
}
public void Write2Prop()
{
this.SetStretchRenderer();
this.SetColorInfo();
this.m_CurrentLayer.Renderer = this.m_CurrentRenderer;
}
public void SetDefaultValue(object value)
{
}
private void InvokeEditValueChanged(object sender, System.EventArgs e)
{
if (this.editorChanged != null)
{
this.editorChanged(sender, e);
}
this.isDirty = true;
}
private void chkDisplayBackground_CheckStateChanged(object sender, System.EventArgs e)
{
this.textEdit3.Enabled = this.chkDisplayBackground.Checked;
}
private void checkEdit1_CheckStateChanged(object sender, System.EventArgs e)
{
this.txtZScale.Enabled = this.chkUseHillShade.Checked;
}
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.labelControl1 = new LabelControl();
this.labelControl2 = new LabelControl();
this.cboBands = new ComboBoxEdit();
this.labelControl3 = new LabelControl();
this.lblHigh = new LabelControl();
this.labelControl5 = new LabelControl();
this.txtHigh = new TextEdit();
this.txtMedium = new TextEdit();
this.lblLow = new LabelControl();
this.txtLow = new TextEdit();
this.panelControl1 = new PanelControl();
this.labelControl6 = new LabelControl();
this.chkDisplayBackground = new CheckEdit();
this.colorEdit1 = new ColorEdit();
this.labelControl9 = new LabelControl();
this.textEdit3 = new TextEdit();
this.chkUseHillShade = new CheckEdit();
this.labelControl10 = new LabelControl();
this.txtZScale = new TextEdit();
this.labelControl11 = new LabelControl();
this.colorEdit2 = new ColorEdit();
this.pnlCtrl = new PictureEdit();
this.ucColorRamps1 = new UCColorRamps();
((ISupportInitialize)this.cboBands.Properties).BeginInit();
((ISupportInitialize)this.txtHigh.Properties).BeginInit();
((ISupportInitialize)this.txtMedium.Properties).BeginInit();
((ISupportInitialize)this.txtLow.Properties).BeginInit();
((ISupportInitialize)this.panelControl1).BeginInit();
((ISupportInitialize)this.chkDisplayBackground.Properties).BeginInit();
((ISupportInitialize)this.colorEdit1.Properties).BeginInit();
((ISupportInitialize)this.textEdit3.Properties).BeginInit();
((ISupportInitialize)this.chkUseHillShade.Properties).BeginInit();
((ISupportInitialize)this.txtZScale.Properties).BeginInit();
((ISupportInitialize)this.colorEdit2.Properties).BeginInit();
((ISupportInitialize)this.pnlCtrl.Properties).BeginInit();
base.SuspendLayout();
this.labelControl1.Location = new Point(10, 141);
this.labelControl1.Name = "labelControl1";
this.labelControl1.Size = new Size(60, 14);
this.labelControl1.TabIndex = 0;
this.labelControl1.Text = "色\u3000\u3000域:";
this.labelControl2.Location = new Point(11, 15);
this.labelControl2.Name = "labelControl2";
this.labelControl2.Size = new Size(60, 14);
this.labelControl2.TabIndex = 2;
this.labelControl2.Text = "波\u3000\u3000段:";
this.cboBands.EditValue = "Band_1";
this.cboBands.Location = new Point(81, 12);
this.cboBands.Name = "cboBands";
this.cboBands.Properties.Buttons.AddRange(new EditorButton[]
{
new EditorButton(ButtonPredefines.Combo)
});
this.cboBands.Properties.Items.AddRange(new object[]
{
"Band_1",
"Band_2",
"Band_3"
});
this.cboBands.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
this.cboBands.Size = new Size(250, 21);
this.cboBands.TabIndex = 3;
this.cboBands.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.labelControl3.Location = new Point(35, 39);
this.labelControl3.Name = "labelControl3";
this.labelControl3.Size = new Size(24, 14);
this.labelControl3.TabIndex = 4;
this.labelControl3.Text = "颜色";
this.lblHigh.Location = new Point(188, 59);
this.lblHigh.Name = "lblHigh";
this.lblHigh.Size = new Size(21, 14);
this.lblHigh.TabIndex = 6;
this.lblHigh.Text = "255";
this.labelControl5.Location = new Point(235, 39);
this.labelControl5.Name = "labelControl5";
this.labelControl5.Size = new Size(24, 14);
this.labelControl5.TabIndex = 7;
this.labelControl5.Text = "标识";
this.txtHigh.Location = new Point(236, 56);
this.txtHigh.Name = "txtHigh";
this.txtHigh.Size = new Size(156, 21);
this.txtHigh.TabIndex = 8;
this.txtHigh.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.txtMedium.Location = new Point(235, 83);
this.txtMedium.Name = "txtMedium";
this.txtMedium.Size = new Size(157, 21);
this.txtMedium.TabIndex = 10;
this.txtMedium.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.lblLow.Location = new Point(188, 113);
this.lblLow.Name = "lblLow";
this.lblLow.Size = new Size(7, 14);
this.lblLow.TabIndex = 11;
this.lblLow.Text = "0";
this.txtLow.AllowDrop = true;
this.txtLow.Location = new Point(235, 110);
this.txtLow.Name = "txtLow";
this.txtLow.Size = new Size(157, 21);
this.txtLow.TabIndex = 12;
this.txtLow.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.panelControl1.BorderStyle = BorderStyles.NoBorder;
this.panelControl1.Location = new Point(3, 217);
this.panelControl1.Name = "panelControl1";
this.panelControl1.Size = new Size(390, 296);
this.panelControl1.TabIndex = 20;
this.labelControl6.Location = new Point(188, 39);
this.labelControl6.Name = "labelControl6";
this.labelControl6.Size = new Size(12, 14);
this.labelControl6.TabIndex = 21;
this.labelControl6.Text = "值";
this.chkDisplayBackground.Location = new Point(8, 163);
this.chkDisplayBackground.Name = "chkDisplayBackground";
this.chkDisplayBackground.Properties.Caption = "背景色显示颜色:";
this.chkDisplayBackground.Size = new Size(160, 19);
this.chkDisplayBackground.TabIndex = 23;
this.chkDisplayBackground.CheckedChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.chkDisplayBackground.CheckStateChanged += new System.EventHandler(this.chkDisplayBackground_CheckStateChanged);
this.colorEdit1.EditValue = Color.Empty;
this.colorEdit1.Location = new Point(328, 163);
this.colorEdit1.Name = "colorEdit1";
this.colorEdit1.Properties.Buttons.AddRange(new EditorButton[]
{
new EditorButton(ButtonPredefines.Combo)
});
this.colorEdit1.Size = new Size(62, 21);
this.colorEdit1.TabIndex = 26;
this.colorEdit1.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.labelControl9.Location = new Point(310, 166);
this.labelControl9.Name = "labelControl9";
this.labelControl9.Size = new Size(12, 14);
this.labelControl9.TabIndex = 25;
this.labelControl9.Text = "为";
this.textEdit3.Enabled = false;
this.textEdit3.Location = new Point(236, 163);
this.textEdit3.Name = "textEdit3";
this.textEdit3.Properties.Mask.EditMask = "n";
this.textEdit3.Properties.Mask.MaskType = MaskType.Numeric;
this.textEdit3.Size = new Size(44, 21);
this.textEdit3.TabIndex = 24;
this.textEdit3.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.chkUseHillShade.Location = new Point(8, 190);
this.chkUseHillShade.Name = "chkUseHillShade";
this.chkUseHillShade.Properties.Caption = "显示阴影晕染效果:";
this.chkUseHillShade.Size = new Size(130, 19);
this.chkUseHillShade.TabIndex = 23;
this.chkUseHillShade.CheckedChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.chkUseHillShade.CheckStateChanged += new System.EventHandler(this.checkEdit1_CheckStateChanged);
this.labelControl10.Location = new Point(149, 193);
this.labelControl10.Name = "labelControl10";
this.labelControl10.Size = new Size(19, 14);
this.labelControl10.TabIndex = 27;
this.labelControl10.Text = "Z:";
this.txtZScale.Enabled = false;
this.txtZScale.Location = new Point(175, 190);
this.txtZScale.Name = "txtZScale";
this.txtZScale.Properties.Mask.EditMask = "n";
this.txtZScale.Properties.Mask.MaskType = MaskType.Numeric;
this.txtZScale.Size = new Size(44, 21);
this.txtZScale.TabIndex = 24;
this.txtZScale.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.labelControl11.Location = new Point(247, 193);
this.labelControl11.Name = "labelControl11";
this.labelControl11.Size = new Size(75, 14);
this.labelControl11.TabIndex = 29;
this.labelControl11.Text = "显示Nodata为";
this.colorEdit2.EditValue = Color.Empty;
this.colorEdit2.Location = new Point(328, 189);
this.colorEdit2.Name = "colorEdit2";
this.colorEdit2.Properties.Buttons.AddRange(new EditorButton[]
{
new EditorButton(ButtonPredefines.Combo)
});
this.colorEdit2.Size = new Size(62, 21);
this.colorEdit2.TabIndex = 28;
this.colorEdit2.EditValueChanged += new System.EventHandler(this.InvokeEditValueChanged);
this.pnlCtrl.Location = new Point(35, 56);
this.pnlCtrl.Name = "pnlCtrl";
this.pnlCtrl.Properties.ReadOnly = true;
this.pnlCtrl.Size = new Size(25, 75);
this.pnlCtrl.TabIndex = 30;
this.ucColorRamps1.Location = new Point(80, 137);
this.ucColorRamps1.Name = "ucColorRamps1";
this.ucColorRamps1.Size = new Size(313, 27);
this.ucColorRamps1.TabIndex = 1;
this.ucColorRamps1.SelectIndexChanged += new UCColorRamps.SelectIndexChangedHandler(this.ucColorRamps1_SelectIndexChanged);
this.AutoScroll = true;
base.Controls.Add(this.pnlCtrl);
base.Controls.Add(this.labelControl11);
base.Controls.Add(this.colorEdit2);
base.Controls.Add(this.labelControl10);
base.Controls.Add(this.colorEdit1);
base.Controls.Add(this.labelControl9);
base.Controls.Add(this.txtZScale);
base.Controls.Add(this.textEdit3);
base.Controls.Add(this.chkUseHillShade);
base.Controls.Add(this.chkDisplayBackground);
base.Controls.Add(this.labelControl6);
base.Controls.Add(this.panelControl1);
base.Controls.Add(this.txtLow);
base.Controls.Add(this.lblLow);
base.Controls.Add(this.txtMedium);
base.Controls.Add(this.txtHigh);
base.Controls.Add(this.labelControl5);
base.Controls.Add(this.lblHigh);
base.Controls.Add(this.labelControl3);
base.Controls.Add(this.cboBands);
base.Controls.Add(this.labelControl2);
base.Controls.Add(this.ucColorRamps1);
base.Controls.Add(this.labelControl1);
base.Name = "UCRasterStretchRenderer";
base.Size = new Size(397, 520);
((ISupportInitialize)this.cboBands.Properties).EndInit();
((ISupportInitialize)this.txtHigh.Properties).EndInit();
((ISupportInitialize)this.txtMedium.Properties).EndInit();
((ISupportInitialize)this.txtLow.Properties).EndInit();
((ISupportInitialize)this.panelControl1).EndInit();
((ISupportInitialize)this.chkDisplayBackground.Properties).EndInit();
((ISupportInitialize)this.colorEdit1.Properties).EndInit();
((ISupportInitialize)this.textEdit3.Properties).EndInit();
((ISupportInitialize)this.chkUseHillShade.Properties).EndInit();
((ISupportInitialize)this.txtZScale.Properties).EndInit();
((ISupportInitialize)this.colorEdit2.Properties).EndInit();
((ISupportInitialize)this.pnlCtrl.Properties).EndInit();
base.ResumeLayout(false);
base.PerformLayout();
}
}
}