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
asked Jan 19, 2019 at 0:41

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.

answered Jan 20, 2019 at 19:56
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.