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)[source]#

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 latter 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, this 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. If name is not given the raster data will be returned as a numpy array.

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 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 cells. Current options are interpolate and nearest. nearest is best suited for discrete data where values between the discrete classes are not allowed.

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 100) if the interpolate method is selected, ignored if nearest is selected and for all the nodata values if None is used as method.