0

I am trying to create a line graph of how the bands in a satellite image change over a 'line' in GEE. I have created a feature collection made up of the bands ('B2','B3','B4', etc) however I don't know how to make this feature collection into a graph representing this.

var dataset = ee.ImageCollection('COPERNICUS/S2')
                  .filterDate('2018-05-01', '2018-05-15')
                  .filterBounds(roi)
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
                  .map(maskS2clouds);

var image = dataset.first();
var data = image.sample({region:line, scale:10, geometries: true})
print(data)

and outputs this:

FeatureCollection (8 elements, 16 columns)
type: FeatureCollection
columns: Object (16 properties)
features: List (8 elements)
0: Feature 0 (Point, 16 properties)
type: Feature
id: 0
geometry: Point (-3.64, 50.30)
properties: Object (16 properties)
B1: 0.16940000653266907
B10: 0.0013000000035390258
B11: 0.29249998927116394
B12: 0.22840000689029694
B2: 0.17190000414848328
B3: 0.1882999986410141
B4: 0.2198999971151352
B5: 0.23330000042915344
B6: 0.26420000195503235
B7: 0.28139999508857727
B8: 0.2653999924659729
B8A: 0.2827000021934509
B9: 0.08699999749660492
QA10: 0
QA20: 0
QA60: 0
1: Feature 1 (Point, 16 properties)
2: Feature 2 (Point, 16 properties)
3: Feature 3 (Point, 16 properties)
4: Feature 4 (Point, 16 properties)
5: Feature 5 (Point, 16 properties)
6: Feature 6 (Point, 16 properties)
7: Feature 7 (Point, 16 properties)
properties: Object (1 property)

How do I make this a chart of pixel location/cross-section (x axis) vs band info (y axis)?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
em28
  • 1

1 Answers1

0

Easiest thing to do is export the data to a CSV and make a chart there. You can even include the X Y coordinates as a seperate column. From there, you can work out how to make a chart.

var dataset = ee.ImageCollection('COPERNICUS/S2')
                  .filterDate('2018-05-01', '2018-05-15')
                  .filterBounds(roi)
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
                  .map(maskS2clouds);

var image = dataset.first();
var data = image.sample({region:line, scale:10, geometries: true})

// Add coordinates as a property to the FeatureCollection
var data =  data.map(function(f) {
      var g = f.geometry().coordinates();
      return f.set('lon', g.get(0))
              .set('lat', g.get(1))
    })

print(data)

// Export data to a CSV
Export.table.toDrive({
  collection: data, 
  description: 'Export_S2_Line',
  fileFormat: 'CSV'
})
CrossLord
  • 574
  • 4
  • 20