0

I want to cast my ee.Image, to do so I followed this link implementation, but I got this error:

Traceback (most recent call last):
  File "/home/felipe/.local/lib/python3.6/site-packages/ee/data.py", line 338, in _execute_cloud_call
    return call.execute(num_retries=num_retries)
  File "/home/felipe/.local/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper 
    return wrapped(*args, **kwargs)
  File "/home/felipe/.local/lib/python3.6/site-packages/googleapiclient/http.py", line 898, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/value:compute?prettyPrint=false&alt=json returned "Image.sampleRectangle: Fully masked pixels / pixels outside of the image footprint when sampling band 'soilDiff' with no default value set. Note that calling sampleRectangle() on an image after ee.Image.clip() may result in a sampling bounding box outside the geometry passed to clip().">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "exportImgs_v2.py", line 205, in <module>
    array = imageToArray(imgAlerta, rect)
  File "exportImgs_v2.py", line 41, in imageToArray
    print(band_arrs.getInfo())
  File "/home/felipe/.local/lib/python3.6/site-packages/ee/computedobject.py", line 95, in getInfo
    return data.computeValue(self)
  File "/home/felipe/.local/lib/python3.6/site-packages/ee/data.py", line 703, in computeValue
    prettyPrint=False))['result']
  File "/home/felipe/.local/lib/python3.6/site-packages/ee/data.py", line 340, in _execute_cloud_call
    raise _translate_cloud_exception(e)
ee.ee_exception.EEException: Image.sampleRectangle: Fully masked pixels / pixels outside of the image footprint when sampling band 'soilDiff' with no default value set. Note that calling sampleRectangle() on an image after ee.Image.clip() may result in a sampling bounding box outside the geometry passed to clip().

my exact code is the one below:

def imageToArray(img, geomet):
    band_arrs = ee.Image(img).sampleRectangle(ee.Geometry(geomet))
    print(band_arrs.getInfo())
    band_arr_b4 = band_arrs.get('eviDiff')
    band_arr_b5 = band_arrs.get('soilDiff')
    band_arr_b6 = band_arrs.get('mask')

    # Transfer the arrays from server to client and cast as np array.
    np_arr_b4 = np.array(band_arr_b4.getInfo())
    np_arr_b5 = np.array(band_arr_b5.getInfo())
    np_arr_b6 = np.array(band_arr_b6.getInfo())

    print(np_arr_b4.shape)
    print(np_arr_b5.shape)
    print(np_arr_b6.shape)

    np_arr_b4 = np.expand_dims(np_arr_b4, 2)
    np_arr_b5 = np.expand_dims(np_arr_b5, 2)
    np_arr_b6 = np.expand_dims(np_arr_b6, 2)

    rgb_img = np.concatenate((np_arr_b6, np_arr_b5, np_arr_b4), 2)
    print(rgb_img.shape)

    return rgb_img

Does anyone know how can I fix this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.