0

Recently while working with GEE in python I was trying to slice a Landsat image to get its bands and grid for a specific area.

On the first stage I sampled a neighborhood around a point with radius 150 pixels (i.e. 4500 m):

neighborhood = image.neighborhoodToArray(kernel=ee.Kernel.square(radius=150, units='pixels'))
data = neighborhood.sampleRectangle(point)
result_dict = data.getInfo()

After doing so I managed to obtain an array containing values for each band I selected:

array = np.empty((10,301,301))
for i, key in enumerate(bands):
  region = result_dict['properties'][key]
  array[i] = region[0][0][:][:]

So my question is how to get a geographical grid for this data?

In other words, is it possible to access latitudes and longitudes as a raster layer and extract it?

I know how to do that using rasterio and gdal, but it requires direct download of the data, which I'd like to avoid.

1 Answer 1

0

Add the bands from ee.Image.pixelLonLat() to your image. But getInfo is not the right way to get the pixels. Check out ee.data.computePixels(). It'll even give you numpy format if you ask for it.

1
  • Thanks for your help! These functions turned out to be really useful=) Commented Mar 10 at 3:47

Your Answer

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

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