April 11

GEE APP 4

var chegara = ee.FeatureCollection('projects/geoinfouz/assets/quyichirchiq')

Map.centerObject(chegara, 11);
Map.addLayer(chegara.style({color:"red", fillColor: "#00000000"}))

var sentinel2 = ee.ImageCollection('COPERNICUS/S2_SR_HARMONIZED')
                  .filterBounds(chegara)
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 30))
                  .sort('CLOUDY_PIXEL_PERCENTAGE')

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

var yearSelect = ui.Select({
  items: ['Sanani tanlang', 'Mart', '10-aprel', '25-aprel', '5-may', '15-may', '25-may', '5-iyun', '15-iyun', '25-iyul', '5-iyul', '15-iyul', '25-iyul', '5-avgust', '15-avgust', '25-avgust', '5-sentaybr', '15-sentaybr', '25-sentaybr', '5-oktyabr', '15-oktyabr', '25-oktyabr', '5-noyabr','15-noyabr', '25-noyabr', '5-dekabr'],
  value: 'Sanani tanlang',
  onChange: function(selectedYear) {
    var img
    if (selectedYear == 'Mart')
      img = sentinel2.filterDate("2023-03-01", "2023-03-20")
    if (selectedYear == '10-aprel')
        img = sentinel2.filterDate("2023-04-01", "2023-04-15")
    if (selectedYear == '25-aprel')
        img = sentinel2.filterDate("2023-04-16", "2023-04-30")
    if (selectedYear == '15-may')
      img = sentinel2.filterDate("2023-05-11", "2023-05-20")
    if (selectedYear == '25-may')
      img = sentinel2.filterDate("2023-05-21", "2023-05-30")
    if (selectedYear == '5-iyun')
      img = sentinel2.filterDate("2023-06-01", "2023-06-09")
    if (selectedYear == '15-iyun')
      img = sentinel2.filterDate("2023-06-10", "2023-06-29")   
    if (selectedYear == '25-iyun')
      img = sentinel2.filterDate("2023-06-20", "2023-06-30")
    if (selectedYear == '25-iyun')
      img = sentinel2.filterDate("2023-06-20", "2023-06-30")
    if (selectedYear == '5-iyul')
      img = sentinel2.filterDate("2023-07-01", "2023-07-10")
    if (selectedYear == '15-iyul')
      img = sentinel2.filterDate("2023-07-11", "2023-07-20")
    if (selectedYear == '25-iyul')
      img = sentinel2.filterDate("2023-07-21", "2023-07-30")
    if (selectedYear == '5-avgust')
      img = sentinel2.filterDate("2023-08-01", "2023-08-10")
    if (selectedYear == '15-avgust')
      img = sentinel2.filterDate("2023-08-11", "2023-08-20")      
    if (selectedYear == '25-avgust')
      img = sentinel2.filterDate("2023-08-21", "2023-08-30") 
    if (selectedYear == '5-sentaybr')
      img = sentinel2.filterDate("2023-09-01", "2023-09-10")  
    if (selectedYear == '15-sentaybr')
      img = sentinel2.filterDate("2023-09-11", "2023-09-20") 
    if (selectedYear == '25-sentaybr')
      img = sentinel2.filterDate("2023-09-21", "2023-09-30")
    if (selectedYear == '5-oktaybr')
      img = sentinel2.filterDate("2023-10-01", "2023-10-10")
    if (selectedYear == '15-oktaybr')
      img = sentinel2.filterDate("2023-10-11", "2023-10-20")
    if (selectedYear == '25-oktaybr')
      img = sentinel2.filterDate("2023-10-21", "2023-10-30")
    if (selectedYear == '5-noyabr')
      img = sentinel2.filterDate("2023-11-01", "2023-11-10")
    if (selectedYear == '15-noyabr')
      img = sentinel2.filterDate("2023-11-11", "2023-11-20")
    if (selectedYear == '25-noyabr')
      img = sentinel2.filterDate("2023-11-21", "2023-11-30")
    if (selectedYear == '5-dekabr')
      img = sentinel2.filterDate("2023-12-01", "2023-12-15")
    var ndvi = img.select(['B8', 'B4']).median().clip(chegara).normalizedDifference(['B8', 'B4']).rename('NDVI');
    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)

    Map.layers().reset();
    Map.addLayer(chegara.style({color:"red", fillColor: "#00000000"}))
    Map.addLayer(ndviClasses.clip(chegara), {min: 0, max: 5, palette: classColor}, selectedYear);

  },
  style: {width: '200px'}
});


var yearPanel = ui.Panel({
  widgets: [
    ui.Label('Vaqtni ko\'rsating:', {fontWeight: 'bold'}),
    yearSelect
  ],
  style: {
    position: 'top-right',
    padding: '10px'
  }
});
Map.add(yearPanel);

var Legend = ui.Panel({
  style: {position: 'bottom-left', padding: '8px', width: '300px'}
})
Legend.add(ui.Label({
        value: "Shartli belgilar",
        style: {margin: '10px 6px', fontWeight: 'bold'}
}))

Map.add(Legend);

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')
        })
      )
}

Map.add(ui.Label({
  value: "Quyichirchiq tumani qishloq xo'jaligi yerlari vegetatsiyasi",
  style: {
    color: "red",
    position: 'top-center',
    padding: '10px',
    fontWeight: 'bold',
    fontSize: '25px'
    
  }
}))

https://geoinfouz.projects.earthengine.app/view/quyichirchiq