从符号库中取出渲染使用的色带对象IColorRamp(也可以自己定义色带内容)
- <pre name="code" class="csharp">IStyleGallery pSG = new ServerStyleGalleryClass();
- IStyleGalleryStorage pSGS = pSG as IStyleGalleryStorage;
- try
- {
- pSGS.AddFile(Application.StartupPath + "\\ESRI.ServerStyle");
- }
- catch (Exception err)
- {
- MessageBox.Show(err.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- IEnumStyleGalleryItem pMarkerSymbolEnum = pSG.get_Items("Color Ramps", Application.StartupPath+"\\ESRI.ServerStyle", "");
- pMarkerSymbolEnum.Reset();
- IStyleGalleryItem pItem = pMarkerSymbolEnum.Next();
- while (pItem != null)
- {
- if (pItem.Name == "Elevation #1")
- {
- pColorRamp = pItem.Item as IColorRamp;
- break;
- }
- pItem = pMarkerSymbolEnum.Next();
- }
<pre name="code" class="csharp">IStyleGallery pSG = new ServerStyleGalleryClass();
IStyleGalleryStorage pSGS = pSG as IStyleGalleryStorage;
try
{
pSGS.AddFile(Application.StartupPath + "\\ESRI.ServerStyle");
}
catch (Exception err)
{
MessageBox.Show(err.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
} IEnumStyleGalleryItem pMarkerSymbolEnum = pSG.get_Items("Color Ramps", Application.StartupPath+"\\ESRI.ServerStyle", "");
pMarkerSymbolEnum.Reset();
IStyleGalleryItem pItem = pMarkerSymbolEnum.Next();
while (pItem != null)
{
if (pItem.Name == "Elevation #1")
{
pColorRamp = pItem.Item as IColorRamp;
break;
}
pItem = pMarkerSymbolEnum.Next();
}
使用取得的ColorRamp对象渲染DEM
- IRasterLayer pRasterLayr = axMapControl1.get_Layer(0) as IRasterLayer;
- IRasterStretchColorRampRenderer pStretchRenderer = new RasterStretchColorRampRendererClass();
- IRasterRenderer pRasterRenderer = (IRasterRenderer)pStretchRenderer;
- IRaster pRaster = pRasterLayr.Raster;
- pRasterRenderer.Raster = pRaster;
- pRasterRenderer.Update();
- pStretchRenderer.BandIndex = 0;
- pStretchRenderer.ColorRamp = pColorRamp;
- IRasterStretch pStretchType = (IRasterStretch)pRasterRenderer;
- pStretchType.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
- pStretchType.StandardDeviationsParam = 2.5;
- pRasterLayr.Renderer = pRasterRenderer;
- axMapControl1.Refresh();
- axTOCControl1.SetBuddyControl(axMapControl1);
- axTOCControl1.Update();
- axTOCControl1.Refresh();
IRasterLayer pRasterLayr = axMapControl1.get_Layer(0) as IRasterLayer; IRasterStretchColorRampRenderer pStretchRenderer = new RasterStretchColorRampRendererClass();
IRasterRenderer pRasterRenderer = (IRasterRenderer)pStretchRenderer;
IRaster pRaster = pRasterLayr.Raster;
pRasterRenderer.Raster = pRaster;
pRasterRenderer.Update();
pStretchRenderer.BandIndex = 0;
pStretchRenderer.ColorRamp = pColorRamp;
IRasterStretch pStretchType = (IRasterStretch)pRasterRenderer;
pStretchType.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;
pStretchType.StandardDeviationsParam = 2.5; pRasterLayr.Renderer = pRasterRenderer;
axMapControl1.Refresh();
axTOCControl1.SetBuddyControl(axMapControl1);
axTOCControl1.Update();
axTOCControl1.Refresh();
效果如下图所示