0

I am using Google Colab and Earth Engine Python API to extract NDVI value according to date and coordinate. I was trying to follow the guide code from https://gis.stackexchange.com/q/360278; and used print(get('NDVI')) with a sample coordinate to see if I can get any value. Instead of getting a value, this is the result that I got, instead of a numeric number.

Is there anything else I can do?

My example:

#Define a region of interest as a point and buffer 1km around the area
roi = ee.Geometry.Point([-124.0769, 40.1035]).buffer(1000)

#Get Image from Landsat

image = ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_RT')\
                     .filterDate('2014-01-01', '2014-01-01')\
                     .filterBounds(roi))

#Function from https://gis.stackexchange.com/q/360278

def meanNDVICollection (img,aoi):
  nir = img.select('B5')
  red = img.select('B4')
  ndviImage = nir.subtract(red).divide(nir.add(red)).rename('NDVI')

  # Compute the mean of NDVI over the 'region'
  ndviValue = ndviImage.reduceRegion(**{
    'geometry': aoi.getInfo(),
    'reducer': ee.Reducer.mean(),
  }).get('NDVI');  # result of reduceRegion is always a dictionary, so get the element we want

  newFeature = ee.Feature(None, {
      # Adding computed NDVI value
      'NDVI': ndviValue
  }).copyProperties(img, [
      # Picking properties from original image
      'system:time_start'
  ])

  return newFeature

My result:

ee.ComputedObject({
  "functionInvocationValue": {
    "functionName": "Element.get",
    "arguments": {
      "object": {
        "functionInvocationValue": {
          "functionName": "Element.copyProperties",
          "arguments": {
            "destination": {
              "functionInvocationValue": {
                "functionName": "Feature",
                "arguments": {
                  "metadata": {
                    "dictionaryValue": {
                      "values": {
                        "NDVI": {
                          "functionInvocationValue": {
                            "functionName": "Dictionary.get",
                            "arguments": {
                              "dictionary": {
                                "functionInvocationValue": {
                                  "functionName": "Image.reduceRegion",
                                  "arguments": {
                                    "geometry": {
                                      "functionInvocationValue": {
                                        "functionName": "GeometryConstructors.Polygon",
                                        "arguments": {
                                          "coordinates": {
                                            "constantValue": [
                                              [
                                                [
                                                  -124.0769,
                                                  40.11249886595147
                                                ],
                                                [
                                                  -124.08018654971627,
                                                  40.11214066464644
                                                ],
                                                [
                                                  -124.0832113930106,
                                                  40.11109458435475
                                                ],
                                                [
                                                  -124.08573368559792,
                                                  40.10944392209392
                                                ],
                                                [
                                                  -124.08755263737298,
                                                  40.10732010876987
                                                ],
                                                [
                                                  -124.08852350016701,
                                                  40.1048922353547
                                                ],
                                                [
                                                  -124.08856907708011,
                                                  40.10235358218749
                                                ],
                                                [
                                                  -124.0876858411974,
                                                  40.099906227117316
                                                ],
                                                [
                                                  -124.08594418480988,
                                                  40.09774495978181
                                                ],
                                                [
                                                  -124.08348278913968,
                                                  40.09604178254263
                                                ],
                                                [
                                                  -124.0804975711721,
                                                  40.0949322298689
                                                ],
                                                [
                                                  -124.07722609182845,
                                                  40.094504591784705
                                                ],
                                                [
                                                  -124.073928665595,
                                                  40.09479289545506
                                                ],
                                                [
                                                  -124.07086766920538,
                                                  40.095774200623666
                                                ],
                                                [
                                                  -124.06828668714203,
                                                  40.09737042293922
                                                ],
                                                [
                                                  -124.06639114440881,
                                                  40.099454540880345
                                                ],
                                                [
                                                  -124.06533196131409,
                                                  40.10186069488513
                                                ],
                                                [
                                                  -124.065193529275,
                                                  40.10439737846875
                                                ],
                                                [
                                                  -124.06598696817112,
                                                  40.106862674842496
                                                ],
                                                [
                                                  -124.0676492097828,
                                                  40.109060328478726
                                                ],
                                                [
                                                  -124.0700479900754,
                                                  40.11081537264418
                                                ],
                                                [
                                                  -124.07299236167236,
                                                  40.1119880672073
                                                ],
                                                [
                                                  -124.0762478946487,
                                                  40.11248503400732
                                                ],
                                                [
                                                  -124.0769,
                                                  40.11249886595147
                                                ]
                                              ]
                                            ]
                                          }
                                        }
                                      }
                                    },
1

The ouput that you got is expected because you are printing an Earth Engine (i.e. server-side) type object to the screen. To print a ee object to your Collab notebook, you must "extract" the information it contains using .getInfo(). Example:

print(feature.get('NDVI').getInfo())

where fetature is some ee.Feature that is returned from your function meanNDVICollection.

GEE guide on client versus server side objects: https://developers.google.com/earth-engine/guides/client_server

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.