2

I have code in GEE that creates image collection based on geometry, calc for each polygon the mean value of NDVI for each image, creates new featurecollection with the image as title, and then the polygons names + their mean NDVI value.

My problem is that for some reason the data calculated only for one tile, originally. I have 10 features: enter image description here

But in the results, where each polygon name gets column, I get only few (arc, csv and find are the names) : enter image description here

I have tries to select manually other tiles, and when I did it, I could get the data of other polygons, but I would like to get all this data at once.

Here is link to my code, I shared the geometry, let me know if it doesn't work: https://code.earthengine.google.com/b6480f7aa62bbf6ef0736066e095bf68

My endgoal: to get the data for all the polygons, even if they are not in the same tile (image). (or in another words: to create featurecollection with more than one tile-images)

Edit: following Daniel's answer, I have tried to change it from set to create dictionary, so I have tried to change this:

// Collect region, image, value triplets.
var triplets = filter.map(function(image) {
  return image.select('NDVI').reduceRegions({
    collection: geometry.select(['Name']), 
    reducer: ee.Reducer.mean(), 
    scale: 10,
  })
    .map(function(f) { 
      return f.set('time', (ee.Date(image.get('system:time_start'))).format("YYYY-MM-dd"));
    });
}).flatten();

to this:

// Collect region, image, value triplets.
var triplets = filter.map(function(image) {
  return image.select('NDVI').reduceRegions({
    collection: geometry.select(['Name']), 
    reducer: ee.Reducer.mean(), 
    scale: 10,
  })
    .map(function(f) { 
      return ee.Feature(null,ee.Dictionary({time:(ee.Date(image.get('system:time_start'))).format("YYYY-MM-dd")}));
    });
}).flatten();

print('triplets', triplets);

But then when I print "triplets" I get many images that have geoemtry "null" and they have only one column in proprty- time, but without the mean NDVI for the polygon, and in addition I get this error message:

FeatureCollection (Error) Error in map(ID=20180911T050649_20180911T052326_T43PHT_00000000000000000000): Dictionary: Element at position 0 is not a string.

that if I understand correct- means that it doesn't recognize the column "Name" anymore.

Here you can see the the "modified" code with the featurecollection instead of the set. : https://code.earthengine.google.com/1df1a654d9473d02c071e28f40d6b014

What am I missing?

1 Answer 1

3
+150

They are missing because their mean is null, and get filtered out with .filter(ee.Filter.neq('mean', null)).

Some debug printing will show you:

print(triplets.distinct('Name').aggregate_array('Name'))

Then there is a second problem, which comes from a somewhat surprising behavior in ee.Feature. When calling ee.Feature.set() with null as value, or with an ee.Dictionary containing null values, these properties are never actually set. Luckily, there's a workaround. When you construct your ee.Feature, you can provide an ee.Dictionary with null values without having them removed:

print('Empty', ee.Feature(null).set('foo', null))
print('Empty', ee.Feature(null).set(ee.Dictionary({foo: null})))
print('Not empty', ee.Feature(null, ee.Dictionary({foo: null})))

If you use this little workaround, and remove the filtering of null values, you should get your script to work:

https://code.earthengine.google.com/cd4ee4177c8019d747cf29a5b98775bf

8
  • thank you for your answer. I have tried to remove this line (.filter(ee.Filter.neq('mean', null))) but I still get only part of my polygons. I also tried to play with the neq changing it to eq,expcecting to get all the missing polygons, but then I got nothing. I believe I misunderstand something here...
    – Reut
    Apr 20, 2020 at 13:30
  • thank you for this explaination. I have tried to play with your example a little and then I tried to write it ehis way: .map(function(f) { return ee.Feature(null, ee.Dictionary(({time : (ee.Date(image.get('system:time_start'))).format("YYYY-MM-dd")}))); }); }).flatten(); but it still weird- when I print triplets I get only null (and ofcurse the featurecollection doesnt print because it doesn't "recognize" the featurecollection because I couldn't define it. do you have any more hints for me ? code.earthengine.google.com/82a698b4376267d4f7cb0467ff93b42c thanks:)
    – Reut
    Apr 20, 2020 at 17:13
  • ee.Feature really doesn't want to contain null property values. Even when you manage to get it in there, calling .set('time, ...) causes these null props to be removed. Maybe the best option is to ignore these null props, but explicitly include them in your selectors when exporting. code.earthengine.google.com/83afc888b3e23df085669569c5ac0bf9 Apr 24, 2020 at 9:21
  • I feel a little bit confusd, I thought from your explaination that if I do it similar to the third option, it can get the null values, but from the link you shared, it is still checking only one tile , so do you think it's impossible to make GEE to check many tiles at once in this case?
    – Reut
    Apr 24, 2020 at 13:40
  • 1
    OK, I see. I had misunderstood. You're filtering images based on their pixel count, just keeping the ones with the most pixels. I'm not sure why you do that, and it's probably not what you want to do. Images for S2 comes clipped to the tile grid. Some will cover the whole tile, some only a part of it. You have thrown away all images over some of your polygons. Here I added the geometry of the original dataset, and one filtered down. You'll see that you have no imagery over some of your poylgons. code.earthengine.google.com/df7fba25ca99ffdbc9e839217caed906 Apr 27, 2020 at 9:27

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.