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.

BERA
  • 72,339
  • 13
  • 72
  • 161
ImanolUr
  • 1,102
  • 1
  • 10
  • 21
  • 2
    Is this what you want to do? https://gis.stackexchange.com/questions/271226/up-sampling-increasing-resolution-raster-image-using-gdal – BERA Sep 18 '18 at 09: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 Sep 18 '18 at 13:27

1 Answers1

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.

nyquist
  • 148
  • 7