I would like to vectorize binary raster layers in Google Earth Engine in order to be able to use the geometry of the resulting FeatureCollection in other tasks (e.g. clipping data or similar things).

One example: Let's create a vectorized map indicating high mountain regions based on SRTM data:

var srtm = ee.Image('CGIAR/SRTM90_V4');
var highMountains = srtm.gt(2000);
var mask = highMountains.reduceToVectors();

Unfortunately, this does not work - you'll receive the error message

Layer 2: Layer error: Image.reduceToVectors: Too many pixels in the region. Found 62208000000, but only 10000000 allowed.

Is there a way to achieve my goal? Or am I doing something wrong?

  • There is almost a solution in gis.stackexchange.com/questions/255433/… . The problem is that even for comparably small regions, the nice solution of Mr. Gorelick runs into problems: For one giant polygon per class you receive a description length error, for the multi-feature solution you receive an error when trying to print the FeatureCollection because it has accumulated so many elements. – Michael Nov 26 '18 at 19:50

Almost always there is a way. For such large operations it is best to export the results, for example to your asset. You will also have to set the maxPixels, in this case to the amount needed.

I am not yet completely sure if it will finish, as this massive operation will take some time. You will have to try. Otherwise clip the image in multiple smaller images, set tileScale larger or set bestEffort to true and you will have an working code on a lower resolution.

// get the image
var srtm = ee.Image('CGIAR/SRTM90_V4');
var highMountains = srtm.gt(2000);

// export the result to your asset
  collection: highMountains.reduceToVectors({maxPixels: 62208000000}),
// visualize in the map

And here you can upload the result in a later stadium.

// Import the result (change name and file name), after it is finished
var table = ee.FeatureCollection("users/YOUR_NAME/NAME_FILE")

The link: https://code.earthengine.google.com/69356cc3833ea5f4878a7e2ff4f1967f

  • Great answer! How did you determine the number maxPixels? – Michael Nov 28 '18 at 10:18
  • That is the error being thrown in your own post – Kuik Nov 28 '18 at 10:26
  • 1
    Unfortunately, the output to the asset was a too large file, so you will have to increase the tileScale or reduce the image by clipping – Kuik Nov 28 '18 at 10:29
  • I can confirm this: "Error: Computed value is too large." – Michael Nov 28 '18 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.