blocksnet.preprocessing.blocks_splitter

Module to split blocks based on the distribution of buildings within them.

Classes

BlocksSchema(*args, **kwargs)

Schema for validating blocks GeoDataFrame.

BlocksSplitter(blocks, buildings)

Splits blocks based on the distribution of buildings within them.

BuildingsSchema(*args, **kwargs)

Schema for validating buildings GeoDataFrame.

class blocksnet.preprocessing.blocks_splitter.BlocksSchema(*args, **kwargs)[source]

Bases: BaseSchema

Schema for validating blocks GeoDataFrame.

Variables:

_geom_types (list) – List of allowed geometry types for the blocks, default is [shapely.Polygon].

class Config

Bases: Config

name = 'BlocksSchema'
class blocksnet.preprocessing.blocks_splitter.BuildingsSchema(*args, **kwargs)[source]

Bases: BaseSchema

Schema for validating buildings GeoDataFrame.

Variables:

_geom_types (list) – List of allowed geometry types for the buildings, default is [shapely.Point].

class Config

Bases: Config

name = 'BuildingsSchema'
class blocksnet.preprocessing.blocks_splitter.BlocksSplitter(blocks: GeoDataFrame, buildings: GeoDataFrame)[source]

Bases: object

Splits blocks based on the distribution of buildings within them.

Parameters:
  • blocks (gpd.GeoDataFrame) – GeoDataFrame containing block data. Must contain the following columns: - index : int - geometry : Polygon

  • buildings (gpd.GeoDataFrame) – GeoDataFrame containing building data. Must contain the following columns: - index : int - geometry : Point

Raises:

AssertionError – If the Coordinate Reference Systems (CRS) of blocks and buildings do not match.

run(n_clusters: int = 4, points_quantile: float = 0.98, area_quantile: float = 0.95) gpd.GeoDataFrame[source]

Splits blocks based on buildings distribution.

Parameters:
  • n_clusters (int) – Number of clusters to form within each block, default is 4.

  • points_quantile (float) – Quantile value to filter blocks by the number of points, default is 0.98.

  • area_quantile (float) – Quantile value to filter blocks by area, default is 0.95.

Returns:

GeoDataFrame containing all the blocks.

Return type:

gpd.GeoDataFrame

static _drop_index_columns(gdf) None[source]

Drops index columns from a GeoDataFrame if they exist.

Parameters:

gdf (gpd.GeoDataFrame) – GeoDataFrame from which to drop index columns.

static _split_block(block: Polygon, buildings: GeoDataFrame, n_clusters: int) GeoDataFrame[source]

Splits a block into smaller regions based on building locations using Voronoi diagrams and K-Means clustering.

Parameters:
  • block (shapely.Polygon) – The geometry of the block to be split.

  • buildings (gpd.GeoDataFrame) – GeoDataFrame containing the buildings within the block.

  • n_clusters (int) – Number of clusters to form within the block.

Returns:

GeoDataFrame containing the split regions.

Return type:

gpd.GeoDataFrame

run(n_clusters: int = 4, points_quantile: float = 0.98, area_quantile: float = 0.95) GeoDataFrame[source]

Splits blocks based on the distribution of buildings.

Parameters:
  • n_clusters (int) – Number of clusters to form within each block, default is 4.

  • points_quantile (float) – Quantile value to filter blocks by the number of points, default is 0.98.

  • area_quantile (float) – Quantile value to filter blocks by area, default is 0.95.

Returns:

GeoDataFrame containing the split blocks.

Return type:

gpd.GeoDataFrame