ImageryLayer - raster attribute table

This sample shows how to use the attribute table of an ImageryLayer to mask pixels from display. The pixelFilter property of the layer allows the developer to add color to each pixel using RGB values and exclude unwanted pixels.

This layer contains land cover data. Each pixel value represents a land cover type and has attributes associated with it available via the raster attribute table in the image service. This sample displays the desert areas in the western United States by only displaying pixels with values of Shrub/Scrub or Barren Land.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
// to get the raster attribute table, you first must
// wait for the layer to be ready
layer.when(() => {
  rasterAttributes = layer.serviceRasterInfo.attributeTable.features;

  // Get the objects storing field information for
  // pixels classified as Barren Land and "Shrub/Scrub"

  fields = rasterAttributes.filter((item, i) => {
    let className = item.attributes.ClassName;
    return className === "Barren Land" || className === "Shrub/Scrub";
  });
});

Once you have the fields of interest, you can use the pixel filter to exclude unwanted pixels with the mask property of the pixel block and color the desired pixels with either the preset color scheme or any other desired color scheme.

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