2

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

  • 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
  • I am currently researching this problem, I can see that the answer lies somewhere along the lines of using the IStretchFunctionArguments interface - from here you can set the min and max percent values. I will be doing more research, but that's about as far as I have got. I understand this issue is old, and may be of no interest to you now, but hopefully my eventual answer may help others in the future. – Vidar May 17 '17 at 10:27
1

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);
            }
        }
  • 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
1

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();
rl.CreateFromDataset(rd);
IRasterRenderer rr = rl.Renderer;

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

Yields

...
<GammaValues xsi:type='typens:ArrayOfDouble'>
    <Double>1.0894412254829782</Double>
    <Double>1.0894412254829782</Double>
    <Double>1.0894412254829782</Double>
</GammaValues>
<PercentClipMin>0.25</PercentClipMin>
<PercentClipMax>0.25</PercentClipMax>

...

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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