ImageryLayer - raster attribute table

Explore in the sandboxView live

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.

// to get the raster attribute table, you first must
// wait for the layer to be ready
layer.when(function() {
  rasterAttributes = layer.serviceRasterInfo.attributeTable.features;

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

  fields = rasterAttributes.filter(function(item, i) {
    var 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.