0

I want to convert a google earth image to a numpy array and use Google Earth Engine's Reducer.toList operation. But the size of array I get is different than the size of image as I see in image metadata. Below is the code. I have a sentinel 2 image that I clip it to an area and then look at clipped image dimensions, which will be 11x12. However, reducing it will give me an array of 11x11 elements (the resolution of sentinel band B2 is 10 meters and I mentioned in in reducer parameters). What is the problem with different results?

area = ee.Geometry.Polygon(
    [[[105.532, 19.059], [105.533, 19.059], [105.533, 19.060], [105.532, 19.060], [105.532, 19.059]]])

image = ee.Image("COPERNICUS/S2/20160209T034234_20160209T090731_T48QWG").select('B2')
image_clip = image.clip(area)
info = image_clip.getInfo()
dims = info['bands'][0].get('dimensions')
print(dims)
# Will give us [11, 12] -> 132 pixels

reduced = image.reduceRegion(
    reducer=ee.Reducer.toList(),
    geometry=area,
    maxPixels=1e8,
    scale=10);
data = np.array(reduced.get('B2').getInfo())
print(data.size)
# Will give us a list of 11x11 = 121 pixels

1 Answer 1

2

Your polygon doesn't exactly select an even an number of pixels; the border pixels are only partially overlapped by the polygon. The reduce is only including the pixels that are at least 50% inside the polygon.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.