Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
what exactly are you trying to do? Can you include more code than just one line, to give us more context? – Devdatta Tengshe Apr 10 '13 at 11:29
I want to pull out functionality from the Layer Properties dialog and put it in a custom dockable window. Thus, the user can change (raster) properties for more than one layer at the same time. – Saleika Apr 10 '13 at 12:56
A screen capture of the Layer Properties dialog you are describing would be helpful. – Kirk Kuykendall May 10 '13 at 13:21
I'm wondering if you ever found at answer to this @Saleika , I'm grappling with the same thing myself! – rowanwins Nov 26 '15 at 2:52

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;
                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)
share|improve this answer
Thank you for your post. But it's not exactly what I'm looking for. The CustomStretchMin and CustomStretchMax Values are allready Pixel values, while the input for Percent Clip are percent values. I hope there is an easier way than to calculate the CustomStretchMin and CustomStretchMax Values using histogram information and min/max percent values. E.g. for the stretch type esriRasterStretchTypesEnum.esriRasterStretch_StandardDeviations exists a property called IRasterStretch2.StandardDeviationsParam. – Saleika Apr 10 '13 at 13:30

I have to post as an answer rather than a comment. I also cannot find percent min / max clip fields in ArcObjects, however they are present in the XML obtained by serializing the layer's RasterRenderer.

Here's the code to serialize, for anyone interested (straight from ESRI snippets)

IWorkspaceFactory wf = new RasterWorkspaceFactory();
IWorkspace wsrd = wf.OpenFromFile(@"\\calcium\Data\Rasters", 0);
IRasterDataset rd = ((IRasterWorkspace)wsrd).OpenRasterDataset(@"po_908238_bgrn_0000000.tif");
RasterLayerClass rl = new RasterLayerClass();
IRasterRenderer rr = rl.Renderer;

IFile xmlFile = new FileStreamClass();
xmlFile.Open(@"C:\temp\rr.xml", esriFilePermission.esriReadWrite);
IXMLSerialize mySerializeData = (IXMLSerialize)rr;
IXMLWriter myXmlWriter = new XMLWriterClass();
IXMLSerializer myXmlSerializer = new XMLSerializerClass();
myXmlSerializer.WriteObject(myXmlWriter, null, null, null, null, mySerializeData);


<GammaValues xsi:type='typens:ArrayOfDouble'>


In my testing, a layer symbolized as shown in the picture "is" an RasterRGBRenderer, which is exclusive to IRasterStretchMinMax, so I don't think they're hiding in there.

As an alternative to serial/de-serializing, ESRI provide a StretchFunction as a subclass of IRasterFunction, which does provide direct access to clip params, although unfortunately not linked to the UI shown above.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.