Is there anyway to set an alpha channel for a rasterlayer renderer?
Hi,
You could also try applying a mask e.g.
<SPAN class="keyword token">async</SPAN> Task <SPAN class="token function">AddRasterAndSetBackgroundColorValue</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">try</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// Create a raster dataset from a local file raster.</SPAN> Raster raster <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Raster</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">@"..\FileRaster.tif"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Await the Load to catch any errors.</SPAN> <SPAN class="keyword token">await</SPAN> raster<SPAN class="punctuation token">.</SPAN><SPAN class="token function">LoadAsync</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Create a raster function from the JSON string using the static/Shared method called: RasterFunction.FromJson(json as String)</SPAN> RasterFunction rasterFunction <SPAN class="operator token">=</SPAN> RasterFunction<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FromJson</SPAN><SPAN class="punctuation token">(</SPAN>jsonFunction<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Get the raster function arguments</SPAN> RasterFunctionArguments rasterFunctionArguments <SPAN class="operator token">=</SPAN> rasterFunction<SPAN class="punctuation token">.</SPAN>Arguments<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Get the list of raster names from the raster function arguments.</SPAN> IReadOnlyList<SPAN class="operator token"><</SPAN><SPAN class="keyword token">string</SPAN><SPAN class="operator token">></SPAN> rasterNames <SPAN class="operator token">=</SPAN> rasterFunctionArguments<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetRasterNames</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Set the local file raster as a raster name argument.</SPAN> rasterFunctionArguments<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetRaster</SPAN><SPAN class="punctuation token">(</SPAN>rasterNames<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> raster<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Create a new raster based on the raster function.</SPAN> Raster rasterWithFunction <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Raster</SPAN><SPAN class="punctuation token">(</SPAN>rasterFunction<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Create a new raster layer from the raster with function applied.</SPAN> RasterLayer rasterLayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">RasterLayer</SPAN><SPAN class="punctuation token">(</SPAN>rasterWithFunction<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// Add RasterLayer with function to Map OperationalLayers collection.</SPAN> Map<SPAN class="punctuation token">.</SPAN>OperationalLayers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>rasterLayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> ex<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">string</SPAN> jsonFunction <SPAN class="operator token">=</SPAN> <SPAN class="string token">@"{ ""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"" }"</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Mike
Hey Michael,
This is exactly what I ended up doing based on that link to a post you made back in 2019.
Cheers!
This approach seems to be the only option:
https://community.esri.com/message/824870-geotiff-file-background-transparency
or set a transparent background value?
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.