Announcement: All noncommercial projects registered to use Earth Engine before April 15, 2025 must verify noncommercial eligibility to maintain Earth Engine access.
Stay organized with collections
Save and categorize content based on your preferences.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[[["\u003cp\u003e\u003ccode\u003esampleRectangle\u003c/code\u003e extracts a rectangular region of pixels from a specified image into a multidimensional array for each band, preserving the image's original properties.\u003c/p\u003e\n"],["\u003cp\u003eThe extracted region is defined by a geometry or defaults to the image's footprint, with each band sampled in its native projection.\u003c/p\u003e\n"],["\u003cp\u003eOutput arrays are 2D for scalar bands and (2+N)D for array bands, where N represents the original band's dimensions, utilizing default values for masked or out-of-bounds pixels if provided.\u003c/p\u003e\n"],["\u003cp\u003eUsers can customize the properties carried over from the original image and specify default values for masked or out-of-bounds pixel values.\u003c/p\u003e\n"]]],["It extracts a rectangular pixel region from an image into an ND array per band, returning a feature with the same properties and geometry as the input. Bands are sampled in their input projection using a specified region or the image footprint. Output arrays are 2D for scalar bands and (2+N)D for array bands. If a sampled region is entirely masked, a specified default value or array is used. Properties from the image can be copied.\n"],null,["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.\n\n\u003cbr /\u003e\n\n| Usage | Returns |\n|-------------------------------------------------------------------------------------------------|---------|\n| Image.sampleRectangle`(`*region* `, `*properties* `, `*defaultValue* `, `*defaultArrayValue*`)` | Feature |\n\n| Argument | Type | Details |\n|---------------------|-------------------------|--------------------------------------------------------------------------------------------------------------|\n| this: `image` | Image | The image to sample. |\n| `region` | Geometry, default: null | The region whose projected bounding box is used to sample the image. Defaults to the footprint in each band. |\n| `properties` | List, default: null | The properties to copy over from the sampled image. Defaults to all non-system properties. |\n| `defaultValue` | Float, default: null | A default value used when a sampled pixel is masked or outside a band's footprint. |\n| `defaultArrayValue` | Array, default: null | A default value used when a sampled array pixel is masked or outside a band's footprint. |"]]