pyrsgis.convert.array_to_table

pyrsgis.convert.array_to_table(arr)[source]

Convert 2D or 3D array to table

The function converts single band or multiband raster array to a table where columns represents the input bands and each row represents a cell.

Parameters
arrnumpy array

A single band (2D) or multiband (3D) raster array. Please note that for multiband raster arrays, the band index should be in the beginning, similar to the one generated by the pyrsgis.raster.read function.

Examples

>>> from pyrsgis import raster, convert
>>> input_file = r'E:/path_to_your_file/raster_file.tif'
>>> ds, data_arr = raster.read(input_file)
>>> data_table = convert.array_to_table(data_arr)

Now check the shape of the input and reshaped arrays.

>>> print('Shape of the input array', data_arr.shape)
>>> print('Shape of the reshaped array:', data_table.shape)
Shape of the input array: (6, 800, 400)
Shape of the reshaped array: (320000, 6)

Here, the input was a six band multispectral raster image. Same method applies for single band rasters also.