This sample demonstrates how to apply user defined raster function and mosaic rules to an ImageryLayer layer.
The imagery layer’s raster function uses a raster function chain to reclassify and re-render the original land cover categories into two new categories: forest and non-forest.
// Define a Remap raster function to reclassify pixel values. const remapRasterFunction = { functionName: "Remap", // Separate forested and unforested areas. functionArguments: { // Define the pixel value ranges to remap: 0-40, 41-43, and 44-255. inputRanges: [0, 41, 41, 44, 44, 255], // Remap forest pixels (41-43) to 2 and non-forest pixels to 1. outputValues: [1, 2, 1], // Reference the entire image service, this is the default. raster: "$$", // $2 would refer to the second image of the service. }, };
// Define a Colormap raster function to color each pixel based on its value. const rasterFunction = { functionName: "Colormap", functionArguments: { colormap: [ // Assign rgb(253, 254, 152) to pixels with a value of 1. [1, 253, 254, 152], // Unforested areas get a yellow color. // Assign rgb(2, 102, 6) to pixels with a value of 2. [2, 2, 102, 6], // Forested areas get a green color. ], raster: remapRasterFunction, // Chain the Remap raster function here. }, outputPixelType: "u8", // Store output values as 0-255 integers. };
// Specify how images overlap in the mosaic. Autocasts as MosaicRule. const mosaicRule = { ascending: true, method: "center", operation: "last" };
// Initialize the layer with the last autocast RasterFunction in the chain. const layer = new ImageryLayer({ mosaicRule, rasterFunction, url }); viewElement.map.add(layer);Mosaic rule changes the mosaic schema of all raster items in the referenced image service. Once set, it generates a map in which green areas represent forest while yellow areas are non-forest.