Skip to content
import PixelBlock from "@arcgis/core/layers/support/PixelBlock.js";
Inheritance:
PixelBlockAccessor
Since
ArcGIS Maps SDK for JavaScript 4.0

An object representing the pixel arrays in the view. It stores and decodes source data fetched from an image service associated with an ImageryLayer. This provides the user access to each pixel on the client via the pixels property. The PixelBlock object is designed to handle generic pixel arrays from any raster data source.

See also

Constructors

Constructor

Constructor
Parameters
ParameterTypeDescriptionRequired
properties
See the properties table for a list of all the properties that may be passed into the constructor.

Properties

Any properties can be set, retrieved or listened to. See the Watch for changes topic.

bandMasks

Property
Type
Uint8Array<ArrayBuffer>[] | null | undefined

Masks for each band. 0 means noData.

declaredClass

readonlyinherited Property
Type
string
Inherited from: Accessor
Since
ArcGIS Maps SDK for JavaScript 4.7

The name of the class. The declared class name is formatted as esri.folder.className.

height

Property
Type
number

The height (or number of rows) of the PixelBlock in pixels.

mask

Property
Type
Uint8Array<ArrayBuffer> | null | undefined

An array of nodata mask. All pixels are valid when mask is null.

maskIsAlpha

Property
Type
boolean

Indicates whether mask should be used as alpha values. If no (default), a pixel is valid when corresponding mask value is truthy

Default value
false

pixels

Property
Type
BandValuesArray[]

A two dimensional array representing the pixels from the Image Service displayed on the client. The length of the first dimension is the same as the number of bands in the layer. The length of the second dimension is height * width. The length of each band is the same. The pixels in each band are arranged row by row in this format: [p_00, p_10, p_20, ... p_10, p_11, ...] where p_xy is the pixel value at the column x and row y.

Example
let pixels = imgLyr.pixelData.pixelBlock.pixels;
// Prints the number of bands in the layer
console.log(pixels.length);
// An array containing all the pixels in the first band
let band1 = pixels[0];

pixelType

Property
Type
RasterPixelType

The pixel type. Currently pixel block only supports pixels in "u8", "s8", "u16", "s16", "u32", "s32", "f32", "f64" types.

Default value
"f32"

statistics

Property
Type
PixelBlockBandStatistics[] | null | undefined

An array of objects containing numeric statistical properties. Each object has the following specification if defined.

validPixelCount

Property
Type
number | null | undefined

Number of valid pixels

width

Property
Type
number

The width (or number of columns) of the PixelBlock in pixels.

Methods

MethodSignatureClass
fromJSON
inherited static
fromJSON(json: any): any
addData(bandData: PixelBlockBandData): void
getAsRGBA(): Uint8ClampedArray<ArrayBuffer>
getAsRGBAFloat(): Float32Array<ArrayBuffer>
getPlaneCount(): number | null | undefined
toJSON
inherited
toJSON(): any

fromJSON

inheritedstatic Method
Signature
fromJSON (json: any): any
Inherited from: JSONSupportMixin

Creates a new instance of this class and initializes it with values from a JSON object generated from an ArcGIS product. The object passed into the input json parameter often comes from a response to a query operation in the REST API or a toJSON() method from another ArcGIS product. See the Using fromJSON() topic in the Guide for details and examples of when and how to use this function.

Parameters
ParameterTypeDescriptionRequired
json
any

A JSON representation of the instance in the ArcGIS format. See the ArcGIS REST API documentation for examples of the structure of various input JSON objects.

Returns
any

Returns a new instance of this class.

addData

Method
Signature
addData (bandData: PixelBlockBandData): void

Adds another band to the PixelBlock.

Parameters
ParameterTypeDescriptionRequired
bandData

The data to add to the PixelBlock.

Returns
void

getAsRGBA

Method
Signature
getAsRGBA (): Uint8ClampedArray<ArrayBuffer>

Returns pixels and masks using a single array in bip format (e.g. [p_00_r, p_00_g, p_00_b, p_00_a, p_10_r, p_10_g, p_10_b, p_10_a, .....]). Use this method to get an unsigned 8 bit pixel array. The result can be used to create a webgl texture.

Returns
Uint8ClampedArray<ArrayBuffer>

An unsigned 8-bit pixel array.

getAsRGBAFloat

Method
Signature
getAsRGBAFloat (): Float32Array<ArrayBuffer>

Similar to getAsRGBA(), but returns floating point data. The result can be used to create a webgl texture (OES_texture_float).

Returns
Float32Array<ArrayBuffer>

A floating point array.

getPlaneCount

Method
Signature
getPlaneCount (): number | null | undefined

Returns the plane band count of the PixelBlock.

Returns
number | null | undefined

The plane band count.

toJSON

inherited Method
Signature
toJSON (): any
Inherited from: JSONSupportMixin

Converts an instance of this class to its ArcGIS portal JSON representation. See the Using fromJSON() guide topic for more information.

Returns
any

The ArcGIS portal JSON representation of an instance of this class.

Type definitions

PixelBlockBandData

Type definition

The data to add to the PixelBlock via the addData() method.

pixels

Property
Type
number[]

An array representing the pixel data to add.

statistics

Property
Type
PixelBlockBandStatistics | undefined

An object containing numeric statistical properties.

PixelBlockBandStatistics

Type definition

Pixel block band statistics. Returns the minimum and maximum pixel values for a band in a PixelBlock, as well as the no data value.

minValue

readonly Property
Type
number

The minimum pixel value in the pixels array.

maxValue

readonly Property
Type
number

The maximum pixel value in the pixels array.

noDataValue

readonly Property
Type
number | null | undefined

Value representing areas of no data.