2

I have tried to adapt this script but when i use my points for var newft = fg_points.map(mapfunc);

var NDVI_pixels = nut_def_pts.map(mapfunc);

it claims the nut_def_pts.map is 'not a function'. Why would this be?

 //read in the collection, filter it by date and then path which covers all of the Rep of Ireland
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
  .filterDate('2017-01-01', '2018-12-31')
  .filter(ee.Filter.or(
    ee.Filter.and(ee.Filter.eq('WRS_PATH', 208),         
                  ee.Filter.eq('WRS_ROW', 22)),
    ee.Filter.and(ee.Filter.eq('WRS_PATH', 208),         
                  ee.Filter.eq('WRS_ROW', 23)),
    ee.Filter.and(ee.Filter.eq('WRS_PATH', 208),         
                  ee.Filter.eq('WRS_ROW', 24)),              
    ee.Filter.and(ee.Filter.eq('WRS_PATH', 207),         
                  ee.Filter.eq('WRS_ROW', 22)),              
    ee.Filter.and(ee.Filter.eq('WRS_PATH', 207),         
                  ee.Filter.eq('WRS_ROW', 23)),              
    ee.Filter.and(ee.Filter.eq('WRS_PATH', 207),         
                  ee.Filter.eq('WRS_ROW', 24)),
    ee.Filter.and(ee.Filter.eq('WRS_PATH', 206),         
                  ee.Filter.eq('WRS_ROW', 23)),
    ee.Filter.and(ee.Filter.eq('WRS_PATH', 206),         
                  ee.Filter.eq('WRS_ROW', 24))));

//specify what bands you want to use to view the image, in this case RGB
var visParams = {bands: ['B4', 'B3', 'B2'], max: 0.3};

//specify where the centre of the map is to be
Map.setCenter(-9, 53, 8);

//view the map using the predefined dataset and bands
//Map.addLayer(l8, visParams, 'l8_mayo collection');

//get the cloud cover information from the QA
var getQABits = function(image, start, end, newName) {
    // Compute the bits we need to extract.
    var pattern = 0;
    for (var i = start; i <= end; i++) {
       pattern += Math.pow(2, i);
    }
    // Return a single band image of the extracted QA bits, giving the band
    // a new name.
    return image.select([0], [newName])
                  .bitwiseAnd(pattern)
                  .rightShift(start);
};

// A function to mask out cloud shadow pixels.
var cloud_shadows = function(image) {
  // Select the QA band.
  var QA = image.select(['BQA']);
  // Get the internal_cloud_algorithm_flag bit.
  return getQABits(QA, 7,8, 'Cloud_shadows').eq(1);
  // Return an image masking out cloudy areas.
};

// A function to mask out cloudy pixels.
var clouds = function(image) {
  // Select the QA band.
  var QA = image.select(['BQA']);
  // Get the internal_cloud_algorithm_flag bit.
  return getQABits(QA, 4,4, 'Cloud').eq(0);
  // Return an image masking out cloudy areas.
};

//run the cloud cover for the images
var maskClouds = function(image) {
  var cs = cloud_shadows(image);
  var c = clouds(image);
  image = image.updateMask(cs);
  return image.updateMask(c);
};

//create the cloud free images
var l8_cfree = l8.map(maskClouds);

//view the cloud free images
//Map.addLayer(l8_cfree, visParams, 'l8_mayo collection without clouds');

//add NDVI as a column to the multispectral bands data
var addNDVI = function(image) {
  //var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
  var ndvi = image.select('B5').subtract(image.select('B4')).divide((image.select('B5').add(image.select('B4')))).rename('NDVI');
  return image.addBands(ndvi);
};

//map the landsat collect with the cloud free data and the NDVI band
var withNDVI = l8.map(maskClouds).map(addNDVI);

//view the NDVI images
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
Map.addLayer(withNDVI.select('NDVI'), ndviParams, 'NDVI image');

//view the NDVI as a time series
var NDVI_ts = ui.Chart.image.series({
  imageCollection: withNDVI.select('NDVI'),
  region: nut_def_pts,
  reducer: ee.Reducer.median(),
  scale: 30
}).setOptions({title: 'NDVI time series'});

// Display the chart in the console.
print(NDVI_ts);

//creates a function that extracts pixel values for NDVI for each point in
//the geom file for each image and writes to a table
var mapfunc = function(feat) {
  var geom = feat.geometry();
  var addProp = function(img, f) {
    var newf = ee.Feature(f);
    var date = img.date().format();
    var value = img.reduceRegion(ee.Reducer.median(), geom, 30).get('NDVI');
    return ee.Feature(ee.Algorithms.If(value,
                                       newf.set(date, ee.String(value)),
                                       newf.set(date, ee.String('No data'))));
  };
  var newfeat = ee.Feature(withNDVI.iterate(addProp, feat));
  return newfeat;
};

var NDVI_pixels = nut_def_pts.map(mapfunc);


//write to the table
Export.table.toDrive(NDVI_pixels,
"NDVI_extraction", //job name
"EarthEngine", //folder name
"NDVI_pixels"); //file name
4
  • where have you defined nut_def_pts? I don't see its definition in the script Apr 13, 2018 at 11:33
  • Oh they are just 6 points i have entered in from the viewer over Ireland. It doesn't really matter where in Ireland the points are just as long as they are within the tiles
    – Walshe_d
    Apr 13, 2018 at 11:43
  • 1
    What type of Object is it? A FeatureCollection? Apr 13, 2018 at 12:54
  • Ah ha no i had changed from importing the points from a shp file (as a FeatureCollection) to just clicking and importing the data (as a MultiPoint). That fixes it!
    – Walshe_d
    Apr 13, 2018 at 13:32

1 Answer 1

1

As Rodrigo pointed out i had to ensure the points were imported as a FeatureCollection

Your Answer

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

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