I'm trying to write an earth engine script which extracts the pixel band values inside a polygon. (geometry) Only for pixels completely within the polygon. The polygons will be quite small. (field size)
I have looked through the docs, and searched for this, but am unable to find a solution. Have only found statistical reductions.
// get the dates
var startDate = ee.Date.fromYMD(2018,1,1);
var endDate = ee.Date.fromYMD(2018,2,1);
// Create a geometry representing an export region.
var myGeometry = ee.Geometry.Polygon(
[[[-61.15985870361328, -32.94904673848672],
[-61.152305603027344, -32.944797148619905],
[-61.15659713745117, -32.9395388987784],
[-61.16432189941406, -32.94378874137744]]]);
var landsatCollection = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR");
// Filter image collection to dateRange of interest
var landsatDateCollection = ee.ImageCollection(landsatCollection
.filterDate(startDate,endDate));
//Filter to AOI.
var landsatAOI = ee.ImageCollection(landsatDateCollection
.filterBounds(myGeometry));
// Filter to image with least clouds
var landsatBestImage = ee.Image(landsatAOI
.sort('CLOUD_COVER')
.first());
// Load a landsat image and select three bands.
var landsatDownload = ee.Image(landsatBestImage)
.select(['B4', 'B5']);
/////////
//Added code that was improved after Jon's comments
/////////
// generate a new image containing lat/lon of the pixel and reproject it to Landsat projection
var coordsImage = ee.Image.pixelLonLat().reproject(landsatDownload.projection());
var joinedImage = coordsImage.addBands(landsatDownload);
var valuesList = joinedImage.reduceRegion({
reducer: ee.Reducer.toList(4),
geometry: myGeometry
}).values().get(0);
print(valuesList);
Jon's inspiration on the MODIS script allowed the modification above. The valuesList now contains all the pixel information.
To see how to Export the data in valuesList to a CSV see
Earth Engine convert list with coordinates and values into a feature collection for export