3

I have an ArcGIS Add-In that scans our file directory for aerial imagery rasters intersecting a given point geometry and loads the qualified images to an mxd. As soon as you hit "Update Georeferencing" from the toolbar, the image turns black. If the file resource is loaded manually it renders correctly along with the updated georeferencing.

Before enter image description here

After enter image description here

Here are the two methods that deal with its symbology and loading:

private static void PullImages(IPoint centerpoint, ref List<IRasterLayer> rasterList, string directoryPath, ref int rasterCount, ref int imagesFound)
{
    IWorkspace ws; IDataset dataset; IRasterLayer rasterLayer;
    ws = RWSF.OpenFromFile(directoryPath, ArcMap.Application.hWnd);
    IEnumDataset enumDataset = ws.get_Datasets(esriDatasetType.esriDTRasterDataset);
    dataset = enumDataset.Next();

    while (dataset != null)
    {
        rasterCount++;
        OnUpdatePercentageLabel(rasterCount);
        IEnvelope rasterEnvelope = (dataset as IGeoDataset).Extent;
        rasterEnvelope.Project(NAD83);
        if (centerpoint.X > rasterEnvelope.XMin && centerpoint.X < rasterEnvelope.XMax &&
            centerpoint.Y > rasterEnvelope.YMin && centerpoint.Y < rasterEnvelope.YMax)
        {
            rasterLayer = new RasterLayerClass();
            rasterLayer.CreateFromDataset(dataset as IRasterDataset);
            RemoveHistogramStretchAndMinimize(ref rasterLayer);
            MXD.AddLayer(rasterLayer);
            Marshal.ReleaseComObject(rasterLayer);
            imagesFound++;
        }
        dataset = enumDataset.Next();
    }
}

internal static void RemoveHistogramStretchAndMinimize(ref IRasterLayer rasterLayer)
{
    IRasterRenderer renderer = new RasterStretchColorRampRendererClass();
    renderer.Raster = rasterLayer.Raster;
    renderer.Update();
    IRasterStretch2 stretch = (IRasterStretch2)renderer;
    stretch.StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE;
    rasterLayer.Renderer = renderer;

    ILegendInfo legendInfo = (ILegendInfo)rasterLayer.Renderer;
    ILegendGroup legendGroup = (ILegendGroup)legendInfo.get_LegendGroup(0);
    legendGroup.Visible = false;
}
  • 1
    Is your raster RGB or greyscale? It looks single band in the image, if so renderer should be new RasterStretchColorRampRendererClass()... What would happen if you changed your stretch type to esriRasterStretch_MinimumMaximum? After the layer is loaded can you adjust the layer properties manually and get it to appear? – Michael Stimson Mar 15 '17 at 21:52
  • Have you tried recalculating the statistics of the image? – kenbuja Mar 15 '17 at 22:45

Your Answer

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

Browse other questions tagged or ask your own question.