Skip to main content
Tweeted twitter.com/StackGIS/status/1111417880304742405
Bumped by Community user
naming; removed apology and appreciation
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

Google earth engineEarth Engine: how to select ndviNDVI for some land cover type

I am quite new to both Google Earth Engine and Javascript. Sorry if my question is trivialJavaScript. My goal is to obtain the ndviNDVI just for some region (some polygon) only in the selected cover type. I managed to compute areas and number of pixels for every cover type. I have the ndviNDVI for all the region. Now I would like to select the ndviNDVI just in some land cover type (e.g. LC_Type=10 'grassland').

Here is my code so far. Thank you in advance.

Google earth engine: how to select ndvi for some land cover type

I am quite new to both Google Earth Engine and Javascript. Sorry if my question is trivial. My goal is to obtain the ndvi just for some region (some polygon) only in the selected cover type. I managed to compute areas and number of pixels for every cover type. I have the ndvi for all the region. Now I would like to select the ndvi just in some land cover type (e.g. LC_Type=10 'grassland').

Here is my code so far. Thank you in advance.

Google Earth Engine: how to select NDVI for some land cover type

I am quite new to both Google Earth Engine and JavaScript. My goal is to obtain the NDVI just for some region (some polygon) only in the selected cover type. I managed to compute areas and number of pixels for every cover type. I have the NDVI for all the region. Now I would like to select the NDVI just in some land cover type (e.g. LC_Type=10 'grassland').

Here is my code so far.

Source Link
Marta
  • 33
  • 2

Google earth engine: how to select ndvi for some land cover type

I am quite new to both Google Earth Engine and Javascript. Sorry if my question is trivial. My goal is to obtain the ndvi just for some region (some polygon) only in the selected cover type. I managed to compute areas and number of pixels for every cover type. I have the ndvi for all the region. Now I would like to select the ndvi just in some land cover type (e.g. LC_Type=10 'grassland').

Here is my code so far. Thank you in advance.

var modis_landcover = ee.ImageCollection("MODIS/006/MCD12Q1"),
modis_reflectance = ee.ImageCollection("MODIS/006/MOD09GA"),
roi = /* color: #d63000 */ee.Geometry.Polygon(
    [[[37.83249743231477, 11.586900001191903],
      [40.64499743231477, 11.500787248991408],
      [40.16159899481477, 13.943967698396829],
      [38.05222399481477, 13.85865131156253]]]);

Map.centerObject(roi,6);

// select dates for land cover
var lcSeries=modis_landcover.filterDate('2000-01-01', '2017-12-31');
print('MODIS lc series:', lcSeries);

//select dates for reflectance/ndvi
var reflSeries=modis_reflectance.filterDate('2001-01-01', '2001-12-31');
print('MODIS refl series:', reflSeries);

var lc=modis_landcover.filterBounds(roi)
                         .filterDate('2010-01-01')
                         .select('LC_Type1');
print('lc filtered per year and type: ',lc);
var refl=modis_reflectance.filterBounds(roi)
                          .filterDate('2010-09-01')
                          .first();

// Use the normalizedDifference(A, B) to compute (A - B) / (A + B)
var ndvi=refl.normalizedDifference(['sur_refl_b02','sur_refl_b01']);
// Make a palette: a list of hex strings.
var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
               '74A901', '66A000', '529400', '3E8601', '207401', '056201',
               '004C00', '023B01', '012E01', '011D01', '011301'];
var palette2=['05450a', '086a10', '54a708', '78d203', '009900', 'c6b044', 'dcd159',
    'dade48', 'fbff13', 'b6ff05', '27ff87', 'c24f44', 'a5a5a5', 'ff6d4c',
    '69fff8', 'f9ffa4', '1c0dff'];

var ndvi_roi=ndvi.clip(roi);
var lc_roi=lc.map(function(img) {return img.clip(roi)});
Map.addLayer(ndvi_roi, {min: 0, max: 1, palette: palette}, 'NDVI');
Map.addLayer(lc_roi,{min: 1, max: 17, palette: palette2},'land cover');

//area of the region in Km^2
print('Polygon area in km^2: ', roi.area().divide(1000 * 1000));


// Get the scale of the data from the first band's projection:
var modisScale = refl.select('sur_refl_b01')
    .projection().nominalScale();
print('MODIS scale in meters:', modisScale);

var lc_image=lc.first();
var c = lc_image.reduceRegion({
  reducer: ee.Reducer.count(),
  geometry: roi
  });
  print(c);

var frequency = lc_image.reduceRegion({
      reducer:ee.Reducer.frequencyHistogram(),
      geometry:roi,
      scale:1000
    });
    print('landcover frequency', frequency.get('LC_Type1'));