|
15 | 15 | "metadata": {},
|
16 | 16 | "outputs": [],
|
17 | 17 | "source": [
|
18 |
| - "import momepy\n", |
19 |
| - "import geopandas as gpd\n", |
20 |
| - "import matplotlib.pyplot as plt" |
| 18 | + "import matplotlib.pyplot as plt\n", |
| 19 | + "import momepy" |
21 | 20 | ]
|
22 | 21 | },
|
23 | 22 | {
|
|
52 | 51 | "source": [
|
53 | 52 | "import osmnx as ox\n",
|
54 | 53 | "\n",
|
55 |
| - "gdf = ox.geometries.geometries_from_place('Kahla, Germany', tags={'building': True})\n", |
| 54 | + "gdf = ox.geometries.geometries_from_place(\n", |
| 55 | + " \"Kahla, Germany\", tags={\"building\": True}\n", |
| 56 | + ")\n", |
56 | 57 | "buildings = ox.projection.project_gdf(gdf)\n",
|
57 | 58 | "\n",
|
58 |
| - "buildings['uID'] = momepy.unique_id(buildings)\n", |
| 59 | + "buildings[\"uID\"] = momepy.unique_id(buildings)\n", |
59 | 60 | "limit = momepy.buffered_limit(buildings)\n",
|
60 |
| - "tessellation = momepy.Tessellation(buildings, unique_id='uID', limit=limit).tessellation" |
| 61 | + "tessellation = momepy.Tessellation(\n", |
| 62 | + " buildings, unique_id=\"uID\", limit=limit\n", |
| 63 | + ").tessellation" |
61 | 64 | ]
|
62 | 65 | },
|
63 | 66 | {
|
|
66 | 69 | "metadata": {},
|
67 | 70 | "outputs": [],
|
68 | 71 | "source": [
|
69 |
| - "streets_graph = ox.graph_from_place('Kahla, Germany', network_type='drive')\n", |
| 72 | + "streets_graph = ox.graph_from_place(\"Kahla, Germany\", network_type=\"drive\")\n", |
70 | 73 | "streets_graph = ox.projection.project_graph(streets_graph)\n",
|
71 |
| - "edges = ox.graph_to_gdfs(streets_graph, nodes=False, edges=True,\n", |
72 |
| - " node_geometry=False, fill_edge_geometry=True)" |
| 74 | + "edges = ox.graph_to_gdfs(\n", |
| 75 | + " streets_graph,\n", |
| 76 | + " nodes=False,\n", |
| 77 | + " edges=True,\n", |
| 78 | + " node_geometry=False,\n", |
| 79 | + " fill_edge_geometry=True,\n", |
| 80 | + ")" |
73 | 81 | ]
|
74 | 82 | },
|
75 | 83 | {
|
|
123 | 131 | }
|
124 | 132 | ],
|
125 | 133 | "source": [
|
126 |
| - "buildings['orientation'] = momepy.Orientation(buildings).series\n", |
127 |
| - "tessellation['orientation'] = momepy.Orientation(tessellation).series" |
| 134 | + "buildings[\"orientation\"] = momepy.Orientation(buildings).series\n", |
| 135 | + "tessellation[\"orientation\"] = momepy.Orientation(tessellation).series" |
128 | 136 | ]
|
129 | 137 | },
|
130 | 138 | {
|
|
150 | 158 | }
|
151 | 159 | ],
|
152 | 160 | "source": [
|
153 |
| - "buildings.plot(column='orientation', legend=True, cmap='Spectral',\n", |
154 |
| - " figsize=(10, 10)).set_axis_off()" |
| 161 | + "buildings.plot(\n", |
| 162 | + " column=\"orientation\", legend=True, cmap=\"Spectral\", figsize=(10, 10)\n", |
| 163 | + ").set_axis_off()" |
155 | 164 | ]
|
156 | 165 | },
|
157 | 166 | {
|
|
167 | 176 | "metadata": {},
|
168 | 177 | "outputs": [],
|
169 | 178 | "source": [
|
170 |
| - "blg_cell_align = momepy.CellAlignment(buildings, tessellation,\n", |
171 |
| - " 'orientation', 'orientation',\n", |
172 |
| - " 'uID', 'uID')\n", |
173 |
| - "buildings['cell_align'] = blg_cell_align.series" |
| 179 | + "blg_cell_align = momepy.CellAlignment(\n", |
| 180 | + " buildings, tessellation, \"orientation\", \"orientation\", \"uID\", \"uID\"\n", |
| 181 | + ")\n", |
| 182 | + "buildings[\"cell_align\"] = blg_cell_align.series" |
174 | 183 | ]
|
175 | 184 | },
|
176 | 185 | {
|
|
196 | 205 | }
|
197 | 206 | ],
|
198 | 207 | "source": [
|
199 |
| - "buildings.plot(column='cell_align', legend=True, cmap='Reds',\n", |
200 |
| - " figsize=(10, 10)).set_axis_off()" |
| 208 | + "buildings.plot(\n", |
| 209 | + " column=\"cell_align\", legend=True, cmap=\"Reds\", figsize=(10, 10)\n", |
| 210 | + ").set_axis_off()" |
201 | 211 | ]
|
202 | 212 | },
|
203 | 213 | {
|
|
244 | 254 | }
|
245 | 255 | ],
|
246 | 256 | "source": [
|
247 |
| - "edges['networkID'] = momepy.unique_id(edges)\n", |
248 |
| - "buildings['networkID'] = momepy.get_network_id(buildings, edges,\n", |
249 |
| - " 'networkID').values" |
| 257 | + "edges[\"networkID\"] = momepy.unique_id(edges)\n", |
| 258 | + "buildings[\"networkID\"] = momepy.get_network_id(\n", |
| 259 | + " buildings, edges, \"networkID\"\n", |
| 260 | + ").values" |
250 | 261 | ]
|
251 | 262 | },
|
252 | 263 | {
|
|
332 | 343 | }
|
333 | 344 | ],
|
334 | 345 | "source": [
|
335 |
| - "str_align = momepy.StreetAlignment(buildings_net, edges,\n", |
336 |
| - " 'orientation', 'networkID',\n", |
337 |
| - " 'networkID')\n", |
338 |
| - "buildings_net['str_align'] = str_align.series" |
| 346 | + "str_align = momepy.StreetAlignment(\n", |
| 347 | + " buildings_net, edges, \"orientation\", \"networkID\", \"networkID\"\n", |
| 348 | + ")\n", |
| 349 | + "buildings_net[\"str_align\"] = str_align.series" |
339 | 350 | ]
|
340 | 351 | },
|
341 | 352 | {
|
|
361 | 372 | }
|
362 | 373 | ],
|
363 | 374 | "source": [
|
364 |
| - "ax = edges.plot(color='grey', linewidth=0.5, figsize=(10, 10))\n", |
365 |
| - "buildings_net.plot(ax=ax, column='str_align', legend=True)\n", |
| 375 | + "ax = edges.plot(color=\"grey\", linewidth=0.5, figsize=(10, 10))\n", |
| 376 | + "buildings_net.plot(ax=ax, column=\"str_align\", legend=True)\n", |
366 | 377 | "ax.set_axis_off()"
|
367 | 378 | ]
|
368 | 379 | },
|
|
383 | 394 | "source": [
|
384 | 395 | "point = (40.731603, -73.977857)\n",
|
385 | 396 | "dist = 1000\n",
|
386 |
| - "gdf = ox.geometries.geometries_from_point(point, dist=dist, tags={'building':True})\n", |
| 397 | + "gdf = ox.geometries.geometries_from_point(\n", |
| 398 | + " point, dist=dist, tags={\"building\": True}\n", |
| 399 | + ")\n", |
387 | 400 | "buildings = ox.projection.project_gdf(gdf)\n",
|
388 |
| - "buildings = buildings[buildings.geom_type.isin(['Polygon', 'MultiPolygon'])]" |
| 401 | + "buildings = buildings[buildings.geom_type.isin([\"Polygon\", \"MultiPolygon\"])]" |
389 | 402 | ]
|
390 | 403 | },
|
391 | 404 | {
|
|
400 | 413 | " except ValueError:\n",
|
401 | 414 | " return 0\n",
|
402 | 415 | "\n",
|
403 |
| - "buildings['height'] = buildings['height'].fillna(0).apply(clean_heights)\n", |
| 416 | + "\n", |
| 417 | + "buildings[\"height\"] = buildings[\"height\"].fillna(0).apply(clean_heights)\n", |
404 | 418 | "buildings = buildings.reset_index().explode()\n",
|
405 | 419 | "buildings.reset_index(inplace=True, drop=True)"
|
406 | 420 | ]
|
|
411 | 425 | "metadata": {},
|
412 | 426 | "outputs": [],
|
413 | 427 | "source": [
|
414 |
| - "streets_graph = ox.graph_from_point(point, dist, network_type='drive')\n", |
| 428 | + "streets_graph = ox.graph_from_point(point, dist, network_type=\"drive\")\n", |
415 | 429 | "streets_graph = ox.projection.project_graph(streets_graph)\n",
|
416 |
| - "edges = ox.graph_to_gdfs(streets_graph, nodes=False, edges=True,\n", |
417 |
| - " node_geometry=False, fill_edge_geometry=True)" |
| 430 | + "edges = ox.graph_to_gdfs(\n", |
| 431 | + " streets_graph,\n", |
| 432 | + " nodes=False,\n", |
| 433 | + " edges=True,\n", |
| 434 | + " node_geometry=False,\n", |
| 435 | + " fill_edge_geometry=True,\n", |
| 436 | + ")" |
418 | 437 | ]
|
419 | 438 | },
|
420 | 439 | {
|
|
440 | 459 | }
|
441 | 460 | ],
|
442 | 461 | "source": [
|
443 |
| - "ax = buildings.plot(figsize=(10, 10), color='lightgrey')\n", |
| 462 | + "ax = buildings.plot(figsize=(10, 10), color=\"lightgrey\")\n", |
444 | 463 | "edges.plot(ax=ax)\n",
|
445 | 464 | "ax.set_axis_off()"
|
446 | 465 | ]
|
|
462 | 481 | }
|
463 | 482 | ],
|
464 | 483 | "source": [
|
465 |
| - "profile = momepy.StreetProfile(edges, buildings, heights='height')" |
| 484 | + "profile = momepy.StreetProfile(edges, buildings, heights=\"height\")" |
466 | 485 | ]
|
467 | 486 | },
|
468 | 487 | {
|
|
478 | 497 | "metadata": {},
|
479 | 498 | "outputs": [],
|
480 | 499 | "source": [
|
481 |
| - "edges['widths'] = profile.w\n", |
482 |
| - "edges['width_deviations'] = profile.wd\n", |
483 |
| - "edges['openness'] = profile.o\n", |
484 |
| - "edges['heights'] = profile.h\n", |
485 |
| - "edges['heights_deviations'] = profile.hd\n", |
486 |
| - "edges['profile'] = profile.p" |
| 500 | + "edges[\"widths\"] = profile.w\n", |
| 501 | + "edges[\"width_deviations\"] = profile.wd\n", |
| 502 | + "edges[\"openness\"] = profile.o\n", |
| 503 | + "edges[\"heights\"] = profile.h\n", |
| 504 | + "edges[\"heights_deviations\"] = profile.hd\n", |
| 505 | + "edges[\"profile\"] = profile.p" |
487 | 506 | ]
|
488 | 507 | },
|
489 | 508 | {
|
|
510 | 529 | ],
|
511 | 530 | "source": [
|
512 | 531 | "f, axes = plt.subplots(figsize=(15, 25), ncols=2, nrows=3)\n",
|
513 |
| - "edges.plot(ax=axes[0][0], column='widths', legend=True, cmap='Blues_r')\n", |
514 |
| - "buildings.plot(ax=axes[0][0], color='lightgrey')\n", |
515 |
| - "edges.plot(ax=axes[0][1], column='width_deviations', legend=True)\n", |
516 |
| - "buildings.plot(ax=axes[0][1], color='lightgrey')\n", |
| 532 | + "edges.plot(ax=axes[0][0], column=\"widths\", legend=True, cmap=\"Blues_r\")\n", |
| 533 | + "buildings.plot(ax=axes[0][0], color=\"lightgrey\")\n", |
| 534 | + "edges.plot(ax=axes[0][1], column=\"width_deviations\", legend=True)\n", |
| 535 | + "buildings.plot(ax=axes[0][1], color=\"lightgrey\")\n", |
517 | 536 | "axes[0][0].set_axis_off()\n",
|
518 |
| - "axes[0][0].set_title('widths')\n", |
| 537 | + "axes[0][0].set_title(\"widths\")\n", |
519 | 538 | "axes[0][1].set_axis_off()\n",
|
520 |
| - "axes[0][1].set_title('width_deviations')\n", |
521 |
| - "edges.plot(ax=axes[1][0], column='profile', legend=True, cmap='Spectral')\n", |
522 |
| - "buildings.plot(ax=axes[1][0], color='lightgrey')\n", |
523 |
| - "edges.plot(ax=axes[1][1], column='openness', legend=True, cmap='Greens')\n", |
524 |
| - "buildings.plot(ax=axes[1][1], color='lightgrey')\n", |
| 539 | + "axes[0][1].set_title(\"width_deviations\")\n", |
| 540 | + "edges.plot(ax=axes[1][0], column=\"profile\", legend=True, cmap=\"Spectral\")\n", |
| 541 | + "buildings.plot(ax=axes[1][0], color=\"lightgrey\")\n", |
| 542 | + "edges.plot(ax=axes[1][1], column=\"openness\", legend=True, cmap=\"Greens\")\n", |
| 543 | + "buildings.plot(ax=axes[1][1], color=\"lightgrey\")\n", |
525 | 544 | "axes[1][0].set_axis_off()\n",
|
526 |
| - "axes[1][0].set_title('profile')\n", |
| 545 | + "axes[1][0].set_title(\"profile\")\n", |
527 | 546 | "axes[1][1].set_axis_off()\n",
|
528 |
| - "axes[1][1].set_title('openness')\n", |
529 |
| - "edges.plot(ax=axes[2][0], column='heights', legend=True, cmap='Reds')\n", |
530 |
| - "buildings.plot(ax=axes[2][0], color='lightgrey')\n", |
531 |
| - "edges.plot(ax=axes[2][1], column='heights_deviations', legend=True)\n", |
532 |
| - "buildings.plot(ax=axes[2][1], color='lightgrey')\n", |
| 547 | + "axes[1][1].set_title(\"openness\")\n", |
| 548 | + "edges.plot(ax=axes[2][0], column=\"heights\", legend=True, cmap=\"Reds\")\n", |
| 549 | + "buildings.plot(ax=axes[2][0], color=\"lightgrey\")\n", |
| 550 | + "edges.plot(ax=axes[2][1], column=\"heights_deviations\", legend=True)\n", |
| 551 | + "buildings.plot(ax=axes[2][1], color=\"lightgrey\")\n", |
533 | 552 | "axes[2][0].set_axis_off()\n",
|
534 |
| - "axes[2][0].set_title('heights')\n", |
| 553 | + "axes[2][0].set_title(\"heights\")\n", |
535 | 554 | "axes[2][1].set_axis_off()\n",
|
536 |
| - "axes[2][1].set_title('heights_deviations')\n", |
| 555 | + "axes[2][1].set_title(\"heights_deviations\")\n", |
537 | 556 | "plt.show()"
|
538 | 557 | ]
|
539 | 558 | }
|
|
0 commit comments