3

It seems an easy question, but I can't find the Python equivalent of R's Dissaggregate:

Disaggregate a RasterLayer to create a new RasterLayer with a higher resolution (smaller cells)

I expected it in GDAL but no luck so far.

2
  • 2
    Is this what you want to do? gis.stackexchange.com/questions/271226/…
    – Bera
    Commented Sep 18, 2018 at 9:32
  • Actually, yes. So I assume in gdal there is no direct method to do so. Thanks for the hint, it will be easy to implement.
    – ImanolUr
    Commented Sep 18, 2018 at 13:27

1 Answer 1

1

Sounds like you might want something like numpy.repeat. Open the raster as a numpy array by doing array = gdal.Open(file).ReadAsArray(), then use np.repeat for both the x and y axes. Here is an example:

import numpy as np

>>> array = np.random.randint(10,size =(3,3))
>>> array
    array([[6, 1, 6],
           [9, 7, 0],
           [3, 1, 7]])
>>> downsampled_in_x = np.repeat(array,2,axis = 1)
>>> downsampled_in_x
    array([[6, 6, 1, 1, 6, 6],
           [9, 9, 7, 7, 0, 0],
           [3, 3, 1, 1, 7, 7]])
>>> downsampled_in_both = np.repeat(downsampled_in_x,2,axis = 0)
>>> downsampled_in_both
    array([[6, 6, 1, 1, 6, 6],
           [6, 6, 1, 1, 6, 6],
           [9, 9, 7, 7, 0, 0],
           [9, 9, 7, 7, 0, 0],
           [3, 3, 1, 1, 7, 7],
           [3, 3, 1, 1, 7, 7]])

See numpy / scipy docs for more info

Note that this is different from resampling, which one could accomplish by using gdal_translate or similar.

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.