Is there anyway to set an alpha channel for a rasterlayer renderer?
Solved! Go to Solution.
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
or set a transparent background value?
This approach seems to be the only option:
https://community.esri.com/message/824870-geotiff-file-background-transparency
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
Hey Michael,
This is exactly what I ended up doing based on that link to a post you made back in 2019.
Cheers!