RasterLayer Alpha Channel?

73
4
Jump to solution
10-20-2020 07:50 AM
Highlighted
New Contributor II

Is there anyway to set an alpha channel for a rasterlayer renderer?

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Frequent Contributor

Hi,

You could also try applying a mask e.g.

async Task AddRasterAndSetBackgroundColorValue() 
{
try
{
// Create a raster dataset from a local file raster.
Raster raster = new Raster(@"..\FileRaster.tif");

// Await the Load to catch any errors.
await raster.LoadAsync();

// Create a raster function from the JSON string using the static/Shared method called: RasterFunction.FromJson(json as String)
RasterFunction rasterFunction = RasterFunction.FromJson(jsonFunction);

// Get the raster function arguments
RasterFunctionArguments rasterFunctionArguments = rasterFunction.Arguments;

// Get the list of raster names from the raster function arguments.
IReadOnlyList<string> rasterNames = rasterFunctionArguments.GetRasterNames();

// Set the local file raster as a raster name argument.
rasterFunctionArguments.SetRaster(rasterNames[0], raster);

// Create a new raster based on the raster function.
Raster rasterWithFunction = new Raster(rasterFunction);

// Create a new raster layer from the raster with function applied.
RasterLayer rasterLayer = new RasterLayer(rasterWithFunction);

// Add RasterLayer with function to Map OperationalLayers collection.
Map.OperationalLayers.Add(rasterLayer);
}
catch (Exception ex)
{

}
}

string jsonFunction =
@"{
""raster_function"":{""type"":""Mask_function""},
""raster_function_arguments"":
{
""nodata_values"":{""double_array"":[0],""type"":""Raster_function_variable""},
""nodata_interpretation"":{""nodata_interpretation"":""all"",""type"":""Raster_function_variable""},
""raster"":{""name"":""raster"",""is_raster"":true,""type"":""Raster_function_variable""},
""type"":""Raster_function_arguments""
},
""type"":""Raster_function_template""
}"
;

Mike

View solution in original post

4 Replies
Highlighted
New Contributor II

or set a transparent background value?

Reply
0 Kudos
Highlighted
New Contributor II
Reply
0 Kudos
Highlighted
Esri Frequent Contributor

Hi,

You could also try applying a mask e.g.

async Task AddRasterAndSetBackgroundColorValue() 
{
try
{
// Create a raster dataset from a local file raster.
Raster raster = new Raster(@"..\FileRaster.tif");

// Await the Load to catch any errors.
await raster.LoadAsync();

// Create a raster function from the JSON string using the static/Shared method called: RasterFunction.FromJson(json as String)
RasterFunction rasterFunction = RasterFunction.FromJson(jsonFunction);

// Get the raster function arguments
RasterFunctionArguments rasterFunctionArguments = rasterFunction.Arguments;

// Get the list of raster names from the raster function arguments.
IReadOnlyList<string> rasterNames = rasterFunctionArguments.GetRasterNames();

// Set the local file raster as a raster name argument.
rasterFunctionArguments.SetRaster(rasterNames[0], raster);

// Create a new raster based on the raster function.
Raster rasterWithFunction = new Raster(rasterFunction);

// Create a new raster layer from the raster with function applied.
RasterLayer rasterLayer = new RasterLayer(rasterWithFunction);

// Add RasterLayer with function to Map OperationalLayers collection.
Map.OperationalLayers.Add(rasterLayer);
}
catch (Exception ex)
{

}
}

string jsonFunction =
@"{
""raster_function"":{""type"":""Mask_function""},
""raster_function_arguments"":
{
""nodata_values"":{""double_array"":[0],""type"":""Raster_function_variable""},
""nodata_interpretation"":{""nodata_interpretation"":""all"",""type"":""Raster_function_variable""},
""raster"":{""name"":""raster"",""is_raster"":true,""type"":""Raster_function_variable""},
""type"":""Raster_function_arguments""
},
""type"":""Raster_function_template""
}"
;

Mike

View solution in original post

Highlighted
New Contributor II

Hey Michael, 

This is exactly what I ended up doing based on that link to a post you made back in 2019.

Cheers!

Reply
0 Kudos