3

I want to download a time series of the average pixel value of a buffer around a number of points. In the resulting table, I'd like to have the coordinates of each point as a variable. How to do this?

A strategy seems to be generating the centroids of the buffers and add as a feature, but I can't make the centroid value appear in the table.

Also, what is the .geo() variable in the resulting table in the example below?

Code here



// set of points

var pointList= ee.List(
        [[-133.49345223488783, 28.4392489430013],
         [-134.28446785988783, 27.273691218174367],
         [-135.73466317238783, 27.351783369494303]]);


// turn them into a feature collection
var pointCollection = ee.FeatureCollection(pointList.map(function(p){
  var point = ee.Feature(ee.Geometry.Point(p), {});
  return point;
}));

print(pointCollection);
Map.addLayer(pointCollection);

// generate the buffers
var bufferBy = function(size) {
  return function(feature) {
    return feature.buffer(size);   
  };
};

// adds the centroid to the buffer as a feature
var getCentroids = function(feature) {
  return feature.set({polyCent: feature.centroid()});
};

var pointCollectionBfs = ee.FeatureCollection(pointCollection.map(bufferBy(10000)).map(getCentroids));

print('points Bf',pointCollectionBfs);
Map.addLayer(pointCollectionBfs, {color: 'd63000'}, 'points');

////////////////        //////////////////
// IMAGE COLLECTION - MODIS-Aqua
////////////////        //////////////////
var start = ee.Date('2014-01-01');
var finish = ee.Date('2014-05-31');

var chla = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI')
  .filterDate(start,finish)
  .select('chlor_a');

var coll=pointCollectionBfs ;
var collName='pointBfs' ;

// CHLA
// chla mean
var chla_mean = chla.map(function(image) {
  return image.reduceRegions({
    collection: coll, 
    reducer: ee.Reducer.mean(), 
    scale: 3000
  }).filter(ee.Filter.neq('mean', null))
    .map(function(f) { 
      return f.set('date', image.date());
    })
    .map(function(f) { 
      return f.set('id', image.id());
      });
})
.flatten();

Export.table.toDrive({
  collection: chla_mean,
  description: 'example_chla_mean_'+collName,
  fileFormat: 'CSV'
});

1 Answer 1

2

Following code prints in your csv table the coordinates of centroids as centroid_x, centroid_y (one column for each coordinate). I hope this helps.

// set of points

var pointList= ee.List(
        [[-133.49345223488783, 28.4392489430013],
         [-134.28446785988783, 27.273691218174367],
         [-135.73466317238783, 27.351783369494303]]);


// turn them into a feature collection
var pointCollection = ee.FeatureCollection(pointList.map(function(p){
  var point = ee.Feature(ee.Geometry.Point(p), {});
  return point;
}));

print(pointCollection);
Map.addLayer(pointCollection);

// generate the buffers
var bufferBy = function(size) {
  return function(feature) {
    return feature.buffer(size);   
  };
};

// adds the centroid to the buffer as a feature
var getCentroids = function(feature) {
  return feature.set({polyCent: feature.centroid()});
};

var pointCollectionBfs = ee.FeatureCollection(pointCollection.map(bufferBy(10000))
  .map(getCentroids));

print('points Bf',pointCollectionBfs);
Map.addLayer(pointCollectionBfs, {color: 'd63000'}, 'buffers');

////////////////        //////////////////
// IMAGE COLLECTION - MODIS-Aqua
////////////////        //////////////////
var start = ee.Date('2014-01-01');
var finish = ee.Date('2014-05-31');

var chla = ee.ImageCollection('NASA/OCEANDATA/MODIS-Aqua/L3SMI')
  .filterDate(start,finish)
  .select('chlor_a');

var coll = pointCollectionBfs ;
var collName='pointBfs' ;

// CHLA
// chla mean
var chla_mean = chla.map(function(image) {
  return image.reduceRegions({
    collection: coll, 
    reducer: ee.Reducer.mean(), 
    scale: 3000
  }).filter(ee.Filter.neq('mean', null))
    .map(function(f) { 
      return f.set('centroid_y', f.geometry().centroid().coordinates().get(1));
    })
    .map(function(f) { 
      return f.set('centroid_x', f.geometry().centroid().coordinates().get(0));
    })
    .map(function(f) { 
      return f.set('date', image.date());
    })
    .map(function(f) { 
      return f.set('id', image.id());
      });
}).flatten();

Export.table.toDrive({
  collection: chla_mean,
  description: 'example_chla_mean_' + collName,
  fileFormat: 'CSV'
});

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.