onstove.DataProcessor#
- class onstove.DataProcessor(project_crs: pyproj.CRS | int | None = 3395, cell_size: tuple[float] = (1000, 1000), output_directory: str = '.')[source]#
Class containing the methods to process the GIS datasets required for the
MCA
and theOnStove
models.- Parameters:
- project_crs: pyproj.CRS or int, default 3395
The coordinate system of the project. The value can be anything accepted by geopandas.GeoDataFrame.to_crs, such as an authority string (eg “EPSG:4326”), a WKT string or an EPSG int. If defined all datasets added to the
DataProcessor
will be reprojected to this crs when calling thereproject_layers()
method. If not defined then thecrs
of thebase_layer
will be used.- cell_size: tuple of float (width, height), default (1000, 1000)
The desired cell size of the raster layers. It should be defined in the units of the used
crs
. If defined, it will be used to rescale all datasets when calling thealign()
method. If not defined, thecell_size
of thebase_layer
will be used.- output_directory: str, default ‘output’
A folder path where to save the output datasets.
- Attributes:
- layers: dict[str, dict[str, ‘RasterLayer’]]
All layers added to the
DataProcessor
using theadd_layer()
method.- mask_layer: VectorLayer
Layer used to mask all datasets when calling the
mask_layers()
method. It is set with theadd_mask_layer()
method.- conn: psycopg2.connect
Connection to a PostgreSQL database, set with the
set_postgres()
method.- base_layer:
RasterLayer to use as template for all raster based data processes. For example, the
align_layers()
uses the grid cell of this raster to align all other rasters.
Methods
add_layer
(path, layer_type[, category, ...])Adds a new layer (type VectorLayer or RasterLayer) to the DataProcessor class
add_mask_layer
(path[, category, name, ...])Adds a vector layer to self.mask_layer.
align_layers
([datasets, save_layers])Ensures that the coordinate system and resolution of the raster is the same as the base layer
get_distance_rasters
([datasets, save_layers])Calls the .distance_raster method of all the layers entered.
mask_layers
([datasets, crop, save_layers])Uses the mask layer in
self.mask_layer
to mask layers to its boundaries.normalize_rasters
([datasets, buffer, ...])Calls the .normalize method of all the layers entered.
read_model
(path)Reads a model from a pickle
reproject_layers
([datasets, save_layers])Reprojects all layers entered.
save_datasets
([datasets])Saves layers.
set_postgres
(dbname, user, password)Wrapper function to set a connection to a PostgreSQL database using the psycopg2.connect class.
to_pickle
(name)Saves the model as a pickle.