-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommand3.cs
More file actions
187 lines (167 loc) · 6.42 KB
/
Command3.cs
File metadata and controls
187 lines (167 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Display ;
namespace MapControlApplication7
{
/// <summary>
/// Command that works in ArcMap/Map/PageLayout
/// </summary>
[Guid("428c1a54-780f-47c4-8dec-8041e9cd86f8")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("MapControlApplication7.Command3")]
public sealed class Command3 : BaseCommand
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
//
// TODO: Add any COM registration code here
//
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
//
// TODO: Add any COM unregistration code here
//
}
#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Register(regKey);
ControlsCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Unregister(regKey);
ControlsCommands.Unregister(regKey);
}
#endregion
#endregion
private IHookHelper m_hookHelper = null;
private ILayer selectlayer;
public Command3(ILayer select )
{
//
// TODO: Define values for the public properties
//
selectlayer = select;
base.m_category = ""; //localizable text
base.m_caption = ""; //localizable text
base.m_message = "This should work in ArcMap/MapControl/PageLayoutControl"; //localizable text
base.m_toolTip = ""; //localizable text
base.m_name = ""; //unique id, non-localizable (e.g. "MyCategory_MyCommand")
try
{
//
// TODO: change bitmap name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
#region Overridden Class Methods
/// <summary>
/// Occurs when this command is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
if (hook == null)
return;
try
{
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
if (m_hookHelper.ActiveView == null)
m_hookHelper = null;
}
catch
{
m_hookHelper = null;
}
if (m_hookHelper == null)
base.m_enabled = false;
else
base.m_enabled = true;
// TODO: Add other initialization code
}
/// <summary>
/// Occurs when this command is clicked
/// </summary>
///
public void RasterStretchColorMapRender(IRasterLayer pRasterlayer)
{
try
{
IRaster pRaster = pRasterlayer.Raster;
int intTransPValue = 30;
IColor pFromColor = new RgbColorClass();
//Red + (0x100 * Green) + (0x10000 * Blue);
pFromColor.RGB = 255 + 0x100 * 255;
IColor pToColor = new RgbColorClass();
pToColor.RGB = 0x10000 * 255;
IRasterStretchColorRampRenderer pStretchRender =(IRasterStretchColorRampRenderer)pRasterlayer.Renderer;
IRasterRenderer pRasterRender =default(IRasterRenderer);
pRasterRender = (IRasterRenderer)pStretchRender;
pRasterRender.Raster = pRaster;
pRasterRender.Update();
IAlgorithmicColorRamp pColorRamp =
new AlgorithmicColorRamp();
pColorRamp.Size = 255;
pColorRamp.FromColor = pFromColor;
pColorRamp.ToColor = pToColor;
bool outvalue = true;
pColorRamp.CreateRamp(out outvalue);
pStretchRender.BandIndex = 0;
pStretchRender.ColorRamp = pColorRamp;
if (intTransPValue > 0)
{
IRasterDisplayProps pRRenProp =
(IRasterDisplayProps)pStretchRender;
pRRenProp.TransparencyValue = intTransPValue;
}
pRasterRender.Update();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
public override void OnClick()
{
IRasterLayer a = selectlayer as IRasterLayer;
RasterStretchColorMapRender(a);
}
#endregion
}
}