pyrsgis.convert.table_to_array

pyrsgis.convert.table_to_array(table, n_rows=None, n_cols=None)[source]

Convert tablar array to 2D or 3D array

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

Parameters
tablenumpy array

A 2D array where rows represent cells of to be generated raster array and each column represents band. This is similar to the one generated by the pyrsgis.convert.array_to_table 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)
>>> 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)

…some analysis/processing that you may want to do and generate more columns, say two more columns. Then:

>>> new_data_arr = convert.table_to_array(data_table, n_rows=ds.RasterYSize, n_cols=ds.RasterXSize)
>>> print('Shape of the array with newly added bands:', new_data_arr.shape)
Shape of the array with newly added bands: (8, 800, 400)

If you want to reshape only the new band(s), then:

>>> new_data_arr = convert.table_to_array(data_table[:, -2:], n_rows=ds.RasterYSize, n_cols=ds.RasterXSize)
>>> print('Shape of the array with newly added bands:', new_data_arr.shape)
Shape of the array with newly added bands: (2, 800, 400)