City

todo

class blocksnet.models.city.BuildingRow(*, geometry: Point, index: int, population: int = 0, floors: float, area: float, living_area: float, is_living: bool)[source]

Bases: BaseRow

geometry: Point
population: int
floors: float
area: float
living_area: float
is_living: bool
class blocksnet.models.city.ServiceRow(*, geometry: Point, index: int, capacity: int)[source]

Bases: BaseRow

geometry: Point
capacity: int
class blocksnet.models.city.Block(**data: Any)[source]

Bases: BaseModel

Class presenting city block

id: int

Unique block identifier across the `city`

geometry: InstanceOf[Polygon]

Block geometry presented as shapely `Polygon`

landuse: str

Current city block landuse

buildings: InstanceOf[gpd.GeoDataFrame]

Buildings `GeoDataFrame`

services: InstanceOf[dict[ServiceType, gpd.GeoDataFrame]]

Services ```GeoDataFrames```s for different ```ServiceType```s

city: InstanceOf[City]

`City` instance that contains the block

property area
property industrial_area
property living_area
to_dict(simplify=True) dict[str, int][source]
__contains__(service_type_name: str) bool[source]

Returns True if service type is contained inside the block

__getitem__(service_type_name: str) dict[str, int][source]

Get service type capacity and demand of the block

update_buildings(gdf: GeoDataFrame[BuildingRow] | None = None)[source]

Update buildings GeoDataFrame of the block

update_services(service_type: ServiceType, gdf: GeoDataFrame[ServiceRow] | None = None)[source]

Update services GeoDataFrame of the block

property is_living: bool
property population: int

Return sum population of the city block

classmethod from_gdf(gdf: GeoDataFrame, city: City) dict[int, blocksnet.models.city.Block][source]

Generate blocks dict from `GeoDataFrame`

__hash__()[source]

Make block hashable, so it can be used as key in dict etc.

class blocksnet.models.city.City(blocks_gdf: GeoDataFrame, adjacency_matrix: DataFrame)[source]

Bases: object

epsg: int
adjacency_matrix: DataFrame
property blocks: list[blocksnet.models.city.Block]

Return list of blocks

property service_types: list[blocksnet.models.service_type.ServiceType]

Return list of service types

plot() None[source]

Plot city model data

get_service_type_gdf(service_type: ServiceType | str)[source]
get_buildings_gdf() GeoDataFrame[source]
get_services_gdf() GeoDataFrame[source]
get_blocks_gdf(simplify=True) GeoDataFrame[source]
update_buildings(gdf: GeoDataFrame)[source]

Update buildings in blocks

update_services(service_type: ServiceType | str, gdf: GeoDataFrame)[source]

Update services in blocks of certain service_type

add_service_type(service_type: ServiceType)[source]
get_distance(block_a: int | Block, block_b: int | Block)[source]

Returns distance (in min) between two blocks

get_out_edges(block: int | Block)[source]

Get out edges for certain block

get_in_edges(block: int | Block)[source]

Get in edges for certain block

static from_pickle(file_path: str)[source]

Load city model from a .pickle file

to_pickle(file_path: str)[source]

Save city model to a .pickle file