[GIS] How to set min and max value for stretchType: esriRasterStretch_PercentMinimumMaximum

arcgis-10.1arcobjectsnetraster

How can I set the min and max values for the stretch type "Percent Clip" in arcobjects?

It's possible to set the Stretch type:

rasterStretch.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_PercentMinimumMaximum;

But I have no idea how I can set the min and max values (like in the Properties Dialog of ArcMap).

Layer Properties with Stretch type Percent Clip and min/max percent values

Best Answer

Looks like you want the IRasterStretchMinMax Interface. Use CustomStretchMin and CustomStretchMax to set the min/max:

public void StretchRenderer(ILayer layer, IMxDocument mxDoc)
        {
            IRasterLayer pRasterLayer = (IRasterLayer)layer;
            try
            {
                IRasterStretchColorRampRenderer pRasterStretchColorRampRenderer;
                pRasterStretchColorRampRenderer = new RasterStretchColorRampRendererClass();
                // Setup the stretch
                IRasterStretch pRasterStretch;
                pRasterStretch = (IRasterStretch)pRasterStretchColorRampRenderer;
                pRasterStretch.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_MinimumMaximum;
                // Set the stretch max/min - 0/254 in this case
                IRasterStretchMinMax pRasterStretchMinMax;
                pRasterStretchMinMax = (IRasterStretchMinMax)pRasterStretchColorRampRenderer;
                pRasterStretchMinMax.UseCustomStretchMinMax = true;
                pRasterStretchMinMax.CustomStretchMin = 0;
                pRasterStretchMinMax.CustomStretchMax = 254;
                // Apply the renderer
                pRasterLayer.Renderer = (IRasterRenderer)pRasterStretchColorRampRenderer;
                // Collapse the legends on each raster
                ILegendInfo legendInfo = (ILegendInfo)pRasterLayer.Renderer;
                ILegendGroup legendGroup = (ILegendGroup)legendInfo.get_LegendGroup(0);
                legendGroup.Visible = false;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Related Question