TransWikia.com

Extract Pixel Values for Multiple Polygons and Images

Geographic Information Systems Asked by Rawail Naeem on April 12, 2021

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?

One Answer

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?

Answered by Sean Roulet on April 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP