1

I am developing an application to analyze the images of the districts of a region. I select the districts this way and it works fine (see image)

var selectd = ui.Select ({
   items: Object.keys (Districts),
   placeholder: 'Select District',
   onChange: function (i) {0
Map.addLayer (table.filter (ee.Filter.inList ('BARLO_DESC', [i])))
Map.centerObject (table.filter (ee.Filter.inList ('BARLO_DESC', [i])), 11)

But I can't get the selected district to be the geometry to filter the image collection, for example:

.filterBounds(selectd)

Code:

/*====================================================
OBJECT DICTIONARY (WIDGETS)
======================================================*/


var bandas = {
'B1': [],
'B2': [],
'B3': [],
'B4': [],
'B5': [],
'B6': [],
'B7': [],
'B8': [],
'B8A': [],
'B9': [],
'B11': [],
'B12': [],
'AOT': [],
'WVP': [],
'SCL': [],
'TCI_R': [],
'TCI_G': [],
'TCI_B': [],
'MSK_CLDPRB': [],
'MSK_SNWPRB': [],
'QA10': [],
'QA20': [],
'QA60': [],

}


/* DISTRICT DICTIONARY */

var Distritos = {
'CRUCE DON SILVIO': [52],
'ZONA PELICANO':    [53],
'ZONA CAMPO KAREN': [54],
'ZONA PRATTS GRILL':    [55],
'ZONA MBUTURETA':   [66],
'ZONA JOEL ESTIGARRIBIA':   [71],
'ZONA MAYOR INFANTE RIVAROLA':  [72],
'ZONA EL SOLITARIO':    [83],
'ZONA GENERAL GARAY':   [222],
'ZONA PEDRO P PEÑA':    [223],
'ZONA POZO HONDO':  [224],
'MISTOLAR': [225],
'ZONA HEERNANDARIAS':   [226],
'ZONA LA PATRIA':   [227],
'ZONA AGROPIL': [228],

}

/***********************************************
 * STARTING THE APP
 * *********************************************/


var selectd = ui.Select({
  items: Object.keys(Distritos), 
  placeholder: 'Seleccione Disrito', 
  onChange: function(i){0
Map.addLayer(table.filter(ee.Filter.inList('BARLO_DESC', [i])))
Map.centerObject(table.filter(ee.Filter.inList('BARLO_DESC', [i])), 10)

  }
})

// print(selectd)
// var filtro = table.filter(ee.Filter.inList('BARLO_DESC'))

// /***********************************************
// PANEL CONTROL
// ************************************************/
// // var c = {};
   
// // c.controlPanel = ui.Panel();
// // c.map = ui.Map();
 
// // c.info = {};
// // c.info.titleLabel = ui.Label('Sistemas de Riego en el Acuifero Yrendá');
// // c.info.aboutlabel = ui.Label(
// //   'Análisis de la dinámica de la Vegetación y, especialmente de las pasturas'  +
// //   ' bajo riego con pivots, en el área del acuífero Yrendá, en el extremo' +
// //   ' Occidental del Chaco Paraguayo.');
  
// // c.info.panel = ui.Panel([
// //   c.info.titleLabel, c.info.aboutlabel
// //   ]);
// //     ui.root.clear();
// //     ui.root.add(c.controlPanel);
// //     ui.root.add(c.map);
    
// //     c.controlPanel.add(c.info.panel);
    
// //     c.controlPanel.style().set({
// //   width: '275px'
// // });

// /************************************************
// * OBJECT DICTIONARY (WIDGETS)
// **********************************************/
 
var dicobjetos = {
  Sliderfecha: ui.DateSlider({start: '2015-01-01', end:ee.Date(Date.now()), period: 15, onChange:function(){},style: {width:'240px'}}),
  select:{
    b1: ui.Select({items: Object.keys(bandas), placeholder: 'Sel.Band', onChange:function(){},style: {width:'70px'}}),
    b2: ui.Select({items: Object.keys(bandas), placeholder: 'Sel.Band', onChange:function(){},style: {width:'70px'}}),
    b3: ui.Select({items: Object.keys(bandas), placeholder: 'Sel.Band', onChange:function(){},style: {width:'70px'}}),
  },
  label: ui.Label('Min:', {}),
  slider:ui.Slider({min: 500, max: 5000, step: 100, onChange:function(){},style: {width:'240px'}}),
  label1: ui.Label('Max:', {}),
  slider1:ui.Slider({min: 500, max: 5000, step: 100, onChange:function(){},style: {width:'240px'}}),
  label2: ui.Label('Gamma:', {}),
  slider2:ui.Slider({min: 0, max: 3, step: 0.1, onChange:function(){},style: {width:'120px'}}),
  
}
  
  var panelv = ui.Panel({widgets: [
  dicobjetos.select.b1,
  dicobjetos.select.b2, 
  dicobjetos.select.b3], layout: ui.Panel.Layout.flow('horizontal'), style: {backgroundColor:'00000000'}})
  
  
  var boton = ui.Button({label:'Aplicar', onClick:function(b){
    var coleccion = ee.ImageCollection("COPERNICUS/S2").filterBounds(table)
    .filterDate(ee.Date(dicobjetos.Sliderfecha.getValue()[0]).format('YYYY-MM-dd'),ee.Date(dicobjetos.Sliderfecha.getValue()[1]).format('YYYY-MM-dd'))
      .filterMetadata('CLOUDY_PIXEL_PERCENTAGE','less_than', 10).mosaic()
    var layer = ui.Map.Layer(coleccion, {bands:[dicobjetos.select.b1.getValue(),dicobjetos.select.b2.getValue(),dicobjetos.select.b3.getValue()],
  min:dicobjetos.slider.getValue(), max: dicobjetos.slider1.getValue(),gamma:dicobjetos.slider2.getValue()}, 'Sentinel 2')
  Map.layers().set(0,layer)

  }})
  
  // MAIN PANEL
  var panel = ui.Panel({widgets: [
  dicobjetos.Sliderfecha, panelv,dicobjetos.label,
  dicobjetos.slider, dicobjetos.label1,dicobjetos.slider1,
  dicobjetos.label2,dicobjetos.slider2, selectd, boton ],
  layout: ui.Panel.Layout.flow('vertical'), style: {backgroundColor:'00005555',position: 'top-left'}});
  Map.add(panel)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.