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]#
VectorLayeris 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
categoryand name of the layer,normalizationanddistancealgorithms to use etc. This data structure is used in both theMCAand theOnStovemodels and theDataProcessorobject.- 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
MCAanalysis.- 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.
See also
- query: str, optional
A query string to filter the data. For more information refer to pandas.DataFrame.query.
See also
- normalization: str, default ‘MinMax’
Sets the default normalization method to use when calling the
RasterLayer.normalize()for any associatedRasterLayer(for example a distance raster). This is relevant to calculate thedemand_index,supply_index,clean_cooking_indexandassistance_need_indexof theMCAmodel.- 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:
frictionRasterLayerobject containing a friction raster dataset used to compute a travel time map.- distance_raster
RasterLayerobject containing a distance raster dataset calculated by theget_distance_raster()method using one of thedistancemethods.- restrictions
List of
RasterLayerorVectorLayerused 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
MCAmodel. It is initialized with a default value of 1.boundsWrapper property to get the west, south, east, north bounds of the dataset using the
total_boundsproperty ofPandas.styleDictionary with the styles properties when visualizing vector files.
- layer
GeoDataFrame with the vector data.
Methods
copy()Wrapper class to the
deepcopyfunction 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
VectorLayerinto disk.start_points(raster)Gets the indexes of the overlapping cells of the
VectorLayerwith the inputRasterLayer.travel_time([friction, output_path, ...])Creates a travel time map to the nearest polygon in the layer using a friction surface.