(转载)基于ArcGIS Engine编写的ColorRamp对栅格渲染代码

转载于:http://www.gisall.com/html/59/26859-2432.html

需要实现类似ArcMap中的单击TOC控件来对图层进行渲染,示例代码中主要针对的是矢量图层FeatureLayerClass, 没有针对RasterLayerClass, 不过原理是很类似的,我们都知道对栅格渲染主要有三种方式:

1.Raster Unique value Renderer  唯一值渲染
2.Raster Classify Renderer  分类渲染
3.Raster Stretch Renderer   色带渲染
 
而现在要实现ColorRamp 色带的渲染:
 
原理主要就是 利用一个axSymbolControl来承载AE中的ColorRamp枚举值,然后主程序TOC控件调用选中的Style. Item 样式并赋值给IRasterStretchColorRampRenderer的对象实例。
 
关键源代码是:
1. 在ColorSymbolForm的载入初始化时,添加ESRI中包含ColorRamp的样式:
//Get the ArcGIS install location
string sInstall = routin_ReadRegistry("SOFTWARE\\ESRI\\CoreRuntime");
//Load the ESRI.ServerStyle. file into the SymbologyControl
axSymbologyControl1.LoadStyleFile(sInstall + "\\Styles\\ESRI.ServerStyle");
2.选中其中的一个样式
public IStyleGalleryItem GetItem(ESRI.ArcGIS.Controls.esriSymbologyStyleClass styleClass)
{ m_StyleGalleryItem = null;
//Disable ok button
button1.Enabled = false;
//Set the style. class
axSymbologyControl1.StyleClass = styleClass;
//Unselect any selected item in the current style. class
axSymbologyControl1.GetStyleClass(styleClass).UnselectItem();
//Show the modal form. this.ShowDialog();
//Return the selected label style.
return m_StyleGalleryItem;
}
3. 选中样式时相应的事件
private void axSymbologyControl1_OnItemSelected(object sender, ESRI.ArcGIS.Controls.ISymbologyControlEvents_OnItemSelectedEvent e)
{ //Get the selected item
m_StyleGalleryItem = axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass).GetSelectedItem();
//Enable ok button
button1.Enabled = true;
}
 
4.然后在主程序中添加TOC右击事件,用Stretch Renderer  色带渲染:
private void axTOCControl_Temp_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) 
{ if (e.button != 2) return;
IBasicMap map = new MapClass();
ILayer layer = new RasterLayerClass();

object ther = new object();

object index = new object();
esriTOCControlItem item = new esriTOCControlItem();
//Determine what kind of item has been clicked on
this.axTOCControl_Temp.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
if (layer == null) return;
IRasterLayer rasterLayer = layer as IRasterLayer;
if (rasterLayer == null) return;
IRasterStretchColorRampRenderer pStretchColorRasterRenderer = new RasterStretchColorRampRendererClass();
IRasterRenderer pRasterRenderer = pStretchColorRasterRenderer as IRasterRenderer;
pRasterRenderer.Raster = rasterLayer.Raster; pRasterRenderer.Update();
//Get the IStyleGalleryItem IStyleGalleryItem styleGalleryItem = null;
//Create the form. with the SymbologyControl ColorSymbolForm. symbolForm. = new ColorSymbolForm();
//Get teh symbol item styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassColorRamps);
//Release the form. symbolForm.Dispose(); this.Focus();
if (styleGalleryItem == null) return;
IColorRamp colorRamp = (IColorRamp)styleGalleryItem.Item;
pStretchColorRasterRenderer.BandIndex = 0; pStretchColorRasterRenderer.ColorRamp = colorRamp as IColorRamp;
pRasterRenderer.Update();
rasterLayer.Renderer = pStretchColorRasterRenderer as IRasterRenderer;
this.axMapControl_Temp.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
this. axMapControl_Temp.SetBuddyControl(axMapControl_Temp); this.axTOCControl_Temp.Refresh();
}
原文地址:https://www.cnblogs.com/myyouthlife/p/2693217.html