Export Geotiff with Alpha using IRasterLayerExport3

657
3
02-23-2022 09:00 AM
Richard_Nairn
New Contributor

Hello,

I am trying to bulk process a number of grids and export out geotiffs. I have been able to use IRasterLayerExport3 to create an RGB geotiff. However they all have black for a background as the tiff only saves with 3 bands, rather than having a four band RGBA.  This is my first attempt at using the SDK

I am trying to emulate the ArcPro export raster functionality to save a raster with a color ramp.

The code I currently use looks like this:

IMapDocument pmapDocument = new MapDocument();
IMap pmap;
pmapDocument.Open(layerName);
pmap = pmapDocument.get_Map(0);
ILayer layer = pmap.Layer[0];

IRasterLayer rlayer = layer as IRasterLayer;

IRasterLayerExport3 r3 = (IRasterLayerExport3)r_export;
ISaveAs2 save_as = (ISaveAs2)rlayer;

r3.Force2RGB = true;
r3.NoData = 0;
r3.RasterLayer = rlayer;

IRasterWorkspace out_Workspace = OpenFileWorkspace(wsName);
IWorkspace ow = (IWorkspace)out_Workspace;

r3.Export(ow, outName, "TIFF");

Am I missing another process that I should be using instead of this?

 

Thanks

0 Kudos
3 Replies
GordonSumerling
Esri Contributor

Hello @Richard_Nairn I like to trial this in interactive form first. I can get this to work with output to JP2's with the following

  1. Export the image initially as TIFF.
  2. Load the TIFF image your interested in.
  3. Go to the symbology tab and Set the Mask values to (0,0,0)

GordonSumerling_0-1645653799012.png

  1. Create a new area feature class and draw a polygon which has the image extent
  2. Right click the TIFF image in the table of contents and select Export Raster
    1. Set the output name to be <name>.jp2
    2. Select the clipping Geometry
    3. Clipping Type : Outside
    4. Use Renderer
    5. Force RGB
    6. Output format JP2
    7. Compression Quality 75

GordonSumerling_1-1645653824490.png

 

 

Output image is a 4 Band JP2 image with Alpha band

Hope this helps. some

Gordon

0 Kudos
Richard_Nairn
New Contributor

In ArcPro the manual export to geotiff with alpha works.  In ArcMap 10.8.1 it only outputs a 3 band RGB with no alpha.

 I need an automatic process as I have hundreds to do. It is going to another program so GeoTIFF is required. The issue is the automated way using ArcObjects does not seem to add the alpha channel. I have not tried the ArcPro SDK to see if I can do something similar. 

Currently I post process using FME to change the 0,0,0 NoData to blank Alpha. It's just an extra processing step I am trying to see if I can do within one of my initial steps rather than. 

0 Kudos
GordonSumerling
Esri Contributor

@Richard_Nairn there is a really good dicusion here on the merits of the Export Raster tool v's the Copy Raster tool. They key is the Force RGB option

" Check the Force RGB check box to export the output raster as a three-band RGB raster dataset with the current renderer. Additionally, while exporting to formats such as TIFF, JP2, PNG, and MRF that support alpha bands, you can use this option to export the data as a four-band raster dataset with an alpha band to preserve the transparency settings of the original data" 

It appears the copy raster tool does not have this capability but has the Ignore Background Value option which may be the same.

Hope this helps

Gordon