Convert raster to dataframe
raster_to_dataframe(raster, bands=None, add_coordinates=False, nodata_value=None)
Convert raster to Pandas DataFrame.
If bands are not given, all bands are used for conversion. Selected bands are named based on their index e.g., band_1, band_2,...,band_n. If wanted, image coordinates (x, y) for each pixel can be written to dataframe by setting add_coordinates to True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raster |
DatasetReader
|
Raster to be converted. |
required |
bands |
Optional[Sequence[int]]
|
Selected bands from multiband raster. Indexing begins from one. Defaults to None. |
None
|
add_coordinates |
bool
|
Determines if pixel coordinates are written into dataframe. Defaults to False. |
False
|
nodata_value |
Optional[float]
|
Specifies the value to be considered as NoData. If None, raster's nodata value is used. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
Raster converted to a DataFrame. |
Raises:
Type | Description |
---|---|
InvalidRasterBandException
|
All selected bands are not contained in the input raster. |
Source code in eis_toolkit/conversions/raster_to_dataframe.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|