onstove.OnStove.raster_to_dataframe#

OnStove.raster_to_dataframe(layer: RasterLayer | str, name: str | None = None, method: str = 'sample', fill_nodata_method: str | None = None, fill_default_value: float | int = 0)#

Takes a RasterLayer and a method (sample or read) and extracts the values from the raster layer to the main GeoDataFrame (gdf).

It uses the coordinates of the population points (previously extracted with the population_to_dataframe() method) to either sample the values from the dataset (if sample is used) or read the rows and cols from the array (if read is used). The further requires that the raster dataset is aligned with the used population layer.

Parameters:
layer: RasterLayer or path to the raster

Raster layer to extract values from. If the method sample is used, the layer must be provided as the path to the raster file.

name: str, optional

Name to use for the column of the extracted data in the gdf.

method: str, default ‘sample’

Method to use when extracting the data. If sample, the values will be sampled using the coordinates of the point of the GeoDataFrame (gdf), which have been previously defined by the population layer. if read, the values are extracted using the the rows and cols attributes, which have been previously extracted using the population layer.

fill_nodata_method: str, optional

Method to use to fill the no data. Currently only interpolate is available.

fill_default_value: float or int, default 0

Default value to use to fill in the no data. This will be used for cells that fall outside the search radius (currently of 100) if the interpolate method is selected, and for all the nodata values if None is used as method.