0

I have a problem in the supervised classification output. The classification itself is giving any problem, but when I try to print or display the image I obtain this error:

Image (Error) Unable to use a collection in an algorithm that requires a feature or image. This may happen when trying to use a collection of collections where a collection of features is expected; use flatten, or map a function to convert inner collections to features. Use clipToCollection (instead of clip) to clip an image to a collection.

Here is the code: https://code.earthengine.google.com/9dae0afc574251bd102e81e10850dd82

I'm pretty sure that the problem is from line 103 to 128. Here I created a polygon from a raster, and set it as a FeatureCollection in order to set a class WATER with value = 1. If I use polygons created by giving the coordinates of nodes, I don't have this problem in the classification. I'll attach another link where I use polygons and don't have any problem: https://code.earthengine.google.com/6b03174ebd1c75a9281944c4a17c78b3

The problem is that I need to use the polygon from the raster and I have no clue how to solve this problem.

1 Answer 1

0

I am not 100 % sure if I have solved the complete issue as the resulting classification still seems weird to me but at least I managed to get rid of the error message.

I think the issue was with the variable trainingSet. When I printed it, it was a featurecollection of: (1) a very weird looking MultiPolygon with many self-intersects and (2) a feature collection spread over the entire ROI.

Sampling the regions does not seem to work with this weird list of a Multipolygon and Feature collection but when I extract the second feature collection and only sample these regions, the code is working.

I hope this helps!

// creation of the training set
var trainingSet = classW.merge(classNoW);

trainingSet = trainingSet.toList(2);
var weirdPols = ee.Feature(trainingSet.get(1));
Map.addLayer(weirdPols, null, 'Weird Polygons');
trainingSet = ee.FeatureCollection(trainingSet.get(1));
Map.addLayer(trainingSet, null, 'TrainingSet');
2
  • unfortunately it doesn't solve the problem. The real difference between the two codes that I sent are in the feature ClassNoW. In the second one (the one that is working) the feature ClassNoW is derived by the transformation into a Feature Collection of a MultiPolygon created as the feature ClassW, so "a very weird looking MultiPolygon with many self-intersects". To transform it and set a label and a value for the classification I used this code: var classW = ee.FeatureCollection([ ee.Feature(multiPolyW, {'WATER': 1})]);. Commented Jun 3, 2020 at 12:59
  • for the first code I used a polygon that is "a feature collection spread over the entire ROI". I transformed a raster layer into a vector layer obtaining a polygon. But when I try to transform it and create the label Water to give it a value of 1, using the same code of the previous comment it does not create any new label. So I used this one: var vSlope1 = vSlope.set('WATER', 1); var classNoW = ee.FeatureCollection([ ee.Feature(vSlope1, {'WATER': 1})]);. But I obtain the problem of the question. Commented Jun 3, 2020 at 13:09

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.