Create project from OpenStreetMap#

In this example, we show how to create an empty project and populate it with a network from OpenStreetMap.

This time we will use GeoPandas to visualize the network.

See also

Several functions, methods, classes and modules are used in this example:

# Imports
from uuid import uuid4
from tempfile import gettempdir
from os.path import join
from aequilibrae import Project
import folium
# We create an empty project on an arbitrary folder
fldr = join(gettempdir(), uuid4().hex)

project = Project()
project.new(fldr)
No pre-existing parameter file exists for this project. Will use default
No pre-existing parameter file exists for this project. Will use default

Now we can download the network from any place in the world (as long as you have memory for all the download and data wrangling that will be done).

We can create from a bounding box or a named place. For the sake of this example, we will choose the small nation of Nauru.

project.network.create_from_osm(place_name="Nauru")
Total polygons: 2                                 :   0%|          | 0/2 [00:00<?, ?it/s]
Total polygons: 2                                 : 100%|██████████| 2/2 [00:07<00:00,  3.89s/it]
Downloading finished. Processing data             : 100%|██████████| 2/2 [00:13<00:00,  3.89s/it]


Processing chunks                                 :   0%|          | 0/1 [00:00<?, ?it/s]


Adding network links                              : 0it [00:00, ?it/s]
Adding network links                              : 18it [00:00, 177.24it/s]
Adding network links                              : 78it [00:00, 419.67it/s]
Adding network links                              : 162it [00:00, 609.20it/s]
Adding network links                              : 251it [00:00, 717.11it/s]
Adding network links                              : 328it [00:00, 734.16it/s]
Adding network links                              : 402it [00:00, 729.42it/s]
Adding network links                              : 486it [00:00, 763.67it/s]
Adding nodes to file                              : : 505it [00:00, 763.67it/s]
Adding links to file                              : : 505it [00:01, 763.67it/s]

We can also choose to create a model from a polygon (which must be in EPSG:4326) or from a Polygon defined by a bounding box, for example.

# project.network.create_from_osm(model_area=box(-112.185, 36.59, -112.179, 36.60))

We grab all the links data as a geopandas GeoDataFrame so we can process it easier

links = project.network.links.data

Let’s plot our network!

map_osm = links.explore(color="blue", weight=10, tooltip="link_type", popup="link_id", name="links")
folium.LayerControl().add_to(map_osm)
map_osm
Make this Notebook Trusted to load map: File -> Trust Notebook


project.close()

Total running time of the script: (0 minutes 18.431 seconds)

Gallery generated by Sphinx-Gallery