ArcGIS Engine DEM拉伸渲染

从符号库中取出渲染使用的色带对象IColorRamp(也可以自己定义色带内容)

 

  1. <pre name="code" class="csharp">IStyleGallery pSG = new ServerStyleGalleryClass();  
  2. IStyleGalleryStorage pSGS = pSG as IStyleGalleryStorage;  
  3. try  
  4. {  
  5.     pSGS.AddFile(Application.StartupPath + "\\ESRI.ServerStyle");  
  6. }  
  7. catch (Exception err)  
  8. {  
  9.     MessageBox.Show(err.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);  
  10. }  
  11.   
  12. IEnumStyleGalleryItem pMarkerSymbolEnum = pSG.get_Items("Color Ramps", Application.StartupPath+"\\ESRI.ServerStyle", "");  
  13. pMarkerSymbolEnum.Reset();  
  14. IStyleGalleryItem pItem = pMarkerSymbolEnum.Next();  
  15. while (pItem != null)  
  16. {  
  17.     if (pItem.Name == "Elevation #1")  
  18.     {  
  19.         pColorRamp = pItem.Item as IColorRamp;  
  20.         break;  
  21.     }  
  22.     pItem = pMarkerSymbolEnum.Next();  
  23. }  
<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

  1. IRasterLayer pRasterLayr = axMapControl1.get_Layer(0) as IRasterLayer;  
  2.   
  3. IRasterStretchColorRampRenderer pStretchRenderer = new RasterStretchColorRampRendererClass();  
  4. IRasterRenderer pRasterRenderer = (IRasterRenderer)pStretchRenderer;  
  5. IRaster pRaster = pRasterLayr.Raster;  
  6. pRasterRenderer.Raster = pRaster;  
  7. pRasterRenderer.Update();  
  8. pStretchRenderer.BandIndex = 0;  
  9. pStretchRenderer.ColorRamp = pColorRamp;  
  10. IRasterStretch pStretchType = (IRasterStretch)pRasterRenderer;  
  11. pStretchType.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations;  
  12. pStretchType.StandardDeviationsParam = 2.5;  
  13.   
  14. pRasterLayr.Renderer = pRasterRenderer;  
  15. axMapControl1.Refresh();  
  16. axTOCControl1.SetBuddyControl(axMapControl1);  
  17. axTOCControl1.Update();  
  18. 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();

效果如下图所示

 

posted @ 2015-12-07 16:07  玥茹苟  阅读(1209)  评论(0编辑  收藏  举报