ee.Image.sampleRectangle

  • The function sampleRectangle extracts a rectangular region of pixels from an image into a multi-dimensional array for each band, returning a feature that retains the image properties and sampling geometry.

  • Each band is sampled in its input projection, using the specified geometry or the band's footprint if no geometry is given.

  • The output array dimension depends on the band type: 2D for scalar bands and (2+N)D for array bands where N is the original number of dimensions.

  • If a sampled region of a band is entirely masked and a default array value is provided, that default value will be used instead of sampling the image.

Extracts a rectangular region of pixels from an image into a ND array per band. The arrays are returned in a feature retaining the same properties as the image and a geometry the same as that used to sample the image (or the image footprint if unspecified). Each band is sampled in its input projection, and if no geometry is specified, sampled using its footprint. For scalar bands, the output array is 2D. For array bands the output array is (2+N)D where N is the number of dimensions in the original band. If sampling array bands, all arrays must have the same number of elements. If a band's sampled region is entirely masked and a default array value is specified, the default array value is used in-lieu of sampling the image.

UsageReturns
Image.sampleRectangle(region, properties, defaultValue, defaultArrayValue)Feature
ArgumentTypeDetails
this: imageImageThe image to sample.
regionGeometry, default: nullThe region whose projected bounding box is used to sample the image. Defaults to the footprint in each band.
propertiesList, default: nullThe properties to copy over from the sampled image. Defaults to all non-system properties.
defaultValueFloat, default: nullA default value used when a sampled pixel is masked or outside a band's footprint.
defaultArrayValueArray, default: nullA default value used when a sampled array pixel is masked or outside a band's footprint.