0

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?

1
  • 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, 2018 at 19:50

1 Answer 1

1

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
Export.table.toAsset({
  collection: highMountains.reduceToVectors({maxPixels: 62208000000}),
  description:'highMountains'
});
// visualize in the map
Map.addLayer(highMountains);

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

4
  • Great answer! How did you determine the number maxPixels?
    – Michael
    Nov 28, 2018 at 10:18
  • That is the error being thrown in your own post
    – Kuik
    Nov 28, 2018 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, 2018 at 10:29
  • I can confirm this: "Error: Computed value is too large."
    – Michael
    Nov 28, 2018 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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