April 11

GEE APP 1

// Ekin maydonlari qatlamini import qilish
var crops = ee.FeatureCollection("projects/geoinfouz/assets/klaster_crops")

// NDVI klassifikatsiyasi uchun
var classColor = ['red', '#ebc709', '#ecf23f', '#4ec71a', '#228B22'];
var className = ['Suv yoki boshqa obyektlar', 'Bo\'sh maydon', 'Vegetatsiya kam', 'Vegetatsiya o\'rtacha', 'Vegetatsiya yaxshi'];



// Ekinlarni rang bo'yicha chiqarish
var crops_colors= ee.Dictionary({
'16': 'ebeb34',
'51': 'gray',
'62': 'green',
})



var styled = crops
  .map(function (feature) {
    return feature.set('style', {
      fillColor: crops_colors.get(feature.get('crop_id'), 'gray'),
      width: 0, color: 'red'
    });
  })
  .style({
    styleProperty: 'style',
  });

// Sentinel 2 ma'lumotlarini filterlash
var startDate = '2023-09-05';
var endDate = '2023-09-20';

var sentinel2 = ee.ImageCollection('COPERNICUS/S2')
  .filterBounds(crops)
  .filterDate('2023-09-05', '2023-09-20')
  .select(['B8', 'B4'])
  .mosaic()
  
var ndvi = sentinel2.normalizedDifference(['B8', 'B4']).rename('NDVI').clip(crops);

 var ndviClasses = ee.Image.constant(0).byte()
      .where(ndvi.gte(-0.1).and(ndvi.lt(0.2)), 1)
      .where(ndvi.gte(0.2).and(ndvi.lt(0.3)), 2)
      .where(ndvi.gte(0.3).and(ndvi.lt(0.4)), 3)
      .where(ndvi.gte(0.4).and(ndvi.lt(0.6)), 4)
      .where(ndvi.gte(0.6).and(ndvi.lt(1)), 5)

    

// Xaritaga ekin maydonlarini qo'shish
Map.centerObject(crops, 12)
Map.addLayer(styled, {},  "Ekinlar")

// Chap Panel
var LeftPanel = ui.Panel({
        layout: ui.Panel.Layout.flow("vertical"),
        style: {
            width: "25%"
      }
})

// Chap Panel elementlari

// Web xaritaga nom berish
LeftPanel.add(ui.Label({
          value: "Buxoro Agro klaster",
          style: {
            fontWeight: 'bold',
            fontSize: '25px',
            textAlign: 'center',
            position: 'top-center',
            color: 'red'
          }
}))

// Web xarita uchun tarif
LeftPanel.add(ui.Label({
          value: "“BUXORO АGROKLАSTER” masʼuliyati cheklangan jamiyati Oʼzbekiston Respublikasining Fuqarolik kodeksi, “Аksiyadorlik jamiyatlari va aktsiyadorlarning huquqlarini himoya qilish toʼgʼrisida”gi va “Masʼuliyati cheklangan va qoʼshimcha masʼuliyatli jamiyatlar tugʼrisida”gi Qonuni hamda “Buxoropaxtasanoat XB” aktsiyadorlik jamiyati aktsiyadorlarining 2019 yil 06 iyuldagi va 11 iyuldagi navbatdan tashqari umumiy yigʼilish qarorlariga muvofiq tashkil etilgan. Ishtirokchilarning 2019 yil 14 dekabrdagi navbatdan tashqari umumiy yigʼilish qarori bilan yangi taxrirda tasdiqlangan.",
          style: {
            fontSize: '15px',
          }
}))


// Ekin turini tanlash uchun label
LeftPanel.add(ui.Label({
          value: "Ekin turlarini tanlash",
          style: {
            fontWeight: 'bold',
            fontSize: '25px',
            textAlign: 'center',
            position: 'top-center',
            color: 'blue'
          }
}))

// Ekin turini tanlash uchun selector
LeftPanel.add(ui.Select({
  items: ['Barchasi', 'Bug\'doy', 'Paxta'],
  value: 'Barchasi',
  onChange: function(selected){
    var selected_features
    
    if (selected == 'Barchasi')
      selected_features=styled
    else if (selected == 'Bug\'doy')
      selected_features=crops.filter(ee.Filter.eq('crop_id', 16)).style({ color: "red", width: 0, fillColor: "ebeb34"})
    else if (selected == 'Paxta')
      selected_features=crops.filter(ee.Filter.eq('crop_id', 62)).style({ color: "red", width: 0, fillColor: "green"})
    
    ShowNDVI.setValue(false)


    Map.remove(Map.layers().get(0))
    Map.addLayer(selected_features, {},  "Ekinlar")
  }
}))


// NDVI ni ko'rsatish uchun Checkbox
var ShowNDVI = ui.Checkbox({ 
    label: 'NDVI Indekslarini ko\'rish',
    value: 0,
    onChange: function(selected){ 
      print(selected)
      if (selected){
        Map.addLayer(ndviClasses.clip(crops), {min: 0, max: 5, palette: classColor}, "NDVI")
      } else {

        Map.remove(Map.layers().get(1))
      }
    }      
})


LeftPanel.add(ShowNDVI)


// NDVI klassifikatsiyasini ko'rsatish uchun Lege
var Legend = ui.Panel({
  style: {position: 'bottom-left', padding: '8px', width: '300px'}
})
Legend.add(ui.Label({
        value: "NDVI klassifikatsiyasi",
        style: {margin: '10px 6px', fontWeight: 'bold'}
}))


for (var i=0; i < className.length; i++) {

  var colorbar = ui.Label({
          style: {backgroundColor: classColor[i], padding: '10px 20px', margin: '5px'}
        })
        
  var nameLegend = ui.Label({
          value: className[i],
          style: {margin: '0 0 4px 6px'}
        })
  
  Legend.add(ui.Panel({
          widgets: [colorbar, nameLegend],
          layout: ui.Panel.Layout.Flow('horizontal')
        })
      )
}

LeftPanel.add(Legend)


// Popup
Map.onClick(function(coords) {
  var clickPoint = ee.Geometry.Point(coords.lon, coords.lat);
  clickPoint.evaluate(function(res){
    var selected_feature = crops.filterBounds(clickPoint).first()
    
    print(selected_feature.get('crop_title'))
    print(selected_feature.get('area_ha'))
  })
})



ui.root.insert(0, LeftPanel)

https://geoinfouz.projects.earthengine.app/view/buxoro-klaster