Skip to main content
`Ctrl`+`K`

Note

Go to the end to download the full example code.

# 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.

References

- Importing from OpenStreetMap

See also

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

- `aequilibrae.project.Network.create_from_osm()`

    # 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:05<00:00,  2.87s/it]
    Downloading finished. Processing data             : 100%|██████████| 2/2 [00:11<00:00,  2.87s/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.82it/s]
    Adding network links                              : 78it [00:00, 420.26it/s]
    Adding network links                              : 161it [00:00, 605.13it/s]
    Adding network links                              : 252it [00:00, 722.64it/s]
    Adding network links                              : 332it [00:00, 745.10it/s]
    Adding network links                              : 407it [00:00, 745.95it/s]
    Adding network links                              : 493it [00:00, 782.85it/s]
    Adding nodes to file                              : : 504it [00:00, 782.85it/s]
    Adding links to file                              : : 504it [00:01, 782.85it/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 16.652 seconds)

Gallery generated by Sphinx-Gallery