2

I have 21 polygons and for each polygon I want to extract the pixel values inside them for Sentinel 1 images from 2017-01-01 to 2017-06-30.

The example below shows how this is done for one polygon. I want this for 21 polygons. Extract complete pixel values inside a geometry

My expected output is a csv with columns polygon name, lat, lon, VH, VV and system:time start dates.

This is what I have so far.

//Location Data
var test= loc;
print(test);
Map.centerObject( test, 10);


// SENTINEL 1 DATA  
var pol = ['VV', 'VH']; 
//Load Sentinel1 image location around location 1
var Sentinel1= S1.filter(ee.Filter.eq('transmitterReceiverPolarisation', pol))
                    .filterMetadata('instrumentMode', 'equals', 'IW')
                    .filterDate('2017-01-01', '2017-06-30')
                    .filterBounds(test)
                    .select(['VH', 'VV'])
                    .filterMetadata('resolution_meters', 'equals' , 10).first();

Map.addLayer(Sentinel1, imageVisParam, 'single_image');
print(Sentinel1)

// generate a new image containing lat/lon of the pixel and reproject it to Sentinel1 projection
var coordsImage = ee.Image.pixelLonLat().reproject(Sentinel1.projection())
var joinedImage = coordsImage.addBands(Sentinel1);
print(joinedImage)

// extract lat/lon coordinates as a list
var newfc= test.map(function(feat){
var coords = joinedImage.reduceRegion({
  reducer: ee.Reducer.toList(4), 
  geometry: feat.geometry(),
  scale: 10

}).values().get(0)

coords = ee.List(coords)


//Export as CSV
var myFeatures = ee.FeatureCollection(coords.map(function(el){
  el = ee.List(el) // cast every element of the list
  var geom = ee.Geometry.Point([ee.Number(el.get(0)), ee.Number(el.get(1))])
  return ee.Feature(null, {'VH':ee.Number(el.get(2)), 'VV':ee.Number(el.get(3)),
  'Long':ee.Number(el.get(0)),'Lat':ee.Number(el.get(1))})

}))

return myFeatures
})

var table= newfc.flatten()

print(newfc);
print(table)

// Export the image, specifying scale and region.
// Export the FeatureCollection.
Export.table.toDrive({
  collection: table,
  description: 'TRIAL',
  fileFormat: 'CSV'
});

//_____________________________________

Link to locations table: https://code.earthengine.google.com/?asset=users/rawailnaeem/test

Right now it is working fine for 1 image. I need this for each image in the imageCollection, not a mosaic image. So basically my question is how to loop this function over the entire image collection?

  • Please, explain better (in this post) what are you trying to do, what is the expected result, what works and what does not. And also add the code in the post (leave the link as well) – Rodrigo E. Principe Sep 3 '18 at 20:48
  • @RodrigoE.Principe I have added the full description. I hope it makes sense now. Thank you – Rawail Naeem Sep 4 '18 at 6:07
  • @RodrigoE.Principe any luck with this one? The code is working fine for a single image. I just need to include a function so it gets images from the image collection. – Rawail Naeem Sep 5 '18 at 10:41
  • Hi, sorry, I haven't had the time to look at it – Rodrigo E. Principe Sep 5 '18 at 18:42
0

The comment by @Rodrigo E. Principe is probably what you are looking for.

You basically go through each feature with the .map(myFunction) and then in myFunction you iterate through the image collection.

Extracting pixel values by points and converting to table in Google Earth Engine?

  • Can't get it right. Can yo please show how it can be implemented on this code? – Rawail Naeem Sep 17 '18 at 11:03

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.