Monday 23 April 2018

remote sensing - Extract Pixel Values for Multiple Polygons and Images


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?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...