0

I have run the code below, to find regions where data is available from my image collection, which This produces a feature collection per region and per variable (in this case SST and Salinity).

// select dates
var startDate = ee.Date('2016-04-01');
var endDate = ee.Date('2016-05-01');

var startyear = 2016; // for DHW make sure match date years above.
var endyear = 2016;

//SST
var sstCollection = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI').select('sst')
.filterDate(startDate, endDate)
.filterBounds(EEZ)
.map(function(image){return image.clip(EEZ)}); 

//Salinity 
var salCollection = ee.ImageCollection('HYCOM/sea_temp_salinity').select('salinity_2')
    .filterDate(startDate, endDate)
    .filterBounds(EEZ)
    .map(function(image){return image.clip(EEZ)});
 

// get presence or absence of data for variable per region, use anyNonZero - where data =1, no data =0

//SST
var sst_mean = sstCollection.mean();
var sstCount_region = sst_mean.reduceRegions({
  reducer: ee.Reducer.anyNonZero(),
  collection: reefsEdit,
  scale: 30});

sstCount_region = sstCount_region.map(function(feature) {
  return feature.set('variable', 'SST');
});

// salinity
var sal_mean = salCollection.mean();
var salCount_region = sal_mean.reduceRegions({
  reducer: ee.Reducer.anyNonZero(),
  collection: reefsEdit,
  scale: 30});

salCount_region = salCount_region.map(function(feature) {
   return feature.set('variable', 'salinity');
 }); 

// add together the feature collections and export as csv

var VarImgCount = ee.FeatureCollection([sstCount_region, salCount_region]).flatten()

I'm trying to get a value per region that sums the property 'any' from this feature collection. But I can't figure out how. So in effect I'd just get one feature collection with the summed values for each region. Was looking at the .aggregate functions but they summarise the entire feature collection into one value, not one value per region, which is not quite what I'm after. A link to my code can be found here.

4
  • The code is in the link above, but here's another copy code.earthengine.google.com/… – mikejwilliamson Jul 3 '20 at 14:30
  • You will need to use the getLink button. Your code is not shared currently. Alternatively, make your repository public (Though I assume the first option is preferred) – Kuik Jul 3 '20 at 14:37
  • That's weird, I used the get link button to get the hyper link above. It seems to open fine when i click it. I've put it below again. Not sure what i;m doing wrong, this usually works code.earthengine.google.com/e56cc8befe5d9c754ad161eea4838517 – mikejwilliamson Jul 3 '20 at 15:37
  • Yes this link works – Kuik Jul 4 '20 at 10:48

Your Answer

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

Browse other questions tagged or ask your own question.