5

I have the Sentinel 2 (COPERNICUS/S2) ImageCollection and a FeatureCollection of points. I want to extract a time series for each of the points from the band information in the ImageCollection.

So far I have the following code:

// Create a polygon to subset sentinel data 
var poly = ee.Geometry.Polygon(
        [[[13.932985323828689, -14.515258012418162],
          [13.932985323828689, -16.041324207881946],
          [15.690797823828689, -16.041324207881946],
          [15.690797823828689, -14.515258012418162]]], null, false);

// Import sentinel data
var sentinel2 = ee.ImageCollection("COPERNICUS/S2")
  .filterBounds(poly)  // TESTING - Filter by polygon
  .filterDate('2016-02-01', '2019-02-10');  // TESTING - Filter on date

// Create FeatureCollection of points
var features = [
  ee.Feature(ee.Geometry.Point(14.5, -15)),
  ee.Feature(ee.Geometry.Point(14.8, -15.1)),
  ee.Feature(ee.Geometry.Point(14.9, -15.2))
  ];

var points = ee.FeatureCollection(features);

// Define a function that works on a single point in the FeatureCollection
var pointExtract = function(feat) {

  // Get geometry of point
  var geom = feat.geometry();

  // Define a function that gets a point value for an image
  var pointGet = function(img, f) {
    // Duplicate feature
    var newf = ee.Feature(f);

    // Extract band value for pixel
    var value = img.reduceRegion(ee.Reducer.first(), geom, 30).get('B2');

    // Return as a string in the duplicated feature
    return ee.Feature(
      newf.set(ee.String(value)));
  };

  // Iterate over imageCollection to get time series
  var newfeat = ee.Feature(sentinel2.iterate(pointGet, feat));
  return newfeat;
};

// Iterate over points in FeatureCollection to extract time series
var output = points.map(pointExtract);

// Inspect output
print(output);

But I get the error:

FeatureCollection (Error)
Error in map(ID=2):
String: Parameter 'input' is required.

1 Answer 1

1

I assume something similar to this is what you wanted?

var site = ee.Geometry.Polygon(
    [[[13.932985323828689, -14.515258012418162],
      [13.932985323828689, -16.041324207881946],
      [15.690797823828689, -16.041324207881946],
      [15.690797823828689, -14.515258012418162]]], null, false);

var features = [
  ee.Feature(ee.Geometry.Point(14.5, -15)),
  ee.Feature(ee.Geometry.Point(14.8, -15.1)),
  ee.Feature(ee.Geometry.Point(14.9, -15.2))
  ];

var points = ee.FeatureCollection(features);
// Import sentinel data
var sentinel2 = ee.ImageCollection("COPERNICUS/S2")
  .filterBounds(site)  // TESTING - Filter by polygon
  .filterDate('2016-02-01', '2016-10-10');  // TESTING - Filter on date

// Set center Object
Map.centerObject(site);

// Time series at the identified points
var chart = ui.Chart.image.seriesByRegion(sentinel2.select('B2'), points, ee.Reducer.first());
print(chart, "Sentinel2TimeSeries");
3
  • Could you please also suggest a way to filter only the required bands from Sentinel-2 data
    – Akriti
    Apr 21, 2021 at 5:18
  • Hi Akriti, I can. However, can you please ask the question as a separate post since it was not asked in the original question and deserve a post on its own?
    – adwiputra
    Apr 22, 2021 at 13:08
  • Hi Adwiputra, I have asked a question here: gis.stackexchange.com/questions/395577/…
    – Akriti
    May 3, 2021 at 7:28

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.