Search code examples
google-earth-engine

Pixel values Google Earth Engine


In Google Earth Engine, is it possible to obtain the pixel values of an image? The following code displays the details of the image and we can see that the image has 10980*10980 pixels for the bands 2,3 and 4. How can we obtain the pixel value of band 3 at the (x,y) pixel or a specific (lat,lon)?

var im1 = ee.Image('COPERNICUS/S2/20160422T084804_20160422T123809_T36TVK')
print(im1)

Solution

  • // Image
    var im1 = ee.Image('COPERNICUS/S2/20160422T084804_20160422T123809_T36TVK')
    
    // Point
    var p = ee.Geometry.Point(32.3, 40.3)
    
    // Extract the data
    var data = im1
    .select("B3")
    .reduceRegion(ee.Reducer.first(),p,10)
    .get("B3")
    
    // Convert to Number for further use
    var dataN = ee.Number(data)
    
    // Show data
    print(dataN)
    
    // Add Layers
    Map.centerObject(im1)
    Map.addLayer(im1,{bands:["B4","B3","B2"],min:0,max:5000})
    Map.addLayer(p)