1

I have been trying to use a shapefile consisting of bounding boxes of cities in order to extract the mean value of the tasseled cap vegetation index. I inserted the shapefile as a FeatureCollection and filtered the Image Collection of Landsat 8 based on it.

What I want to achieve is to find a way to calculate the mean value of the index for each polygon and then export them in a dictionary or a table or any other format that I could further analyze it in GIS software. This means that the values should be connected to an ID attribute that each polygon of the shapefile has.

  var boxes = ee.FeatureCollection("users/dimmegkio/CH_GEE_preprocessing");
  var calculateTasseledCap = function (image){
  var b = image.select("B2", "B3", "B4", "B5", "B6", "B7");
  //Coefficients are only for Landsat 8 TOA
    var brightness_coefficents= ee.Image([0.3029, 0.2786, 0.4733, 0.5599, 0.508, 0.1872])
  var greenness_coefficents= ee.Image([-0.2941, -0.243, -0.5424, 0.7276, 0.0713, -0.1608]);
  var wetness_coefficents= ee.Image([0.1511, 0.1973, 0.3283, 0.3407, -0.7117, -0.4559]);
  var fourth_coefficents= ee.Image([-0.8239, 0.0849, 0.4396, -0.058, 0.2013, -0.2773]);
  var fifth_coefficents= ee.Image([-0.3294, 0.0557, 0.1056, 0.1855, -0.4349, 0.8085]);
  var sixth_coefficents= ee.Image([0.1079, -0.9023, 0.4119, 0.0575, -0.0259, 0.0252]);

    var brightness = image.expression(
            '(B * BRIGHTNESS)',
            {
                'B':b,
                'BRIGHTNESS': brightness_coefficents
                }
            );
  var greenness = image.expression(
    '(B * GREENNESS)',
            {
                'B':b,
                'GREENNESS': greenness_coefficents
                }
            );
  var wetness = image.expression(
    '(B * WETNESS)',
            {
                'B':b,
                'WETNESS': wetness_coefficents
                }
            );
  var fourth = image.expression(
      '(B * FOURTH)',
        {
          'B':b,
          'FOURTH': fourth_coefficents
          }
        );
  var fifth = image.expression(
      '(B * FIFTH)',
        {
          'B':b,
          'FIFTH': fifth_coefficents
          }
        );
  var sixth = image.expression(
    '(B * SIXTH)',
    {
      'B':b,
      'SIXTH': sixth_coefficents
      }
    );
  brightness = brightness.reduce(ee.call("Reducer.sum"));
    greenness = greenness.reduce(ee.call("Reducer.sum"));
    wetness = wetness.reduce(ee.call("Reducer.sum"));
    fourth = fourth.reduce(ee.call("Reducer.sum"));
    fifth = fifth.reduce(ee.call("Reducer.sum"));
  sixth = sixth.reduce(ee.call("Reducer.sum"));
  var tasseled_cap = ee.Image(brightness).addBands(greenness).addBands(wetness)
                             .addBands(fourth)
                             .addBands(fifth)
                             .addBands(sixth).rename('brightness','greenness','wetness','fourth','fifth','sixth')
  return tasseled_cap;
};

var start_date = "2018-12-30"
var end_date = "2018-12-31"
var cloud_cover = 10

var select_2018 = ee.Image("LANDSAT/LC08/C01/T1_RT_TOA/LC08_217073_20180613");
var BRD = boxes.geometry();
Map.centerObject(BRD);

var landsat8_collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
        .filterDate('2013-09-01', '2013-12-31')
        .filterMetadata('CLOUD_COVER', 'less_than', cloud_cover)
        .filterBounds(BRD)


var landsat8_tasseled_cap = landsat8_collection.map(calculateTasseledCap);
console.log(landsat8_tasseled_cap.getInfo())
Map.addLayer(landsat8_tasseled_cap,{},'Landsat 8 Tasseled Cap');
Map.addLayer(landsat8_tasseled_cap,{min: 0, max:1, bands:['brightness']},'brightness');
Map.addLayer(landsat8_tasseled_cap,{min: 0, max:1, bands:['greenness']},'greenness');
Map.addLayer(landsat8_tasseled_cap,{min: 0, max:1, bands:['wetness']},'wetness');
Map.addLayer(boxes,{},'Chinese cities bounding boxes');
1

1 Answer 1

2

There is a little more one would need to do to achieve your goal. Basically, you will need to convert the image collection to an image and then map over all of the features and use image.reduceRegion() in the mapping function to get the mean value from each feature. Your result will be a feature collection with the mean values per band as a property that you can then export as a CSV. Here is an example of what you need to add for your desired results:

var landsat8_tasseled_cap = landsat8_collection.map(calculateTasseledCap);

// reduce tasseled cap collection to an image so we can use .reduceRegion()
var tasseledcapImg = landsat8_tasseled_cap.mosaic()

var reducer = ee.Reducer.mean() // change to whichever reducer you would like to use

// map over each feature in the city collection
var city_stats = boxes.map(function(feature){
  // reduce the feature to get band statistics
  var zonalStats = tasseledcapImg.reduceRegion({
    reducer: reducer,
    geometry:feature.geometry(),
    scale:30
  })
  // return same feature but with the zonal stat results
  return feature.set(zonalStats)
})

// view results
print(city_stats)


Here is a full working example. Your feature collection was not shared so I provided an example one in the full example. You will need to add the export function to get the feature collection out of Earth Engine but this should do the trick. I hope this helps.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.