-2

I am new to GEE with no prior Javascript knowledge. I am trying to find a way to use multiple bounding boxes (which are in bottom-left point x,y and top-right point x,y) from a csv file in order to calculate the mean value of a Vegetation Index within each polygon. Is there any example of this or a similar workflow?

I created a shapefile with the bounding boxes and imported it as an asset. I still fail to find a way to use the shapefile's polygons in order to filter the areas of interest. What would be the way to set my shapefile's bounding boxes as the filter of all Landsat imagery? The script I used is set to an area in Brazil but I fail to understand where this variable is defined.

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 = "2013-01-01"
var end_date = "2018-12-31"
var cloud_cover = 50

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

var landsat8_collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
        .filterDate('2013-01-01', '2019-03-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');
  • Getting the point information from a CSV to an Earth Engine geometry using the JavaScript API is a little move involved. Are you open to sing the Python API where this will be much simpler? – Kel Markert Sep 10 at 16:44
  • @KelMarkert I see. I didn't even know there was a Python API. Could you please guide me through it? – Dimitris Gk Sep 11 at 12:20
  • Here is some information on how to get started with the Python API for Earth Engine. You will want to install the Python API using anaconda on your local machine to access your CSV file. – Kel Markert Sep 13 at 9:32
0

First import your bounding box data to EE, and then add to the code editer. https://support.google.com/earth/answer/176685?hl=en

You can then use the following code to generate the mean value within each polygon:

var meanDictionary_rescale = vegetationIndex.reduceRegion({
  reducer: ee.Reducer.mean(),
  geometry: boundingBox.geometry(),
  scale: 20,
  maxPixels: 1e13
});

// The result is a Dictionary.  Print it.
print(meanDictionary_rescale);
  • I still do not get how to import the bounding boxes properly. I tried to import them as a shapefile but I do not know how to use them to filter the area – Dimitris Gk Sep 11 at 12:22
  • If you have the shapefiles imported as assets then you need to assign them to a variable in the code editer. Then call that geometry in the code above. Make "boundingBox" your variable. It will be helpful to review the documentation - developers.google.com/earth-engine – Pdavis327 Sep 11 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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