0

I have executed Google Earth Engine code for filtering areas with linear regression details for a specific time period. The countries were filtered as separate layers. I need to combine those layers together.

// get the Country names
var names = countries.aggregate_array('ADM0_NAME');

// Initialize a selection field 
// Once a country has been selected, the redraw function is going
var select = ui.Select({items: names.getInfo(), onChange: redraw });

select.setPlaceholder('Choose a country ...'); 

// Add the drop-down 'select' widget to the map
Map.add(select);

function redraw(key){

  // get the selected country
  var selectedCountry = ee.Feature(countries.filter(ee.Filter.eq('ADM0_NAME', key)).first());
  Map.centerObject(selectedCountry);

  // store the name of the selected country
  var selectedCountry_Strg = ee.String(selectedCountry.get('ADM0_NAME'))

  // add the country geometry to the map
 // var layer0 = ui.Map.Layer(selectedCountry, {color:'purple'}, 'Selected country');
  //Map.layers().set(0, layer0)


// filter the ImageCollection with the boundary of the selected country
var startdate = ee.Date('2017-12-01');
var enddate = ee.Date('2018-05-31');

var rawCollection = collection.select('NDVI')
                              // .filterBounds(selectedCountry.geometry())
                               .filterDate(startdate,enddate)
                               .map(clipBoundary)
                               .map(createTimeBand)
                               //.map(makeLayers)
                               .select(['system:time_start', 'NDVI'])
                               .reduce(ee.Reducer.linearFit())
                               .select('scale');
 //clip image collection                              
function clipBoundary(image){
  return image.clip(selectedCountry)
}                              

  //create a time band for linear regression
function createTimeBand(image) {
   // in the linear regression output.
  return image.addBands(image.metadata('system:time_start'));
}
print(rawCollection ) 

    //add image layer to the map
var layernew = ui.Map.Layer(rawCollection ,{},'Selected Country');
  Map.layers().set(20, layernew)
    //select again and agin
var select = ui.Select({items: names.getInfo(), onChange: redraw });
select.setPlaceholder('Choose a country ...'); 
// Add the drop-down 'select' widget to the map
Map.add(select);
}

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.