onstove.VectorLayer#

class onstove.VectorLayer(category: str | None = None, name: str | None = '', path: str | None = None, conn: sqlalchemy.engine.Connection | None = None, query: str | None = None, normalization: str | None = 'MinMax', inverse: bool = False, distance_method: str | None = 'proximity', distance_limit: Callable[[ndarray], ndarray] | None = None, bbox: GeoDataFrame | None = None)[source]#

VectorLayer is an object used to read, manipulate and visualize GIS vector data.

It uses a GeoDataFrame object to store the georeferenced data in a tabular format. It also stores metadata as category and name of the layer, normalization and distance algorithms to use etc. This data structure is used in both the MCA and the OnStove models and the DataProcessor object.

Parameters:
category: str, optional

Category of the layer. This parameter is useful to group the data into logical categories such as “Demographics”, “Resources” and “Infrastructure” or “Demand”, “Supply” and “Others”. These categories are particularly relevant for the MCA analysis.

name: str, optional

Name of the dataset. This name will be used as default in the save() method as the name of the file.

path: str, optional

The relative path to the datafile. This file can be of any type that is accepted by geopandas.read_file.

conn: sqlalchemy.engine.Connection or sqlalchemy.engine.Engine, optional

PostgreSQL connection if the layer needs to be read from a database. This accepts any connection type used by geopandas.read_postgis.

query: str, optional

A query string to filter the data. For more information refer to pandas.DataFrame.query.

See also

read_layer()

normalization: str, default ‘MinMax’

Sets the default normalization method to use when calling the RasterLayer.normalize() for any associated RasterLayer (for example a distance raster). This is relevant to calculate the demand_index, supply_index, clean_cooking_index and assistance_need_index of the MCA model.

inverse: str, optional

Sets the default mode for the normalization algorithm (see RasterLayer.normalize()).

distance_method: str, default ‘proximity’

Sets the default distance algorithm to use when calling the get_distance_raster() method.

distance_limit: Callable object (function or lambda function) with a numpy array as input, optional

Defines a distance limit or range to consider when calculating the distance raster.

Example: lambda function for distance range between 1,000 and 10,000 meters#
>>> distance_limit = lambda  x: (x >= 1000) & (x <= 10000)
bbox: tuple, gpd.GeoDataFrame, gpd.GeoSeries or shapely Geometry, optional

Filter features by given bounding box, GeoSeries, GeoDataFrame or a shapely geometry. For more information refer to geopandas.read_file.

Attributes:
friction

RasterLayer object containing a friction raster dataset used to compute a travel time map.

distance_raster

RasterLayer object containing a distance raster dataset calculated by the get_distance_raster() method using one of the distance methods.

restrictions

List of RasterLayer or VectorLayer used to restrict areas from the distance calculations.

Warning

The use of restrictions is under development and it will be available in future releases.

weight

Value to weigh the layer’s “importance” on the MCA model. It is initialized with a default value of 1.

bounds

Wrapper property to get the west, south, east, north bounds of the dataset using the total_bounds property of Pandas.

style

Dictionary with the styles properties when visualizing vector files.

layer

GeoDataFrame with the vector data.

Methods

copy()

Wrapper class to the deepcopy function of the copy module.

get_distance_raster([method, raster, ...])

This method calls the specified distance calculation method.

mask(mask_layer[, output_path, keep_geom_type])

Wrapper for the geopandas.GeoDataFrame.clip method.

plot([ax, column, style, legend_kwargs, ...])

Plots a map of the layer using custom styles.

proximity(base_layer[, output_path, ...])

Calculates a euclidean proximity distance raster based on the given vector layer.

rasterize([raster, attribute, value, width, ...])

Converts the vector data into a gridded raster dataset.

read_layer(path[, conn, bbox, query])

Reads a dataset from GIS vector data file.

reproject(crs[, output_path])

Wrapper for the geopandas.GeoDataFrame.to_crs method.

save(output_path[, name])

Saves the current VectorLayer into disk.

start_points(raster)

Gets the indexes of the overlapping cells of the VectorLayer with the input RasterLayer.

travel_time([friction, output_path, ...])

Creates a travel time map to the nearest polygon in the layer using a friction surface.