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
RasterLayerand a method (sampleorread) 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 (ifsampleis used) or read therowsandcolsfrom the array (ifreadis 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
sampleis 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.Ifread, the values are extracted using therowsandcolsattributes, 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
interpolateandnearest.nearestis 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
interpolatemethod is selected, ignored ifnearestis selected and for all the nodata values ifNoneis used as method.