<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: MosaicDatasetRaster using raster function in .NET Maps SDK Questions</title>
    <link>https://community.esri.com/t5/net-maps-sdk-questions/mosaicdatasetraster-using-raster-function/m-p/1545001#M13058</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;I reached out to raster SME on my team and he was able to use the code you provide. The only difference being&amp;nbsp;&lt;CODE class="c-mrkdwn__code" data-stringify-type="code"&gt;parameters&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;are added before the mosaic raster is loaded and before setting the Raster. &lt;BR /&gt;Also need to set the&amp;nbsp;&lt;CODE class="c-mrkdwn__code" data-stringify-type="code"&gt;Filter&lt;/CODE&gt;&amp;nbsp;on the&amp;nbsp;&lt;CODE class="c-mrkdwn__code" data-stringify-type="code"&gt;AddRasterParameters&lt;/CODE&gt;&amp;nbsp;object.&lt;BR /&gt;Here is the sample code he used that worked as expected.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;MosaicDatasetRaster rasterMosaic = MosaicDatasetRaster.Create(@"c:\gtiff\mosaic.sqlite", "mosaic_rasters", SpatialReferences.Wgs84);
               AddRastersParameters parameters = new()
               {
                   InputDirectory = @"c:\gtiff\images",
                   Filter = ".*tif"
               };

               await rasterMosaic.AddRastersAsync(parameters);

               RasterFunction rasterFunction = RasterFunction.FromJson(
               @"
               {
                ""raster_function"":{""type"":""Mask_function""},
                ""raster_function_arguments"":
                {
                    ""nodata_values"":
                   {
                       ""double_array"":[255, 255, 255, 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""
               }‍‍‍‍‍‍‍‍‍‍‍"
               );

               IReadOnlyList&amp;lt;string&amp;gt; myRasterNames = rasterFunction.Arguments.GetRasterNames();
               rasterFunction.Arguments.SetRaster(myRasterNames[0], rasterMosaic);
               RasterLayer rasterLayer = new(new Raster(rasterFunction))
               {
                   Opacity = 0.5
               };

               Map.OperationalLayers.Add(rasterLayer);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;er.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Oct 2024 22:31:28 GMT</pubDate>
    <dc:creator>PreetiMaske</dc:creator>
    <dc:date>2024-10-02T22:31:28Z</dc:date>
    <item>
      <title>MosaicDatasetRaster using raster function</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/mosaicdatasetraster-using-raster-function/m-p/1543047#M13040</link>
      <description>&lt;P&gt;I am trying implement raster mosaicking to have a finer grain control over overlapping rasters.&lt;/P&gt;&lt;P&gt;From my limited research, I believe chaining raster functions seems the most promising approach but the documentation for this is confusing at best.&lt;/P&gt;&lt;P&gt;For example, MosaicDatasetRaster extends Raster but doesn't have the option to set the RasterFunction however there does seem to be an option on the&amp;nbsp;AddRastersParameters class to provide a raster function template file. The documentation states "The path to the raster function template".&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my research leads me to ArcGIS desktop which has the ability to save such a template however every attempt I have made to load a file crashes with an Invalid argument: Failed to read 6107 bytes from &amp;lt;path&amp;gt;.&lt;/P&gt;&lt;P&gt;My first approach was to attempt the JSON, second attempt to use the XML schema.&lt;/P&gt;&lt;P&gt;So to summarise my question(s)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;How do I use raster functions with a mosaic dataset&lt;/LI&gt;&lt;LI&gt;Can we create our own functions&lt;/LI&gt;&lt;LI&gt;Can we use all the functions defined in ArcGIS Pro or are we limited to the subset described&amp;nbsp;&lt;A href="https://developers.arcgis.com/net/layers/add-raster-data/#supported-raster-functions" target="_self"&gt;supported-raster-functions&lt;/A&gt;&amp;nbsp;Note the merge function is not supported&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="csharp"&gt;            MosaicDatasetRaster rasterMosaic = MosaicDatasetRaster.Create(@"mosaic.sqlite", "mosaic_rasters", SpatialReferences.Wgs84);
            rasterMosaic.LoadStatusChanged += async (s, e) =&amp;gt;
            {
                if (e.Status == Esri.ArcGISRuntime.LoadStatus.Loaded)
                {
                    AddRastersParameters parameters = new()
                    {
                        InputDirectory = @"tiff",
                        RasterFunctionTemplateFile = @"mask_function.xml"
                    };

                    await rasterMosaic.AddRastersAsync(parameters);
                }
            };
            await rasterMosaic.LoadAsync();

            RasterLayer rasterLayer = new(rasterMosaic)
            {
                Opacity = 0.5
            };

            Map.OperationalLayers.Add(rasterLayer);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;RasterFunctionTemplate xsi:type='typens:RasterFunctionTemplate'
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    xmlns:typens='http://www.esri.com/schemas/ArcGIS/3.3.0'&amp;gt;
    &amp;lt;Name&amp;gt;Raster Function Template&amp;lt;/Name&amp;gt;
    &amp;lt;Description&amp;gt;xxcxdf&amp;lt;/Description&amp;gt;
    &amp;lt;Function xsi:type='typens:MaskFunction' id='ID1'&amp;gt;
        &amp;lt;Name&amp;gt;Mask&amp;lt;/Name&amp;gt;
        &amp;lt;Description&amp;gt;Sets values that you do not want to display.&amp;lt;/Description&amp;gt;
        &amp;lt;PixelType&amp;gt;UNKNOWN&amp;lt;/PixelType&amp;gt;
    &amp;lt;/Function&amp;gt;
    &amp;lt;Arguments xsi:type='typens:MaskFunctionArguments' id='ID2'&amp;gt;
        &amp;lt;Names xsi:type='typens:ArrayOfString' id='ID3'&amp;gt;
            &amp;lt;String&amp;gt;Raster&amp;lt;/String&amp;gt;
            &amp;lt;String&amp;gt;NoDataInterpretation&amp;lt;/String&amp;gt;
            &amp;lt;String&amp;gt;NoDataValues&amp;lt;/String&amp;gt;
            &amp;lt;String&amp;gt;IncludedRanges&amp;lt;/String&amp;gt;
            &amp;lt;String&amp;gt;Invert&amp;lt;/String&amp;gt;
        &amp;lt;/Names&amp;gt;
        &amp;lt;Values xsi:type='typens:ArrayOfAnyType' id='ID4'&amp;gt;
            &amp;lt;AnyType xsi:type='typens:Raster' id='ID5'&amp;gt;
                &amp;lt;RasterBandCollectionNames xsi:type='typens:ArrayOfRasterBandCollectionName' id='ID6'&amp;gt;
                    &amp;lt;RasterBandCollectionName xsi:type='typens:RasterBandCollectionName' id='ID7'&amp;gt;
                        &amp;lt;NameString&amp;gt;&amp;lt;/NameString&amp;gt;
                        &amp;lt;DatasetName xsi:type='typens:RasterDatasetName' id='ID8'&amp;gt;
                            &amp;lt;WorkspaceName xsi:type='typens:WorkspaceName' id='ID9'&amp;gt;
                                &amp;lt;NameString&amp;gt;Raster Workspace = C:\Work\gtiff\;&amp;lt;/NameString&amp;gt;
                                &amp;lt;PathName&amp;gt;C:\Work\gtiff\&amp;lt;/PathName&amp;gt;
                                &amp;lt;BrowseName&amp;gt;Raster Data&amp;lt;/BrowseName&amp;gt;
                                &amp;lt;WorkspaceFactoryProgID&amp;gt;esriDataSourcesRaster.RasterWorkspaceFactory&amp;lt;/WorkspaceFactoryProgID&amp;gt;
                                &amp;lt;WorkspaceType&amp;gt;esriFileSystemWorkspace&amp;lt;/WorkspaceType&amp;gt;
                                &amp;lt;ConnectionProperties xsi:type='typens:PropertySet' id='ID10'&amp;gt;
                                    &amp;lt;PropertyArray xsi:type='typens:ArrayOfPropertySetProperty' id='ID11'&amp;gt;
                                        &amp;lt;PropertySetProperty xsi:type='typens:PropertySetProperty' id='ID12'&amp;gt;
                                            &amp;lt;Key&amp;gt;DATABASE&amp;lt;/Key&amp;gt;
                                            &amp;lt;Value xsi:type='xs:string'&amp;gt;C:\Work\gtiff\&amp;lt;/Value&amp;gt;
                                        &amp;lt;/PropertySetProperty&amp;gt;
                                    &amp;lt;/PropertyArray&amp;gt;
                                &amp;lt;/ConnectionProperties&amp;gt;
                            &amp;lt;/WorkspaceName&amp;gt;
                        &amp;lt;/DatasetName&amp;gt;
                        &amp;lt;BandIDs xsi:type='typens:ArrayOfInt' id='ID13'&amp;gt;
                            &amp;lt;Int&amp;gt;0&amp;lt;/Int&amp;gt;
                            &amp;lt;Int&amp;gt;1&amp;lt;/Int&amp;gt;
                            &amp;lt;Int&amp;gt;2&amp;lt;/Int&amp;gt;
                            &amp;lt;Int&amp;gt;3&amp;lt;/Int&amp;gt;
                        &amp;lt;/BandIDs&amp;gt;
                    &amp;lt;/RasterBandCollectionName&amp;gt;
                &amp;lt;/RasterBandCollectionNames&amp;gt;
            &amp;lt;/AnyType&amp;gt;
            &amp;lt;AnyType xsi:type='typens:RasterFunctionVariable' id='ID14'&amp;gt;
                &amp;lt;Name&amp;gt;NoDataInterpretation&amp;lt;/Name&amp;gt;
                &amp;lt;Description&amp;gt;&amp;lt;/Description&amp;gt;
                &amp;lt;Value xsi:type='xs:int'&amp;gt;1&amp;lt;/Value&amp;gt;
                &amp;lt;IsDataset&amp;gt;false&amp;lt;/IsDataset&amp;gt;
            &amp;lt;/AnyType&amp;gt;
            &amp;lt;AnyType xsi:type='typens:RasterFunctionVariable' id='ID15'&amp;gt;
                &amp;lt;Name&amp;gt;NoDataValues&amp;lt;/Name&amp;gt;
                &amp;lt;Description&amp;gt;&amp;lt;/Description&amp;gt;
                &amp;lt;Value xsi:type='typens:ArrayOfString' id='ID16'&amp;gt;
                    &amp;lt;String&amp;gt;255&amp;lt;/String&amp;gt;
                    &amp;lt;String&amp;gt;255&amp;lt;/String&amp;gt;
                    &amp;lt;String&amp;gt;255&amp;lt;/String&amp;gt;
                    &amp;lt;String&amp;gt;0&amp;lt;/String&amp;gt;
                &amp;lt;/Value&amp;gt;
                &amp;lt;IsDataset&amp;gt;false&amp;lt;/IsDataset&amp;gt;
            &amp;lt;/AnyType&amp;gt;
            &amp;lt;AnyType xsi:type='typens:RasterFunctionVariable' id='ID17'&amp;gt;
                &amp;lt;Name&amp;gt;IncludedRanges&amp;lt;/Name&amp;gt;
                &amp;lt;Description&amp;gt;&amp;lt;/Description&amp;gt;
                &amp;lt;Value xsi:type='typens:ArrayOfDouble' id='ID18'&amp;gt;
                    &amp;lt;Double&amp;gt;0&amp;lt;/Double&amp;gt;
                    &amp;lt;Double&amp;gt;0&amp;lt;/Double&amp;gt;
                    &amp;lt;Double&amp;gt;0&amp;lt;/Double&amp;gt;
                    &amp;lt;Double&amp;gt;0&amp;lt;/Double&amp;gt;
                    &amp;lt;Double&amp;gt;0&amp;lt;/Double&amp;gt;
                    &amp;lt;Double&amp;gt;0&amp;lt;/Double&amp;gt;
                    &amp;lt;Double&amp;gt;0&amp;lt;/Double&amp;gt;
                    &amp;lt;Double&amp;gt;0&amp;lt;/Double&amp;gt;
                &amp;lt;/Value&amp;gt;
                &amp;lt;IsDataset&amp;gt;false&amp;lt;/IsDataset&amp;gt;
            &amp;lt;/AnyType&amp;gt;
            &amp;lt;AnyType xsi:type='typens:RasterFunctionVariable' id='ID19'&amp;gt;
                &amp;lt;Name&amp;gt;Invert&amp;lt;/Name&amp;gt;
                &amp;lt;Description&amp;gt;&amp;lt;/Description&amp;gt;
                &amp;lt;Value xsi:type='xs:boolean'&amp;gt;false&amp;lt;/Value&amp;gt;
                &amp;lt;IsDataset&amp;gt;false&amp;lt;/IsDataset&amp;gt;
            &amp;lt;/AnyType&amp;gt;
        &amp;lt;/Values&amp;gt;
    &amp;lt;/Arguments&amp;gt;
    &amp;lt;Help&amp;gt;&amp;lt;/Help&amp;gt;
    &amp;lt;Type&amp;gt;0&amp;lt;/Type&amp;gt;
    &amp;lt;Thumbnail xsi:type='xs:string'&amp;gt;&amp;lt;/Thumbnail&amp;gt;
    &amp;lt;Definition&amp;gt;&amp;lt;/Definition&amp;gt;
    &amp;lt;Group&amp;gt;&amp;lt;/Group&amp;gt;
    &amp;lt;Tag&amp;gt;&amp;lt;/Tag&amp;gt;
    &amp;lt;ThumbnailEx&amp;gt;&amp;lt;/ThumbnailEx&amp;gt;
    &amp;lt;Properties xsi:type='typens:PropertySet' id='ID20'&amp;gt;
        &amp;lt;PropertyArray xsi:type='typens:ArrayOfPropertySetProperty' id='ID21'&amp;gt;
            &amp;lt;PropertySetProperty xsi:type='typens:PropertySetProperty' id='ID22'&amp;gt;
                &amp;lt;Key&amp;gt;MatchVariable&amp;lt;/Key&amp;gt;
                &amp;lt;Value xsi:type='typens:RasterFunctionVariable' id='ID23'&amp;gt;
                    &amp;lt;Name&amp;gt;MatchVariable&amp;lt;/Name&amp;gt;
                    &amp;lt;Description&amp;gt;&amp;lt;/Description&amp;gt;
                    &amp;lt;Value xsi:type='xs:int'&amp;gt;1&amp;lt;/Value&amp;gt;
                    &amp;lt;IsDataset&amp;gt;false&amp;lt;/IsDataset&amp;gt;
                &amp;lt;/Value&amp;gt;
            &amp;lt;/PropertySetProperty&amp;gt;
            &amp;lt;PropertySetProperty xsi:type='typens:PropertySetProperty' id='ID24'&amp;gt;
                &amp;lt;Key&amp;gt;UnionDimension&amp;lt;/Key&amp;gt;
                &amp;lt;Value xsi:type='typens:RasterFunctionVariable' id='ID25'&amp;gt;
                    &amp;lt;Name&amp;gt;UnionDimension&amp;lt;/Name&amp;gt;
                    &amp;lt;Description&amp;gt;&amp;lt;/Description&amp;gt;
                    &amp;lt;Value xsi:type='xs:int'&amp;gt;0&amp;lt;/Value&amp;gt;
                    &amp;lt;IsDataset&amp;gt;false&amp;lt;/IsDataset&amp;gt;
                &amp;lt;/Value&amp;gt;
            &amp;lt;/PropertySetProperty&amp;gt;
        &amp;lt;/PropertyArray&amp;gt;
    &amp;lt;/Properties&amp;gt;
&amp;lt;/RasterFunctionTemplate&amp;gt;
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Working example on a single raster using the Mask Function&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;            RasterFunction rasterFunction = RasterFunction.FromJson(
            @"
                {
                 ""raster_function"":{""type"":""Mask_function""},
                 ""raster_function_arguments"":
                 {
                     ""nodata_values"":
                    {
                        ""double_array"":[255, 255, 255, 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""
                }‍‍‍‍‍‍‍‍‍‍‍"
            );

            IReadOnlyList&amp;lt;string&amp;gt; myRasterNames = rasterFunction.Arguments.GetRasterNames();
            rasterFunction.Arguments.SetRaster(myRasterNames[0], new Raster(@"C:\Work\gtiff\raster.tiff"));
            RasterLayer rasterLayer = new(new Raster(rasterFunction))
            {
                Opacity = 0.5
            };

            Map.OperationalLayers.Add(rasterLayer);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 14:35:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/mosaicdatasetraster-using-raster-function/m-p/1543047#M13040</guid>
      <dc:creator>rboothmass</dc:creator>
      <dc:date>2024-09-26T14:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: MosaicDatasetRaster using raster function</title>
      <link>https://community.esri.com/t5/net-maps-sdk-questions/mosaicdatasetraster-using-raster-function/m-p/1545001#M13058</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I reached out to raster SME on my team and he was able to use the code you provide. The only difference being&amp;nbsp;&lt;CODE class="c-mrkdwn__code" data-stringify-type="code"&gt;parameters&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;are added before the mosaic raster is loaded and before setting the Raster. &lt;BR /&gt;Also need to set the&amp;nbsp;&lt;CODE class="c-mrkdwn__code" data-stringify-type="code"&gt;Filter&lt;/CODE&gt;&amp;nbsp;on the&amp;nbsp;&lt;CODE class="c-mrkdwn__code" data-stringify-type="code"&gt;AddRasterParameters&lt;/CODE&gt;&amp;nbsp;object.&lt;BR /&gt;Here is the sample code he used that worked as expected.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;MosaicDatasetRaster rasterMosaic = MosaicDatasetRaster.Create(@"c:\gtiff\mosaic.sqlite", "mosaic_rasters", SpatialReferences.Wgs84);
               AddRastersParameters parameters = new()
               {
                   InputDirectory = @"c:\gtiff\images",
                   Filter = ".*tif"
               };

               await rasterMosaic.AddRastersAsync(parameters);

               RasterFunction rasterFunction = RasterFunction.FromJson(
               @"
               {
                ""raster_function"":{""type"":""Mask_function""},
                ""raster_function_arguments"":
                {
                    ""nodata_values"":
                   {
                       ""double_array"":[255, 255, 255, 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""
               }‍‍‍‍‍‍‍‍‍‍‍"
               );

               IReadOnlyList&amp;lt;string&amp;gt; myRasterNames = rasterFunction.Arguments.GetRasterNames();
               rasterFunction.Arguments.SetRaster(myRasterNames[0], rasterMosaic);
               RasterLayer rasterLayer = new(new Raster(rasterFunction))
               {
                   Opacity = 0.5
               };

               Map.OperationalLayers.Add(rasterLayer);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;er.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 22:31:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/net-maps-sdk-questions/mosaicdatasetraster-using-raster-function/m-p/1545001#M13058</guid>
      <dc:creator>PreetiMaske</dc:creator>
      <dc:date>2024-10-02T22:31:28Z</dc:date>
    </item>
  </channel>
</rss>

