1

I created a Feature Collection of Ndvi (mean, min, max) from Image Collection. Now i want to convert FeatureCollection in ImageCollection in order to have a three bands (mean,min,max).How can help me?

var NDVI_POST= ee.ImageCollection(ETM_L7.merge(OLI_L8));
print(NDVI_POST)
var reducers=  ee.Reducer.mean().combine({
  reducer2: ee.Reducer.minMax(),
  sharedInputs: true
});
var ndvi = NDVI_POST.map(function(image) {
  return image.select('NDVI').reduceRegions({
    collection: fire_2007, 
    reducer: reducers,
    scale: 30,
  tileScale: 16
  }).filter(ee.Filter.neq('mean', null))
    .map(function(f) { 
     return f.set('imageId', image.id());
    });
}).flatten();
4
  • What is the reason that you convert this to feature collection at the first place?
    – HamiEbra
    Jun 5, 2020 at 11:59
  • Because I have to create training dataset (the input data as bands not properties) for SupervisedClassification. Jun 5, 2020 at 12:31
  • Your code provide a single min,max, and mean value for each image in the image collection. It is just a value for whole the image. While, there are some functions like "mean", "min", and "max" that can directly apply on the image collection and provide you a mean image.
    – HamiEbra
    Jun 5, 2020 at 13:27
  • @hamikelvin i know but i want an ImageCollection not single Image Jun 5, 2020 at 13:47

1 Answer 1

0

First off: Next time, please link to your script, or confirm that the code you have in your question can run without needing anything else (like fire_2007)

Anyway, here's how you would convert your Feature Collection to an Image Collection. The trick is this code:

  var properties = ["max", "mean", "min"]
  var image = ee.Image.constant(feature.toDictionary(properties).values())

It constructs an image from the chosen properties of a Feature. If you map this over the Feature Collection you can convert your entire Feature Collection.

Here's my entire script with some extra stuff added:

var ndvi = NDVI_POST.map(function(image) {
  return image.select('NDVI').reduceRegions({
    collection: fire_2007, 
    reducer: reducers,
    scale: 30,
  tileScale: 16
  }).filter(ee.Filter.neq('mean', null))
    .map(function(f) { 
     return f.set('system:time_start', image.get("system:time_start"));
    });
}).flatten();

var ndvi_images = ndvi.map(function(feature){
  var date = feature.get("system:time_start")
  var properties = ["max", "mean", "min"]
  var image = ee.Image.constant(feature.toDictionary(properties).values())
  var renamed = image.rename(properties)
  return renamed.set("system:time_start", date)
})

Code Editor

3
  • thanks a lot it work!! Jun 5, 2020 at 15:07
  • If i want computing NDVI mean, min, max of each image from ImageCollection directly. How i can do? Jun 5, 2020 at 15:10
  • You can't really do that. I would say that your script right now is quite close to the normal workflow for this kind of task. Also, if my answer solved your question, I would appreciate it if you mark it as accepted :)
    – JonasV
    Jun 5, 2020 at 16:24

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.