City blocks layer generating

[1]:
import os
import geopandas as gpd

# os.environ["USE_PYGEOS"] = os.environ.get("USE_PYGEOS", "0")
local_crs = 32637
# path to data
example_data_path = "./data"

Input data fetch and parameters setting

[2]:
from blocksnet import BlocksGenerator

territory = gpd.read_file(os.path.join(example_data_path, "territory_spb.geojson")).to_crs(local_crs)
water = gpd.read_file(os.path.join(example_data_path, "water_spb.geojson")).to_crs(local_crs)
roads = gpd.read_file(os.path.join(example_data_path, "roads_spb.geojson")).to_crs(local_crs)
railways = gpd.read_file(os.path.join(example_data_path, "railways_spb.geojson")).to_crs(local_crs)

bg = BlocksGenerator(territory=territory, water=water, roads=roads, railways=railways)
[3]:
blocks = bg.generate_blocks()
GENERATING BLOCKS
Setting up enclosures...
Filling holes...
Dropping overlapping blocks...
Calculating blocks area...
Blocks generated.

[4]:
blocks.plot(figsize=[10,10]).set_axis_off()
../_images/examples_blocks_generator_5_0.png
[5]:
from blocksnet.preprocessing import cut_nodev, add_landuse

landuse = gpd.read_file(os.path.join(example_data_path, "pzz.geojson")).to_crs(local_crs)
nodev = gpd.read_file(os.path.join(example_data_path, "nodev.geojson")).to_crs(local_crs)
[6]:
dev_blocks = cut_nodev(blocks, nodev)
/home/vasilstar/masterplanning/venv/lib/python3.10/site-packages/geopandas/geodataframe.py:1538: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  super().__setitem__(key, value)

Save the result for the next example

[7]:
dev_blocks.head()
[7]:
zone nodev geometry
0 NaN False POLYGON ((21301.667 6676631.699, 21301.673 667...
1 NaN False POLYGON ((21487.777 6676572.005, 21487.763 667...
2 NaN False POLYGON ((15408.084 6684829.087, 15397.413 668...
3 NaN False POLYGON ((22851.282 6679792.626, 22851.221 667...
4 NaN False POLYGON ((12124.455 6673991.926, 12099.346 667...
[9]:
landuse_blocks = add_landuse(dev_blocks, landuse)
[10]:
landuse_blocks.head()
[10]:
zone nodev geometry landuse
0 ['Т3Ж1', 'ТИ2', 'ТИ2', 'ТУ', 'ТУ', 'ТУ'] False POLYGON ((21301.667 6676631.699, 21301.673 667... mixed_use
1 ['ТИ2', 'ТИ2', 'ТР0-2', 'ТР0-2', 'ТУ', 'ТУ', '... False POLYGON ((21487.777 6676572.005, 21487.763 667... recreation
2 ['Т3Ж2', 'Т3Ж2', 'Т3Ж2', 'ТИ2', 'ТИ2', 'ТИ2', ... False POLYGON ((15408.084 6684829.087, 15397.413 668... mixed_use
3 ['Т3Ж2', 'ТД2', 'ТД2', 'ТД2', 'ТИ2', 'ТИ2', 'Т... False POLYGON ((22851.282 6679792.626, 22851.221 667... mixed_use
4 ['ТД1-2', 'ТД1-2', 'ТД1-2', 'ТД1-2', 'ТД2', 'Т... False POLYGON ((12124.455 6673991.926, 12099.346 667... mixed_use
[14]:
blocks.to_parquet(os.path.join(example_data_path, "blocks.parquet"))