Extracting band values of multiple points in GEE

1.8k views Asked by At

I have a question regarding exporting a data from GEE. I am new to coding and GEE. What I would like to achieve is export pixel band data of points a have managed to upload using Fusion Table. Is is possible for GEE to export band data of those point in form of a table?

My code so far: https://code.earthengine.google.com/8a764b5d22a9f7108152fce1acc1fe16

The code:

// Load a FeatureCollection from a Fusion Table
var CRuHM_small_data = ee.FeatureCollection('ft:1ocXhbAqP_NbA0iE7tivKgKCfTFGseNdibklZj0NX');

// Print and display the FeatureCollection.
Map.addLayer(CRuHM_small_data,{},'CRuHM_small_data');
print(CRuHM_small_data);

//Navigate to area of interest
Map.setCenter(17.3834, -0.8929, 8);

// Select a specific Sentinel-2 image from the archive
var sent2a = ee.Image("COPERNICUS/S2/20170801T090021_20170801T091620_T33MYV");

// Add RGB composite to map, for water/land
Map.addLayer(sent2a,{bands:['B8','B11','B4'], min:0, max:3000}, "water/land");

However, the next step is more complicated for me. 
I was trying this code, but something is missing:(

//exporting band data to table
//Export.table.toDrive(collection, description, folder, 
//fileNamePrefix, fileFormat, selectors),

Export.table.toDrive({
  collection: CRuHM_small_Data,
  description: "CRuHM_small_Data",
  folder: "GEE",
  fileNamePrefix: "Table",
  fileFormat: "CSV",
  selectors: ["ID", "B3", "B2"]
  });
1

There are 1 answers

0
Nishanta Khanal On

So what you want is a function called sampledRegions for the ee.Image object.

In your case it would be something like this

var sampledData = sent2a.sampleRegions({
  collection:CRuHM_small_data,
  scale:10
});

Export.table.toDrive({
  collection: sampledData,
  description: "CRuHM_small_Data",
  folder: "GEE",
  fileNamePrefix: "Table",
  fileFormat: "CSV",
  selectors: ["ID", "B3", "B2"]
});

Since you want band information on the points, you have to sample the bands using the points and then export the sampled points.

Also, since it looks like you are trying to export only information from B2 and B3, it would be better if you did a select on your image before sampling.

Something like the following somewhere before your sampleRegions should do the trick.

sent2a = sent2a.select(['B2', 'B3']);