-
Notifications
You must be signed in to change notification settings - Fork 3
/
workflow.py
110 lines (90 loc) · 3.5 KB
/
workflow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import logging
import geopandas as gpd
import matplotlib.pyplot as plt
import overpy
import pandas as pd
from mpl_toolkits.axes_grid1 import make_axes_locatable
from shapely.geometry import Polygon, box
from tqdm import tqdm
from prclz.blocks.extraction import extract_blocks
from prclz.complexity import get_complexity, get_weak_dual_sequence
from prclz.parcels import get_building_centroids
from prclz.plotting import plot_polygons
def main(xmin: float, ymin: float, xmax: float, ymax: float) -> None:
bbox = box(xmin, ymin, xmax, ymax)
blocks = extract_blocks(bbox)
polygons = gpd.GeoDataFrame(geometry=blocks)
centroids = gpd.GeoDataFrame(geometry=newvariable126)
plot_polygons(blocks)
gpd.sjoin(polygons, centroids, how="right").plot(column="index_left", ax=plt.gca(), zorder=500)
plt.show()
if __name__ == "__main__":
logging.basicConfig(format="%(asctime)s/%(levelname)s - %(message)s", datefmt='%Y-%m-%d %H:%M:%S')
logging.getLogger().setLevel("INFO")
tqdm.pandas()
# hyde park
xmin = -87.7764
xmax = -87.5758
ymin = 41.7873
ymax = 41.8022
# xmin = -87.7596
# xmax = -87.5758
# ymin = 41.7684
# ymax = 41.8022
# south chicago
# xmin = -87.719650268555
# xmax = -87.558288574219
# ymin = 41.768495030303
# ymax = 41.892310594158
# freetown/ckg
# ymin = 8.4676606359473
# xmin = -13.266763687134
# ymax = 8.4968634271965
# xmax = -13.231616020203
# freetown
# xmin = -13.2995606518
# xmax = -13.1678762591
# ymin = 8.4584896524
# ymax = 8.5000670774
#chicago
# ymin = 41.737503724226
# ymax = 41.935487296653
# xmax = -87.758445739746
# xmin = -87.51537322998
bbox = box(xmin, ymin, xmax, ymax)
polygons = extract_blocks(bbox)
downloaded_centroids = get_building_centroids(
south=ymin,
west=xmin,
north=ymax,
east=xmax)
blocks = gpd.GeoDataFrame(geometry=polygons)
centroids = gpd.GeoDataFrame(geometry=downloaded_centroids)
logging.info("Aggregating buildings by street block.")
block_aggregation = gpd.sjoin(blocks, centroids, how="right", op="intersects")
block_aggregation = block_aggregation[pd.notnull(block_aggregation["index_left"])].groupby("index_left")["geometry"].agg(list)
block_aggregation.name = "centroids"
block_centroids = blocks.join(block_aggregation)
block_centroids = block_centroids[pd.notnull(block_centroids["centroids"])]
logging.info("Calculating block complexity.")
block_centroids["weak_duals"] = block_centroids.progress_apply(get_weak_dual_sequence, axis=1)
block_centroids["complexity"] = block_centroids["weak_duals"].progress_apply(get_complexity)
logging.info("Plotting (deviously).")
fig, ax = plt.subplots(1, 1)
divider = make_axes_locatable(ax)
block_centroids.plot(column='complexity', ax=ax, legend=True)
plt.autoscale()
plt.show()
# plot_polygons(blocks, facecolors=[])
# centroid_blocks.plot(markersize=0.01, column="index_left", ax=plt.gca(), zorder=500)
# plt.show()
# bc = block_centroids[11:12].copy()
# bc.apply(get_weak_dual_sequence, axis=1)
# sequence = bc.apply(get_weak_dual_sequence, axis=1).iloc[0]
# plt.figure()
# bc.plot(ax=plt.gca())
# for ((i, g), color) in zip(enumerate(sequence), 'krgby'):
# g.plot(ax=plt.gca(), node_color=color, node_size=5*(i+1), width=0.1, edge_color=color)
# plt.autoscale()
# plt.show()
# main(xmin, ymin, xmax, ymax)