TransWikia.com

What is the difference between sample, sampleRegions, and stratifiedSample in Google Earth Engine?

Geographic Information Systems Asked on June 8, 2021

According to the documentation of GEE

  1. ee.Image.sample() samples the pixels of an image and returns them as a FeatureCollection, in which each feature has 1 property per band in the input image. You can provide a region parameter, which defines the region to sample from, or a factor parameter, which subsamples the image, or a numPixels parameter, which approximates the number of pixels to be sampled. I figure that either all pixels from the region are becoming features, or a randomized subset of pixels. Is that correct?
  2. ee.Image.SampleRegions() samples the pixels of an image in one or more region and puts them into a FeatureCollection with 1 property per band of the input image. It requires a FeatureCollection as input, which defines the regions to sample over. Geometries will be snapped to pixel centers, thus I understand that there will be one sample per feature in the FeatureCollection, even if the FeatureCollection contains many extended polygons. Is that correct?
  3. ee.Image.stratifiedSample() extracts stratified random sample points from an image and returns a FeatureCollection of 1 feature per extracted point with each feature having 1 property per band of the input image. It requires a numPoints parameter that defines how many points to sample. Also you can provide a classBand parameter, which tells you the classes to be used for stratification, and a region parameter, which tells you the region to sample from. Thus, other than for the other two sampling operations, you don’t need a FeatureCollection as input, but rather a raster band that contains information about the classes. Is that correct?

I am just wondering: When should which of these strategies be used?
ee.Image.sample() seems most straight-forward. But can it be used if you have a FeatureCollection of training samples, e.g. containing polygon labels?
ee.Image.SampleRegions() seems to be able to do just that, but shrinks all geometries to the centers, if I am not mistaken.
And ee.Image.stratifiedSample() will need a raster image containing your classes. Is this possible for sparse label images, i.e. classBands that do not contain a class for every pixel?

I am really confused a little and would be happy to see a set of comparable examples to gain a better understanding…

One Answer

sample() uses 1 region (either points or polygons) and does exhaustive sampling in that region (all pixels) unless you specify a smaller number of points. But the random sampling it does isn't optimal.

sampleRegions uses multiple regions (either points or polygons) and does exhaustive sampling in each region (all pixels). There are no options for randomness.

Unless you're just doing simple exhaustive sampling, you probably always want to use stratifiedSample as it has the most options and allows the most flexibility as you can always render your features into a "class band" even if it's just a sparse raster with a single value (using e.g.: ee.Image().paint(collection, 0))

Correct answer by Noel Gorelick on June 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP