ImageryLayer - raster function

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.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Defines a Remap raster function. Remap reclassifies pixel
// values to new values. In this case we want to separate
// two land cover types: forested areas and non-forested areas

const remapRF = new RasterFunction({
  functionName: "Remap",
  functionArguments: {
    // pixel values of forest categories are 41, 42, and 43
    // according to the  raster attribute table.
    // The InputRanges property defines the ranges of initial pixel values to remap
    // Three ranges: [0, 41], [41, 44], and [44, 255] are defined to extract forest pixels.
    inputRanges: [0, 41, 41, 44, 44, 255],
    // non-forest pixels (0-41 and 44-255) are remapped to a value of 1,
    // forest pixels (41-44) are remapped to a value of 2.
    outputValues: [1, 2, 1],
    // $$(default) refers to the entire image service,
    // $2 refers to the second image of the image service
    raster: "$$"
  }
});

// The Colormap raster function adds color to each pixel
// based on its pixel value
const colorRF = new RasterFunction({
  functionName: "Colormap",
  functionArguments: {
    colormap: [
      // non-forest pixels (value of 1) are assigned
      // a yellowish color RGB = [253, 254, 152]
      [1, 253, 254, 152],
      // forest pixels (value of 2) are assigned
      // a greenish color RGB = [2, 102, 6]
      [2, 2, 102, 6]
    ],
    // Setting the previous raster function to the Raster
    // property of a new raster function allows you to chain functions
    raster: remapRF
  },
  outputPixelType: "U8"
});

const layer = new ImageryLayer({
  url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer",
  // apply the most recent raster function to the chain
  rasterFunction: colorRF,
  mosaicRule: mosaicRule
});

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 forested while yellow areas are non-forest.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.