基于ArcGIS Engine编写的ColorRamp对栅格渲染代码
2014-01-06 15:36
302 查看
转载于: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的样式:
2.选中其中的一个样式
3. 选中样式时相应的事件
4.然后在主程序中添加TOC右击事件,用Stretch Renderer 色带渲染:
需要实现类似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(); }
相关文章推荐
- (转载)基于ArcGIS Engine编写的ColorRamp对栅格渲染代码
- 【百度分享】基于内核模块的测试代码编写(二)
- 基于jquery编写的横向自适应幻灯片切换特效的实例代码
- 【百度分享】基于内核模块的测试代码编写(三)
- 基于Cocos2d-x学习OpenGL ES 2.0系列——OpenGL ES渲染之LayerColor(8)
- 使用CXF开发WebService程序的总结(四):基于bean的客户端和服务端代码的编写
- 【C语言】【unix c】编写代码实现基于UDP的网络通信
- 基于HIVE文件格式的map reduce代码编写
- 基于C#的TCP文件传输 由于水平有限,代码粗糙请见谅,vs2015编写 文件发送附代码
- Arcgis Engine矢量裁剪栅格,调用Mask工具相关代码
- Horde3D——基于C++编写的3D渲染引擎
- 编写整洁的TableView代码--基于Block的TableView/CollectionView数据源封装
- 2048聚合版开源代码,cocos2d-js编写,基于CocosEditor开发工具,可运行Android,ios,html5等
- 嵌入式ARM 中断 IRQ代码编写 基于S5pv210
- 基于maven项目的串烧~(restful风格服务+spring boot的模板渲染+maven插件mybatis generator代码自动生成)
- 基于jquery编写的横向自适应幻灯片切换特效的实例代码
- ArcGIS Engine代码共享-颜色(Color)对象函数
- Swift调用Objective-C编写的代码(颜色选择器KKColorListPicker调用)
- 使用CXF开发WebService程序的总结(五):基于Map数据类型处理的的客户端和服务端代码的编写
- 基于Cocos2d-x学习OpenGL ES 2.0系列——OpenGL ES渲染之LayerColor(8)