# Relabeling nodes#
## Relabeling#
`convert_node_labels_to_integers`(G[, ...])
Returns a copy of the graph G with the nodes relabeled using consecutive integers.  
`relabel_nodes`(G, mapping[, copy])
Relabel the nodes of the graph G according to a given mapping.
# Glossary#  
dictionary#
    
A Python dictionary maps keys to values. Also known as “hashes”, or “associative arrays” in other programming languages. See the Python tutorial on dictionaries.
edge#
    
Edges are either two-tuples of nodes `(u, v)` or three tuples of nodes with an edge attribute dictionary `(u, v, dict)`.
ebunch#
    
An iterable container of edge tuples like a list, iterator, or file.
edge attribute#
    
Edges can have arbitrary Python objects assigned as attributes by using keyword/value pairs when adding an edge assigning to the `G.edges[u][v]` attribute dictionary for the specified edge u-v.
nbunch#
    
An nbunch is a single node, container of nodes or `None` (representing all nodes). It can be a list, set, graph, etc. To filter an nbunch so that only nodes actually in `G` appear, use `G.nbunch_iter(nbunch)`.
If the nbunch is a container or iterable that is not itself a node in the graph, then it will be treated as an iterable of nodes, for instance, when nbunch is a string or a tuple:
    
    >>> import networkx as nx
    >>> G = nx.DiGraph()
    >>> G.add_edges_from([("b", "c"), ("a", "ab"), ("ab", "c")])
    >>> G.edges("ab")
    OutEdgeDataView([('ab', 'c')])
    
Since “ab” is a node in G, it is treated as a single node:
    
    >>> G.edges("bc")
    OutEdgeDataView([('b', 'c')])
    
Since “bc” is not a node in G, it is treated as an iterator:
    
    >>> G.edges(["bc"])
    OutEdgeDataView([])
    
If “bc” is wrapped in a list, the list is the iterable and “bc” is treated as a single node. That is, if the nbunch is an iterable of iterables, the inner iterables will always be treated as nodes:
    
    >>> G.edges("de")
    OutEdgeDataView([])
    
When nbunch is an iterator that is not itself a node and none of its elements are nodes, then the edge view suite of methods return an empty edge view.
node#
    
A node can be any hashable Python object except None.
node attribute#
    
Nodes can have arbitrary Python objects assigned as attributes by using keyword/value pairs when adding a node or assigning to the `G.nodes[n]` attribute dictionary for the specified node `n`.
# Randomness#
Random Number Generators (RNGs) are often used when generating, drawing and computing properties or manipulating networks. NetworkX provides functions which use one of two standard RNGs: NumPy’s package `numpy.random` or Python’s built-in package `random`. They each provide the same algorithm for generating numbers (Mersenne Twister). Their interfaces are similar (dangerously similar) and yet distinct. They each provide a global default instance of their generator that is shared by all programs in a single session. For the most part you can use the RNGs as NetworkX has them set up and you’ll get reasonable pseudorandom results (results that are statistically random, but created in a deterministic manner).
Sometimes you want more control over how the numbers are generated. In particular, you need to set the `seed` of the generator to make your results reproducible – either for scientific publication or for debugging. Both RNG packages have easy functions to set the seed to any integer, thus determining the subsequent generated values. Since this package (and many others) use both RNGs you may need to set the `seed` of both RNGs. Even if we strictly only used one of the RNGs, you may find yourself using another package that uses the other. Setting the state of the two global RNGs is as simple setting the seed of each RNG to an arbitrary integer:
    
    >>> import random
    >>> random.seed(246)        # or any integer
    >>> import numpy as np
    >>> np.random.seed(4812)
    
Many users will be satisfied with this level of control.
For people who want even more control, we include an optional argument to functions that use an RNG. This argument is called `seed`, but determines more than the seed of the RNG. It tells the function which RNG package to use, and whether to use a global or local RNG.
    
    >>> from networkx import path_graph, random_layout
    >>> G = path_graph(9)
    >>> pos = random_layout(G, seed=None)  # use (either) global default RNG
    >>> pos = random_layout(G, seed=42)  # local RNG just for this call
    >>> pos = random_layout(G, seed=numpy.random)  # use numpy global RNG
    >>> random_state = numpy.random.RandomState(42)
    >>> pos = random_layout(G, seed=random_state)  # use/reuse your own RNG
    
Each NetworkX function that uses an RNG was written with one RNG package in mind. It either uses `random` or `numpy.random` by default. But some users want to only use a single RNG for all their code. This `seed` argument provides a mechanism so that any function can use a `numpy.random` RNG even if the function is written for `random`. It works as follows.
The default behavior (when `seed=None`) is to use the global RNG for the function’s preferred package. If seed is set to an integer value, a local RNG is created with the indicated seed value and is used for the duration of that function (including any calls to other functions) and then discarded. Alternatively, you can specify `seed=numpy.random` to ensure that the global numpy RNG is used whether the function expects it or not. Finally, you can provide a numpy RNG to be used by the function. The RNG is then available to use in other functions or even other package like sklearn. In this way you can use a single RNG for all random numbers in your project.
While it is possible to assign `seed` a `random`-style RNG for NetworkX functions written for the `random` package API, the numpy RNG interface has too many nice features for us to ensure a `random`-style RNG will work in all functions. In practice, you can do most things using only `random` RNGs (useful if numpy is not available). But your experience will be richer if numpy is available.
To summarize, you can easily ignore the `seed` argument and use the global RNGs. You can specify to use only the numpy global RNG with `seed=numpy.random`. You can use a local RNG by providing an integer seed value. And you can provide your own numpy RNG, reusing it for all functions. It is easier to use numpy RNGs if you want a single RNG for your computations.
# Linear algebra#
## Graph Matrix#
Adjacency matrix and incidence matrix of graphs.
`adjacency_matrix`(G[, nodelist, dtype, weight])
Returns adjacency matrix of `G`.  
`incidence_matrix`(G[, nodelist, edgelist, ...])
Returns incidence matrix of G.  
## Laplacian Matrix#
Laplacian matrix of graphs.
All calculations here are done using the out-degree. For Laplacians using in-degree, use `G.reverse(copy=False)` instead of `G` and take the transpose.
The `laplacian_matrix` function provides an unnormalized matrix, while `normalized_laplacian_matrix`, `directed_laplacian_matrix`, and `directed_combinatorial_laplacian_matrix` are all normalized.
`laplacian_matrix`(G[, nodelist, weight])
Returns the Laplacian matrix of G.  
`normalized_laplacian_matrix`(G[, nodelist, ...])
Returns the normalized Laplacian matrix of G.  
`directed_laplacian_matrix`(G[, nodelist, ...])
Returns the directed Laplacian matrix of G.  
`directed_combinatorial_laplacian_matrix`(G[, ...])
Return the directed combinatorial Laplacian matrix of G.  
## Bethe Hessian Matrix#
Bethe Hessian or deformed Laplacian matrix of graphs.
`bethe_hessian_matrix`(G[, r, nodelist])
Returns the Bethe Hessian matrix of G.  
## Algebraic Connectivity#
Algebraic connectivity and Fiedler vectors of undirected graphs.
`algebraic_connectivity`(G[, weight, ...])
Returns the algebraic connectivity of an undirected graph.  
`fiedler_vector`(G[, weight, normalized, tol, ...])
Returns the Fiedler vector of a connected undirected graph.  
`spectral_ordering`(G[, weight, normalized, ...])
Compute the spectral_ordering of a graph.  
`spectral_bisection`(G[, weight, normalized, ...])
Bisect the graph using the Fiedler vector.  
## Attribute Matrices#
Functions for constructing matrix-like objects from graph attributes.
`attr_matrix`(G[, edge_attr, node_attr, ...])
Returns the attribute matrix using attributes from `G` as a numpy array.  
`attr_sparse_matrix`(G[, edge_attr, ...])
Returns a SciPy sparse array using attributes from G.  
## Modularity Matrices#
Modularity matrix of graphs.
`modularity_matrix`(G[, nodelist, weight])
Returns the modularity matrix of G.  
`directed_modularity_matrix`(G[, nodelist, weight])
Returns the directed modularity matrix of G.  
## Spectrum#
Eigenvalue spectrum of graphs.
`adjacency_spectrum`(G[, weight])
Returns eigenvalues of the adjacency matrix of G.  
`laplacian_spectrum`(G[, weight])
Returns eigenvalues of the Laplacian of G  
`bethe_hessian_spectrum`(G[, r])
Returns eigenvalues of the Bethe Hessian matrix of G.  
`normalized_laplacian_spectrum`(G[, weight])
Return eigenvalues of the normalized Laplacian of G  
`modularity_spectrum`(G)
Returns eigenvalues of the modularity matrix of G.
# Utilities#  
## Helper Functions#
Miscellaneous Helpers for NetworkX.
These are not imported into the base networkx namespace but can be accessed, for example, as
    
    >>> import networkx as nx
    >>> nx.utils.make_list_of_ints({1, 2, 3})
    [1, 2, 3]
    >>> nx.utils.arbitrary_element({5, 1, 7})
    1
    
`arbitrary_element`(iterable)
Returns an arbitrary element of `iterable` without removing it.  
`flatten`(obj[, result])
Return flattened version of (possibly nested) iterable object.  
`make_list_of_ints`(sequence)
Return list of ints from sequence of integral numbers.  
`dict_to_numpy_array`(d[, mapping])
Convert a dictionary of dictionaries to a numpy array with optional mapping.  
`pairwise`(iterable[, cyclic])
s -> (s0, s1), (s1, s2), (s2, s3), ...  
`groups`(many_to_one)
Converts a many-to-one mapping into a one-to-many mapping.  
`create_random_state`([random_state])
Returns a numpy.random.RandomState or numpy.random.Generator instance depending on input.  
`create_py_random_state`([random_state])
Returns a random.Random instance depending on input.  
`nodes_equal`(nodes1, nodes2)
Check if nodes are equal.  
`edges_equal`(edges1, edges2)
Check if edges are equal.  
`graphs_equal`(graph1, graph2)
Check if graphs are equal.  
## Data Structures and Algorithms#
Union-find data structure.
`UnionFind.union`(*objects)
Find the sets containing the objects and merge them all.  
## Random Sequence Generators#
Utilities for generating random numbers, random sequences, and random selections.
`powerlaw_sequence`(n[, exponent, seed])
Return sample sequence of length n from a power law distribution.  
`cumulative_distribution`(distribution)
Returns normalized cumulative distribution from discrete distribution.  
`discrete_sequence`(n[, distribution, ...])
Return sample sequence of length n from a given discrete distribution or discrete cumulative distribution.  
`zipf_rv`(alpha[, xmin, seed])
Returns a random value chosen from the Zipf distribution.  
`random_weighted_sample`(mapping, k[, seed])
Returns k items without replacement from a weighted sample.  
`weighted_choice`(mapping[, seed])
Returns a single element from a weighted sample.  
## Decorators#
`open_file`(path_arg[, mode])
Decorator to ensure clean opening and closing of files.  
`not_implemented_for`(*graph_types)
Decorator to mark algorithms as not implemented  
`nodes_or_number`(which_args)
Decorator to allow number of nodes or container of nodes.  
`np_random_state`(random_state_argument)
Decorator to generate a numpy RandomState or Generator instance.  
`py_random_state`(random_state_argument)
Decorator to generate a random.Random instance (or equiv).  
`argmap`(func, *args[, try_finally])
A decorator to apply a map to arguments before calling the function  
## Cuthill-Mckee Ordering#
Cuthill-McKee ordering of graph nodes to produce sparse matrices
`cuthill_mckee_ordering`(G[, heuristic])
Generate an ordering (permutation) of the graph nodes to make a sparse matrix.  
`reverse_cuthill_mckee_ordering`(G[, heuristic])
Generate an ordering (permutation) of the graph nodes to make a sparse matrix.  
## Mapped Queue#
Priority queue class with updatable priorities.
`MappedQueue`([data])
The MappedQueue class implements a min-heap with removal and update-priority.
# np_random_state#  
np_random_state(random_state_argument)[source]#
    
Decorator to generate a numpy RandomState or Generator instance.
The decorator processes the argument indicated by `random_state_argument` using `nx.utils.create_random_state()`. The argument value can be a seed (integer), or a `numpy.random.RandomState` or `numpy.random.RandomState` instance or (`None` or `numpy.random`). The latter two options use the global random number generator for `numpy.random`.
The returned instance is a `numpy.random.RandomState` or `numpy.random.Generator`.
Parameters:
    
random_state_argumentstring or int
    
The name or index of the argument to be converted to a `numpy.random.RandomState` instance.
Returns:
    
_random_statefunction
    
Function whose random_state keyword argument is a RandomState instance.
See also
`py_random_state`
    
Examples
Decorate functions like this:
    
    @np_random_state("seed")
    def random_float(seed=None):
        return seed.rand()
    
    @np_random_state(0)
    def random_float(rng=None):
        return rng.rand()
    
    @np_random_state(1)
    def random_array(dims, random_state=1):
        return random_state.rand(*dims)
    
# Converting to and from other data formats#
## To NetworkX Graph#
Functions to convert NetworkX graphs to and from other formats.
The preferred way of converting data to a NetworkX graph is through the graph constructor. The constructor calls the to_networkx_graph() function which attempts to guess the input type and convert it automatically.
### Examples#
Create a graph with a single edge from a dictionary of dictionaries
    
    >>> d = {0: {1: 1}}  # dict-of-dicts single edge (0,1)
    >>> G = nx.Graph(d)
    
### See Also#
nx_agraph, nx_pydot
`to_networkx_graph`(data[, create_using, ...])
Make a NetworkX graph from a known data structure.  
## Dictionaries#
`to_dict_of_dicts`(G[, nodelist, edge_data])
Returns adjacency representation of graph as a dictionary of dictionaries.  
`from_dict_of_dicts`(d[, create_using, ...])
Returns a graph from a dictionary of dictionaries.  
## Lists#
`to_dict_of_lists`(G[, nodelist])
Returns adjacency representation of graph as a dictionary of lists.  
`from_dict_of_lists`(d[, create_using])
Returns a graph from a dictionary of lists.  
`to_edgelist`(G[, nodelist])
Returns a list of edges in the graph.  
`from_edgelist`(edgelist[, create_using])
Returns a graph from a list of edges.  
## Numpy#
Functions to convert NetworkX graphs to and from common data containers like numpy arrays, scipy sparse arrays, and pandas DataFrames.
The preferred way of converting data to a NetworkX graph is through the graph constructor. The constructor calls the `to_networkx_graph` function which attempts to guess the input type and convert it automatically.
### Examples#
Create a 10 node random graph from a numpy array
    
    >>> import numpy as np
    >>> rng = np.random.default_rng()
    >>> a = rng.integers(low=0, high=2, size=(10, 10))
    >>> DG = nx.from_numpy_array(a, create_using=nx.DiGraph)
    
or equivalently:
    
    >>> DG = nx.DiGraph(a)
    
which calls `from_numpy_array` internally based on the type of `a`.
### See Also#
nx_agraph, nx_pydot
`to_numpy_array`(G[, nodelist, dtype, order, ...])
Returns the graph adjacency matrix as a NumPy array.  
`from_numpy_array`(A[, parallel_edges, ...])
Returns a graph from a 2D NumPy array.  
## Scipy#
`to_scipy_sparse_array`(G[, nodelist, dtype, ...])
Returns the graph adjacency matrix as a SciPy sparse array.  
`from_scipy_sparse_array`(A[, parallel_edges, ...])
Creates a new graph from an adjacency matrix given as a SciPy sparse array.  
## Pandas#
`to_pandas_adjacency`(G[, nodelist, dtype, ...])
Returns the graph adjacency matrix as a Pandas DataFrame.  
`from_pandas_adjacency`(df[, create_using])
Returns a graph from Pandas DataFrame.  
`to_pandas_edgelist`(G[, source, target, ...])
Returns the graph edge list as a Pandas DataFrame.  
`from_pandas_edgelist`(df[, source, target, ...])
Returns a graph from Pandas DataFrame containing an edge list.
# Configs#
Configs provide library-level storage of configuration settings. These settings can be made in code or from environment variables.
config#
    
alias of NetworkXConfig(backend_priority=BackendPriorities(algos=[], generators=[]), backends=Config(), cache_converted_graphs=True, fallback_to_nx=False, warnings_to_ignore=set())
class NetworkXConfig(**kwargs)[source]#
    
Configuration for NetworkX that controls behaviors such as how to use backends.
Attribute and bracket notation are supported for getting and setting configurations:
    
    >>> nx.config.backend_priority == nx.config["backend_priority"]
    True
    
Parameters:
    
backend_prioritylist of backend names or dict or BackendPriorities
    
Enable automatic conversion of graphs to backend graphs for functions implemented by the backend. Priority is given to backends listed earlier. This is a nested configuration with keys `algos`, `generators`, and, optionally, function names. Setting this value to a list of backend names will set `nx.config.backend_priority.algos`. For more information, see `help(nx.config.backend_priority)`. Default is empty list.
backendsConfig mapping of backend names to backend Config
    
The keys of the Config mapping are names of all installed NetworkX backends, and the values are their configurations as Config mappings.
cache_converted_graphsbool
    
If True, then save converted graphs to the cache of the input graph. Graph conversion may occur when automatically using a backend from `backend_priority` or when using the `backend=` keyword argument to a function call. Caching can improve performance by avoiding repeated conversions, but it uses more memory. Care should be taken to not manually mutate a graph that has cached graphs; for example, `G[u][v][k] = val` changes the graph, but does not clear the cache. Using methods such as `G.add_edge(u, v, weight=val)` will clear the cache to keep it consistent. `G.__networkx_cache__.clear()` manually clears the cache. Default is True.
fallback_to_nxbool
    
If True, then “fall back” and run with the default “networkx” implementation for dispatchable functions not implemented by backends of input graphs. When a backend graph is passed to a dispatchable function, the default behavior is to use the implementation from that backend if possible and raise if not. Enabling `fallback_to_nx` makes the networkx implementation the fallback to use instead of raising, and will convert the backend graph to a networkx-compatible graph. Default is False.
warnings_to_ignoreset of strings
    
Control which warnings from NetworkX are not emitted. Valid elements:
  * `"cache"`: when a cached value is used from `G.__networkx_cache__`.


Notes
Environment variables may be used to control some default configurations:
  * `NETWORKX_BACKEND_PRIORITY`: set `backend_priority.algos` from comma-separated names.
  * `NETWORKX_CACHE_CONVERTED_GRAPHS`: set `cache_converted_graphs` to True if nonempty.
  * `NETWORKX_FALLBACK_TO_NX`: set `fallback_to_nx` to True if nonempty.
  * `NETWORKX_WARNINGS_TO_IGNORE`: set `warnings_to_ignore` from comma-separated names.


and can be used for finer control of `backend_priority` such as:
  * `NETWORKX_BACKEND_PRIORITY_ALGOS`: same as `NETWORKX_BACKEND_PRIORITY` to set `backend_priority.algos`.


This is a global configuration. Use with caution when using from multiple threads.
class Config(**kwargs)[source]#
    
The base class for NetworkX configuration.
There are two ways to use this to create configurations. The recommended way is to subclass `Config` with docs and annotations.
    
    >>> class MyConfig(Config):
    ...     '''Breakfast!'''
    ...
    ...     eggs: int
    ...     spam: int
    ...
    ...     def _on_setattr(self, key, value):
    ...         assert isinstance(value, int) and value >= 0
    ...         return value
    >>> cfg = MyConfig(eggs=1, spam=5)
    
Another way is to simply pass the initial configuration as keyword arguments to the `Config` instance:
    
    >>> cfg1 = Config(eggs=1, spam=5)
    >>> cfg1
    Config(eggs=1, spam=5)
    
Once defined, config items may be modified, but can’t be added or deleted by default. `Config` is a `Mapping`, and can get and set configs via attributes or brackets:
    
    >>> cfg.eggs = 2
    >>> cfg.eggs
    2
    >>> cfg["spam"] = 42
    >>> cfg["spam"]
    42
    
For convenience, it can also set configs within a context with the “with” statement:
    
    >>> with cfg(spam=3):
    ...     print("spam (in context):", cfg.spam)
    spam (in context): 3
    >>> print("spam (after context):", cfg.spam)
    spam (after context): 42
    
Subclasses may also define `_on_setattr` (as done in the example above) to ensure the value being assigned is valid:
    
    >>> cfg.spam = -1
    Traceback (most recent call last):
        ...
    AssertionError
    
If a more flexible configuration object is needed that allows adding and deleting configurations, then pass `strict=False` when defining the subclass:
    
    >>> class FlexibleConfig(Config, strict=False):
    ...     default_greeting: str = "Hello"
    >>> flexcfg = FlexibleConfig()
    >>> flexcfg.name = "Mr. Anderson"
    >>> flexcfg
    FlexibleConfig(default_greeting='Hello', name='Mr. Anderson')
    
# reverse_cuthill_mckee_ordering#  
reverse_cuthill_mckee_ordering(G, heuristic=None)[source]#
    
Generate an ordering (permutation) of the graph nodes to make a sparse matrix.
Uses the reverse Cuthill-McKee heuristic (based on breadth-first search) [1].
Parameters:
    
Ggraph
    
A NetworkX graph
heuristicfunction, optional
    
Function to choose starting node for RCM algorithm. If None a node from a pseudo-peripheral pair is used. A user-defined function can be supplied that takes a graph object and returns a single node.
Returns:
    
nodesgenerator
    
Generator of nodes in reverse Cuthill-McKee ordering.
See also
`cuthill_mckee_ordering`
    
Notes
The optimal solution the bandwidth reduction is NP-complete [2].
References
[1]
E. Cuthill and J. McKee. Reducing the bandwidth of sparse symmetric matrices, In Proc. 24th Nat. Conf. ACM, pages 157-72, 1969. http://doi.acm.org/10.1145/800195.805928
[2]
Steven S. Skiena. 1997. The Algorithm Design Manual. Springer-Verlag New York, Inc., New York, NY, USA.
Examples
    
    >>> from networkx.utils import reverse_cuthill_mckee_ordering
    >>> G = nx.path_graph(4)
    >>> rcm = list(reverse_cuthill_mckee_ordering(G))
    >>> A = nx.adjacency_matrix(G, nodelist=rcm)
    
Smallest degree node as heuristic function:
    
    >>> def smallest_degree(G):
    ...     return min(G, key=G.degree)
    >>> rcm = list(reverse_cuthill_mckee_ordering(G, heuristic=smallest_degree))
    
# Functions#
Functional interface to graph methods and assorted utilities.
## Graph#
`degree`(G[, nbunch, weight])
Returns a degree view of single node or of nbunch of nodes.  
`degree_histogram`(G)
Returns a list of the frequency of each degree value.  
`density`(G)
Returns the density of a graph.  
`create_empty_copy`(G[, with_data])
Returns a copy of the graph G with all of the edges removed.  
`is_directed`(G)
Return True if graph is directed.  
`to_directed`(graph)
Returns a directed view of the graph `graph`.  
`to_undirected`(graph)
Returns an undirected view of the graph `graph`.  
`is_empty`(G)
Returns True if `G` has no edges.  
`add_star`(G_to_add_to, nodes_for_star, **attr)
Add a star to Graph G_to_add_to.  
`add_path`(G_to_add_to, nodes_for_path, **attr)
Add a path to the Graph G_to_add_to.  
`add_cycle`(G_to_add_to, nodes_for_cycle, **attr)
Add a cycle to the Graph G_to_add_to.  
`subgraph`(G, nbunch)
Returns the subgraph induced on nodes in nbunch.  
`induced_subgraph`(G, nbunch)
Returns a SubGraph view of `G` showing only nodes in nbunch.  
`restricted_view`(G, nodes, edges)
Returns a view of `G` with hidden nodes and edges.  
`edge_subgraph`(G, edges)
Returns a view of the subgraph induced by the specified edges.  
## Nodes#
`nodes`(G)
Returns a NodeView over the graph nodes.  
`number_of_nodes`(G)
Returns the number of nodes in the graph.  
`neighbors`(G, n)
Returns an iterator over all neighbors of node n.  
`all_neighbors`(graph, node)
Returns all of the neighbors of a node in the graph.  
`non_neighbors`(graph, node)
Returns the non-neighbors of the node in the graph.  
`common_neighbors`(G, u, v)
Returns the common neighbors of two nodes in a graph.  
## Edges#
`edges`(G[, nbunch])
Returns an edge view of edges incident to nodes in nbunch.  
`number_of_edges`(G)
Returns the number of edges in the graph.  
`density`(G)
Returns the density of a graph.  
`non_edges`(graph)
Returns the nonexistent edges in the graph.  
## Self loops#
`selfloop_edges`(G[, data, keys, default])
Returns an iterator over selfloop edges.  
`number_of_selfloops`(G)
Returns the number of selfloop edges.  
`nodes_with_selfloops`(G)
Returns an iterator over nodes with self loops.  
## Attributes#
`is_weighted`(G[, edge, weight])
Returns True if `G` has weighted edges.  
`is_negatively_weighted`(G[, edge, weight])
Returns True if `G` has negatively weighted edges.  
`set_node_attributes`(G, values[, name])
Sets node attributes from a given value or dictionary of values.  
`get_node_attributes`(G, name[, default])
Get node attributes from graph  
`set_edge_attributes`(G, values[, name])
Sets edge attributes from a given value or dictionary of values.  
`get_edge_attributes`(G, name[, default])
Get edge attributes from graph  
## Paths#
`is_path`(G, path)
Returns whether or not the specified path exists.  
`path_weight`(G, path, weight)
Returns total cost associated with specified path and weight  
## Freezing graph structure#
`freeze`(G)
Modify graph to prevent further change by adding or removing nodes or edges.  
`is_frozen`(G)
Returns True if graph is frozen.
# random_weighted_sample#
random_weighted_sample(mapping, k, seed=None)[source]#
    
Returns k items without replacement from a weighted sample.
The input is a dictionary of items with weights as values.
# Exceptions#  
Base exceptions and errors for NetworkX.
class NetworkXException[source]#
    
Base class for exceptions in NetworkX.
class NetworkXError[source]#
    
Exception for a serious error in NetworkX
class NetworkXPointlessConcept[source]#
    
Raised when a null graph is provided as input to an algorithm that cannot use it.
The null graph is sometimes considered a pointless concept [1], thus the name of the exception.
Notes
Null graphs and empty graphs are often used interchangeably but they are well defined in NetworkX. An `empty_graph` is a graph with `n` nodes and 0 edges, and a `null_graph` is a graph with 0 nodes and 0 edges.
References
[1]
Harary, F. and Read, R. “Is the Null Graph a Pointless Concept?” In Graphs and Combinatorics Conference, George Washington University. New York: Springer-Verlag, 1973.
class NetworkXAlgorithmError[source]#
    
Exception for unexpected termination of algorithms.
class NetworkXUnfeasible[source]#
    
Exception raised by algorithms trying to solve a problem instance that has no feasible solution.
class NetworkXNoPath[source]#
    
Exception for algorithms that should return a path when running on graphs where such a path does not exist.
class NetworkXNoCycle[source]#
    
Exception for algorithms that should return a cycle when running on graphs where such a cycle does not exist.
class NodeNotFound[source]#
    
Exception raised if requested node is not present in the graph
class HasACycle[source]#
    
Raised if a graph has a cycle when an algorithm expects that it will have no cycles.
class NetworkXUnbounded[source]#
    
Exception raised by algorithms trying to solve a maximization or a minimization problem instance that is unbounded.
class NetworkXNotImplemented[source]#
    
Exception raised by algorithms not implemented for a type of graph.
class AmbiguousSolution[source]#
    
Raised if more than one valid solution exists for an intermediary step of an algorithm.
In the face of ambiguity, refuse the temptation to guess. This may occur, for example, when trying to determine the bipartite node sets in a disconnected bipartite graph when computing bipartite matchings.
class ExceededMaxIterations[source]#
    
Raised if a loop iterates too many times without breaking.
This may occur, for example, in an algorithm that computes progressively better approximations to a value but exceeds an iteration bound specified by the user.
class PowerIterationFailedConvergence(num_iterations, *args, **kw)[source]#
    
Raised when the power iteration method fails to converge within a specified iteration limit.
`num_iterations` is the number of iterations that have been completed when this exception was raised.
# Introduction#
The structure of NetworkX can be seen by the organization of its source code. The package provides classes for graph objects, generators to create standard graphs, IO routines for reading in existing datasets, algorithms to analyze the resulting networks and some basic drawing tools.
Most of the NetworkX API is provided by functions which take a graph object as an argument. Methods of the graph object are limited to basic manipulation and reporting. This provides modularity of code and documentation. It also makes it easier for newcomers to learn about the package in stages. The source code for each module is meant to be easy to read and reading this Python code is actually a good way to learn more about network algorithms, but we have put a lot of effort into making the documentation sufficient and friendly. If you have suggestions or questions please contact us by joining the NetworkX Google group.
Classes are named using `CamelCase` (capital letters at the start of each word). functions, methods and variable names are `lower_case_underscore` (lowercase with an underscore representing a space between words).
## NetworkX Basics#
After starting Python, import the networkx module with (the recommended way)
    
    import networkx as nx
    
To save repetition, in the documentation we assume that NetworkX has been imported this way.
If importing networkx fails, it means that Python cannot find the installed module. Check your installation and your `PYTHONPATH`.
The following basic graph types are provided as Python classes:
`Graph`
  * This class implements an undirected graph. It ignores multiple edges between two nodes. It does allow self-loop edges between a node and itself.


`DiGraph`
  * Directed graphs, that is, graphs with directed edges. Provides operations common to directed graphs, (a subclass of Graph).


`MultiGraph`
  * A flexible graph class that allows multiple undirected edges between pairs of nodes. The additional flexibility leads to some degradation in performance, though usually not significant.


`MultiDiGraph`
  * A directed version of a MultiGraph.


Empty graph-like objects are created with
    
    G = nx.Graph()
    G = nx.DiGraph()
    G = nx.MultiGraph()
    G = nx.MultiDiGraph()
    
All graph classes allow any hashable object as a node. Hashable objects include strings, tuples, integers, and more. Arbitrary edge attributes such as weights and labels can be associated with an edge.
The graph internal data structures are based on an adjacency list representation and implemented using Python dictionary datastructures. The graph adjacency structure is implemented as a Python dictionary of dictionaries; the outer dictionary is keyed by nodes to values that are themselves dictionaries keyed by neighboring node to the edge attributes associated with that edge. This “dict-of-dicts” structure allows fast addition, deletion, and lookup of nodes and neighbors in large graphs. The underlying datastructure is accessed directly by methods (the programming interface “API”) in the class definitions. All functions, on the other hand, manipulate graph-like objects solely via those API methods and not by acting directly on the datastructure. This design allows for possible replacement of the ‘dicts-of-dicts’-based datastructure with an alternative datastructure that implements the same methods.
## Graphs#
The first choice to be made when using NetworkX is what type of graph object to use. A graph (network) is a collection of nodes together with a collection of edges that are pairs of nodes. Attributes are often associated with nodes and/or edges. NetworkX graph objects come in different flavors depending on two main properties of the network:
>   * Directed: Are the edges directed? Does the order of the edge pairs \\((u, v)\\) matter? A directed graph is specified by the “Di” prefix in the class name, e.g. `DiGraph`. We make this distinction because many classical graph properties are defined differently for directed graphs.
>   * Multi-edges: Are multiple edges allowed between each pair of nodes? As you might imagine, multiple edges requires a different data structure, though clever users could design edge data attributes to support this functionality. We provide a standard data structure and interface for this type of graph using the prefix “Multi”, e.g., `MultiGraph`.
> 

The basic graph classes are named: Graph, DiGraph, MultiGraph, and MultiDiGraph
### Nodes and Edges#
The next choice you have to make when specifying a graph is what kinds of nodes and edges to use.
If the topology of the network is all you care about then using integers or strings as the nodes makes sense and you need not worry about edge data. If you have a data structure already in place to describe nodes you can simply use that structure as your nodes provided it is hashable. If it is not hashable you can use a unique identifier to represent the node and assign the data as a node attribute.
Edges often have data associated with them. Arbitrary data can be associated with edges as an edge attribute. If the data is numeric and the intent is to represent a weighted graph then use the ‘weight’ keyword for the attribute. Some of the graph algorithms, such as Dijkstra’s shortest path algorithm, use this attribute name by default to get the weight for each edge.
Attributes can be assigned to an edge by using keyword/value pairs when adding edges. You can use any keyword to name your attribute and can then query the edge data using that attribute keyword.
Once you’ve decided how to encode the nodes and edges, and whether you have an undirected/directed graph with or without multiedges you are ready to build your network.
## Graph Creation#
NetworkX graph objects can be created in one of three ways:
  * Graph generators—standard algorithms to create network topologies.
  * Importing data from preexisting (usually file) sources.
  * Adding edges and nodes explicitly.


Explicit addition and removal of nodes/edges is the easiest to describe. Each graph object supplies methods to manipulate the graph. For example,
    
    G = nx.Graph()
    G.add_edge(1, 2)  # default edge data=1
    G.add_edge(2, 3, weight=0.9)  # specify edge data
    
Edge attributes can be anything:
    
    import math
    G.add_edge('y', 'x', function=math.cos)
    G.add_node(math.cos)  # any hashable can be a node
    
You can add many edges at one time:
    
    elist = [(1, 2), (2, 3), (1, 4), (4, 2)]
    G.add_edges_from(elist)
    elist = [('a', 'b', 5.0), ('b', 'c', 3.0), ('a', 'c', 1.0), ('c', 'd', 7.3)]
    G.add_weighted_edges_from(elist)
    
See the Tutorial for more examples.
Some basic graph operations such as union and intersection are described in the operators module documentation.
Graph generators such as `binomial_graph()` and `erdos_renyi_graph()` are provided in the graph generators subpackage.
For importing network data from formats such as GML, GraphML, edge list text files see the reading and writing graphs subpackage.
## Graph Reporting#
Class views provide basic reporting of nodes, neighbors, edges and degree. These views provide iteration over the properties as well as membership queries and data attribute lookup. The views refer to the graph data structure so changes to the graph are reflected in the views. This is analogous to dictionary views in Python 3. If you want to change the graph while iterating you will need to use e.g. `for e in list(G.edges):`. The views provide set-like operations, e.g. union and intersection, as well as dict-like lookup and iteration of the data attributes using `G.edges[u, v]['color']` and `for e, datadict in G.edges.items():`. Methods `G.edges.items()` and `G.edges.values()` are familiar from python dicts. In addition `G.edges.data()` provides specific attribute iteration e.g. `for e, e_color in G.edges.data('color'):`.
The basic graph relationship of an edge can be obtained in two ways. One can look for neighbors of a node or one can look for edges. We jokingly refer to people who focus on nodes/neighbors as node-centric and people who focus on edges as edge-centric. The designers of NetworkX tend to be node-centric and view edges as a relationship between nodes. You can see this by our choice of lookup notation like `G[u]` providing neighbors (adjacency) while edge lookup is `G.edges[u, v]`. Most data structures for sparse graphs are essentially adjacency lists and so fit this perspective. In the end, of course, it doesn’t really matter which way you examine the graph. `G.edges` removes duplicate representations of undirected edges while neighbor reporting across all nodes will naturally report both directions.
Any properties that are more complicated than edges, neighbors and degree are provided by functions. For example `nx.triangles(G, n)` gives the number of triangles which include node n as a vertex. These functions are grouped in the code and documentation under the term algorithms.
## Algorithms#
A number of graph algorithms are provided with NetworkX. These include shortest path, and breadth first search (see traversal), clustering and isomorphism algorithms and others. There are many that we have not developed yet too. If you implement a graph algorithm that might be useful for others please let us know through the NetworkX Google group or the GitHub Developer Zone.
As an example here is code to use Dijkstra’s algorithm to find the shortest weighted path:
    
    G = nx.Graph()
    e = [('a', 'b', 0.3), ('b', 'c', 0.9), ('a', 'c', 0.5), ('c', 'd', 1.2)]
    G.add_weighted_edges_from(e)
    print(nx.dijkstra_path(G, 'a', 'd'))
    
    
    ['a', 'c', 'd']
    
## Drawing#
While NetworkX is not designed as a network drawing tool, we provide a simple interface to drawing packages and some simple layout algorithms. We interface to the excellent Graphviz layout tools like dot and neato with the (suggested) pygraphviz package or the pydot interface. Drawing can be done using external programs or the Matplotlib Python package. Interactive GUI interfaces are possible, though not provided. The drawing tools are provided in the module drawing.
The basic drawing functions essentially place the nodes on a scatterplot using the positions you provide via a dictionary or the positions are computed with a layout function. The edges are lines between those dots.
    
    import matplotlib.pyplot as plt
    G = nx.cubical_graph()
    subax1 = plt.subplot(121)
    nx.draw(G)   # default spring_layout
    subax2 = plt.subplot(122)
    nx.draw(G, pos=nx.circular_layout(G), node_color='r', edge_color='b')
    
See the examples for more ideas.
## Data Structure#
NetworkX uses a “dictionary of dictionaries of dictionaries” as the basic network data structure. This allows fast lookup with reasonable storage for large sparse networks. The keys are nodes so `G[u]` returns an adjacency dictionary keyed by neighbor to the edge attribute dictionary. A view of the adjacency data structure is provided by the dict-like object `G.adj` as e.g. `for node, nbrsdict in G.adj.items():`. The expression `G[u][v]` returns the edge attribute dictionary itself. A dictionary of lists would have also been possible, but not allow fast edge detection nor convenient storage of edge data.
Advantages of dict-of-dicts-of-dicts data structure:
  * Find edges and remove edges with two dictionary look-ups.
  * Prefer to “lists” because of fast lookup with sparse storage.
  * Prefer to “sets” since data can be attached to edge.
  * `G[u][v]` returns the edge attribute dictionary.
  * `n in G` tests if node `n` is in graph `G`.
  * `for n in G:` iterates through the graph.
  * `for nbr in G[n]:` iterates through neighbors.


As an example, here is a representation of an undirected graph with the edges \\((A, B)\\) and \\((B, C)\\).
    
    G = nx.Graph()
    G.add_edge('A', 'B')
    G.add_edge('B', 'C')
    print(G.adj)
    
    
    {'A': {'B': {}}, 'B': {'A': {}, 'C': {}}, 'C': {'B': {}}}
    
The data structure gets morphed slightly for each base graph class. For DiGraph two dict-of-dicts-of-dicts structures are provided, one for successors (`G.succ`) and one for predecessors (`G.pred`). For MultiGraph/MultiDiGraph we use a dict-of-dicts-of-dicts-of-dicts [1] where the third dictionary is keyed by an edge key identifier to the fourth dictionary which contains the edge attributes for that edge between the two nodes.
Graphs provide two interfaces to the edge data attributes: adjacency and edges. So `G[u][v]['width']` is the same as `G.edges[u, v]['width']`.
    
    G = nx.Graph()
    G.add_edge(1, 2, color='red', weight=0.84, size=300)
    print(G[1][2]['size'])
    print(G.edges[1, 2]['color'])
    
    
    300
    red
    
Footnotes
* * *
[1]
“It’s dictionaries all the way down.”
# draw_networkx_nodes#
draw_networkx_nodes(G, pos, nodelist=None, node_size=300, node_color='#1f78b4', node_shape='o', alpha=None, cmap=None, vmin=None, vmax=None, ax=None, linewidths=None, edgecolors=None, label=None, margins=None, hide_ticks=True)[source]#
    
Draw the nodes of the graph G.
This draws only the nodes of the graph G.
Parameters:
    
Ggraph
    
A networkx graph
posdictionary
    
A dictionary with nodes as keys and positions as values. Positions should be sequences of length 2.
axMatplotlib Axes object, optional
    
Draw the graph in the specified Matplotlib axes.
nodelistlist (default list(G))
    
Draw only specified nodes
node_sizescalar or array (default=300)
    
Size of nodes. If an array it must be the same length as nodelist.
node_colorcolor or array of colors (default=’#1f78b4’)
    
Node color. Can be a single color or a sequence of colors with the same length as nodelist. Color can be string or rgb (or rgba) tuple of floats from 0-1. If numeric values are specified they will be mapped to colors using the cmap and vmin,vmax parameters. See matplotlib.scatter for more details.
node_shapestring (default=’o’)
    
The shape of the node. Specification is as matplotlib.scatter marker, one of ‘so^>v<dph8’.
alphafloat or array of floats (default=None)
    
The node transparency. This can be a single alpha value, in which case it will be applied to all the nodes of color. Otherwise, if it is an array, the elements of alpha will be applied to the colors in order (cycling through alpha multiple times if necessary).
cmapMatplotlib colormap (default=None)
    
Colormap for mapping intensities of nodes
vmin,vmaxfloats or None (default=None)
    
Minimum and maximum for node colormap scaling
linewidths[None | scalar | sequence] (default=1.0)
    
Line width of symbol border
edgecolors[None | scalar | sequence] (default = node_color)
    
Colors of node borders. Can be a single color or a sequence of colors with the same length as nodelist. Color can be string or rgb (or rgba) tuple of floats from 0-1. If numeric values are specified they will be mapped to colors using the cmap and vmin,vmax parameters. See `scatter` for more details.
label[None | string]
    
Label for legend
marginsfloat or 2-tuple, optional
    
Sets the padding for axis autoscaling. Increase margin to prevent clipping for nodes that are near the edges of an image. Values should be in the range `[0, 1]`. See `matplotlib.axes.Axes.margins()` for details. The default is `None`, which uses the Matplotlib default.
hide_ticksbool, optional
    
Hide ticks of axes. When `True` (the default), ticks and ticklabels are removed from the axes. To set ticks and tick labels to the pyplot default, use `hide_ticks=False`.
Returns:
    
matplotlib.collections.PathCollection
    
`PathCollection` of the nodes.
See also
`draw`
    
`draw_networkx`
    
`draw_networkx_edges`
    
`draw_networkx_labels`
    
`draw_networkx_edge_labels`
    
Examples
    
    >>> G = nx.dodecahedral_graph()
    >>> nodes = nx.draw_networkx_nodes(G, pos=nx.spring_layout(G))
    
Also see the NetworkX drawing examples at https://networkx.org/documentation/latest/auto_examples/index.html
# ring_of_cliques#
ring_of_cliques(num_cliques, clique_size)[source]#
    
Defines a “ring of cliques” graph.
A ring of cliques graph is consisting of cliques, connected through single links. Each clique is a complete graph.
Parameters:
    
num_cliquesint
    
Number of cliques
clique_sizeint
    
Size of cliques
Returns:
    
GNetworkX Graph
    
ring of cliques graph
Raises:
    
NetworkXError
    
If the number of cliques is lower than 2 or if the size of cliques is smaller than 2.
See also
`connected_caveman_graph`
    
Notes
The `connected_caveman_graph` graph removes a link from each clique to connect it with the next clique. Instead, the `ring_of_cliques` graph simply adds the link without removing any link from the cliques.
Examples
    
    >>> G = nx.ring_of_cliques(8, 4)
    
# random_internet_as_graph#
random_internet_as_graph(n, seed=None)[source]#
    
Generates a random undirected graph resembling the Internet AS network
Parameters:
    
n: integer in [1000, 10000]
    
Number of graph nodes
seedinteger, random_state, or None (default)
    
Indicator of random number generation state. See Randomness.
Returns:
    
G: Networkx Graph object
    
A randomly generated undirected graph
Notes
This algorithm returns an undirected graph resembling the Internet Autonomous System (AS) network, it uses the approach by Elmokashfi et al. [1] and it grants the properties described in the related paper [1].
Each node models an autonomous system, with an attribute ‘type’ specifying its kind; tier-1 (T), mid-level (M), customer (C) or content-provider (CP). Each edge models an ADV communication link (hence, bidirectional) with attributes:
>   * type: transit|peer, the kind of commercial agreement between nodes;
>   * customer: <node id>, the identifier of the node acting as customer (‘none’ if type is peer).
> 

References
[1] (1,2)
A. Elmokashfi, A. Kvalbein and C. Dovrolis, “On the Scalability of BGP: The Role of Topology Growth,” in IEEE Journal on Selected Areas in Communications, vol. 28, no. 8, pp. 1250-1261, October 2010.
# dodecahedral_graph#
dodecahedral_graph(create_using=None)[source]#
    
Returns the Platonic Dodecahedral graph.
The dodecahedral graph has 20 nodes and 30 edges. The skeleton of the dodecahedron forms a graph. It is one of 5 Platonic graphs [1]. It can be described in LCF notation as: `[10, 7, 4, -4, -7, 10, -4, 7, -7, 4]^2` [2].
Parameters:
    
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
Returns:
    
Gnetworkx Graph
    
Dodecahedral Graph with 20 nodes and 30 edges
References
[1]
https://en.wikipedia.org/wiki/Regular_dodecahedron#Dodecahedral_graph
[2]
https://mathworld.wolfram.com/DodecahedralGraph.html
# Eulerian#
Eulerian circuits and graphs.
`is_eulerian`(G)
Returns True if and only if `G` is Eulerian.  
`eulerian_circuit`(G[, source, keys])
Returns an iterator over the edges of an Eulerian circuit in `G`.  
`eulerize`(G)
Transforms a graph into an Eulerian graph.  
`is_semieulerian`(G)
Return True iff `G` is semi-Eulerian.  
`has_eulerian_path`(G[, source])
Return True iff `G` has an Eulerian path.  
`eulerian_path`(G[, source, keys])
Return an iterator over the edges of an Eulerian path in `G`.
# Eulerian#  
Eulerian circuits and graphs.
`is_eulerian`(G)
Returns True if and only if `G` is Eulerian.  
`eulerian_circuit`(G[, source, keys])
Returns an iterator over the edges of an Eulerian circuit in `G`.  
`eulerize`(G)
Transforms a graph into an Eulerian graph.  
`is_semieulerian`(G)
Return True iff `G` is semi-Eulerian.  
`has_eulerian_path`(G[, source])
Return True iff `G` has an Eulerian path.  
`eulerian_path`(G[, source, keys])
Return an iterator over the edges of an Eulerian path in `G`.
# Eulerian#  
Eulerian circuits and graphs.
`is_eulerian`(G)
Returns True if and only if `G` is Eulerian.  
`eulerian_circuit`(G[, source, keys])
Returns an iterator over the edges of an Eulerian circuit in `G`.  
`eulerize`(G)
Transforms a graph into an Eulerian graph.  
`is_semieulerian`(G)
Return True iff `G` is semi-Eulerian.  
`has_eulerian_path`(G[, source])
Return True iff `G` has an Eulerian path.  
`eulerian_path`(G[, source, keys])
Return an iterator over the edges of an Eulerian path in `G`.
# Eulerian#  
Eulerian circuits and graphs.
`is_eulerian`(G)
Returns True if and only if `G` is Eulerian.  
`eulerian_circuit`(G[, source, keys])
Returns an iterator over the edges of an Eulerian circuit in `G`.  
`eulerize`(G)
Transforms a graph into an Eulerian graph.  
`is_semieulerian`(G)
Return True iff `G` is semi-Eulerian.  
`has_eulerian_path`(G[, source])
Return True iff `G` has an Eulerian path.  
`eulerian_path`(G[, source, keys])
Return an iterator over the edges of an Eulerian path in `G`.
# Eulerian#  
Eulerian circuits and graphs.
`is_eulerian`(G)
Returns True if and only if `G` is Eulerian.  
`eulerian_circuit`(G[, source, keys])
Returns an iterator over the edges of an Eulerian circuit in `G`.  
`eulerize`(G)
Transforms a graph into an Eulerian graph.  
`is_semieulerian`(G)
Return True iff `G` is semi-Eulerian.  
`has_eulerian_path`(G[, source])
Return True iff `G` has an Eulerian path.  
`eulerian_path`(G[, source, keys])
Return an iterator over the edges of an Eulerian path in `G`.
# Backends#  
NetworkX can be configured to use separate thrid-party backends to improve performance and add functionality. Backends are optional, installed separately, and can be enabled either directly in the user’s code or through environment variables.
Note
The interface used by developers creating custom NetworkX backends is receiving frequent updates and improvements. Participating in weekly NetworkX dispatch meetings is an excellent way to stay updated and contribute to the ongoing discussions.
## Docs for backend users#
NetworkX utilizes a plugin-dispatch architecture. A valid NetworkX backend specifies entry points, named `networkx.backends` and an optional `networkx.backend_info` when it is installed (not imported). This allows NetworkX to dispatch (redirect) function calls to the backend so the execution flows to the designated backend implementation. This design enhances flexibility and integration, making NetworkX more adaptable and efficient.
NetworkX can dispatch to backends explicitly (this requires changing code) or automatically (this requires setting configuration or environment variables). The best way to use a backend depends on the backend, your use case, and whether you want to automatically convert to or from backend graphs. Automatic conversions of graphs is always opt-in.
To explicitly dispatch to a backend, use the `backend=` keyword argument in a dispatchable function. This will convert (and cache by default) input NetworkX graphs to backend graphs and call the backend implementation. Another explicit way to use a backend is to create a backend graph directly–for example, perhaps the backend has its own functions for loading data and creating graphs–and pass that graph to a dispatchable function, which will then call the backend implementation without converting.
Using automatic dispatch requires setting configuration options. Every NetworkX configuration may also be set from an environment variable and are processed at the time networkx is imported. The following configuration variables are supported:
  * `nx.config.backend_priority` (`NETWORKX_BACKEND_PRIORITY` env var), a list of backends, controls dispatchable functions that don’t return graphs such as e.g. `nx.pagerank`. When one of these functions is called with NetworkX graphs as input, the dispatcher iterates over the backends listed in this backend_priority config and will use the first backend that implements this function. The input NetworkX graphs are converted (and cached by default) to backend graphs. Using this configuration can allow you to use the full flexibility of NetworkX graphs and the performance of backend implementations, but possible downsides are that creating NetworkX graphs, converting to backend graphs, and caching backend graphs may all be expensive.
  * `nx.config.backend_priority.algos` (`NETWORKX_BACKEND_PRIORITY_ALGOS` env var), can be used instead of `nx.config.backend_priority` (`NETWORKX_BACKEND_PRIORITY` env var) to emphasize that the setting only affects the dispatching of algorithm functions as described above.
  * `nx.config.backend_priority.generators` (`NETWORKX_BACKEND_PRIORITY_GENERATORS` env var), a list of backends, controls dispatchable functions that return graphs such as nx.from_pandas_edgelist and nx.empty_graph. When one of these functions is called, the first backend listed in this backend_priority config that implements this function will be used and will return a backend graph. When this backend graph is passed to other dispatchable NetworkX functions, it will use the backend implementation if it exists or raise by default unless nx.config.fallback_to_nx is True (default is False). Using this configuration avoids creating NetworkX graphs, which subsequently avoids the need to convert to and cache backend graphs as when using nx.config.backend_priority.algos, but possible downsides are that the backend graph may not behave the same as a NetworkX graph and the backend may not implement all algorithms that you use, which may break your workflow.
  * `nx.config.fallback_to_nx` (`NETWORKX_FALLBACK_TO_NX` env var), a boolean (default False), controls what happens when a backend graph is passed to a dispatchable function that is not implemented by that backend. The default behavior when False is to raise. If True, then the backend graph will be converted (and cached by default) to a NetworkX graph and will run with the default NetworkX implementation. Enabling this configuration can allow workflows to complete if the backend does not implement all algorithms used by the workflow, but a possible downside is that it may require converting the input backend graph to a NetworkX graph, which may be expensive. If a backend graph is duck-type compatible as a NetworkX graph, then the backend may choose not to convert to a NetworkX graph and use the incoming graph as-is.
  * `nx.config.cache_converted_graphs` (`NETWORKX_CACHE_CONVERTED_GRAPHS` env var), a boolean (default True), controls whether graph conversions are cached to G.__networkx_cache__ or not. Caching can improve performance by avoiding repeated conversions, but it uses more memory.


Note
Backends should follow the NetworkX backend naming convention. For example, if a backend is named `parallel` and specified using `backend=parallel` or `NETWORKX_BACKEND_PRIORITY=parallel`, the package installed is `nx-parallel`, and we would use `import nx_parallel` if we were to import the backend package directly.
Backends are encouraged to document how they recommend to be used and whether their graph types are duck-type compatible as NetworkX graphs. If backend graphs are NetworkX-compatible and you want your workflow to automatically “just work” with a backend–converting and caching if necessary–then use all of the above configurations. Automatically converting graphs is opt-in, and configuration gives the user control.
### Examples:#
Use the `cugraph` backend for every algorithm function it supports. This will allow for fall back to the default NetworkX implementations for algorithm calls not supported by cugraph because graph generator functions are still returning NetworkX graphs.
    
    bash> NETWORKX_BACKEND_PRIORITY=cugraph python my_networkx_script.py
    
Explicitly use the `parallel` backend for a function call.
    
    nx.betweenness_centrality(G, k=10, backend="parallel")
    
Explicitly use the `parallel` backend for a function call by passing an instance of the backend graph type to the function.
    
    H = nx_parallel.ParallelGraph(G)
    nx.betweenness_centrality(H, k=10)
    
Explicitly use the `parallel` backend and pass additional backend-specific arguments. Here, `get_chunks` is an argument unique to the `parallel` backend.
    
    nx.betweenness_centrality(G, k=10, backend="parallel", get_chunks=get_chunks)
    
Automatically dispatch the `cugraph` backend for all NetworkX algorithms and generators, and allow the backend graph object returned from generators to be passed to NetworkX functions the backend does not support.
    
    bash> NETWORKX_BACKEND_PRIORITY_ALGOS=cugraph \\
          NETWORKX_BACKEND_PRIORITY_GENERATORS=cugraph \\
          NETWORKX_FALLBACK_TO_NX=True \\
          python my_networkx_script.py
    
### How does this work?#
If you’ve looked at functions in the NetworkX codebase, you might have seen the `@nx._dispatchable` decorator on most of the functions. This decorator allows the NetworkX function to dispatch to the corresponding backend function if available. When the decorated function is called, it first checks for a backend to run the function, and if no appropriate backend is specified or available, it runs the NetworkX version of the function.
#### Backend Keyword Argument#
When a decorated function is called with the `backend` kwarg provided, it checks if the specified backend is installed, and loads it. Next it checks whether to convert input graphs by first resolving the backend of each input graph by looking for an attribute named `__networkx_backend__` that holds the backend name for that graph type. If all input graphs backend matches the `backend` kwarg, the backend’s function is called with the original inputs. If any of the input graphs do not match the `backend` kwarg, they are converted to the backend graph type before calling. Exceptions are raised if any step is not possible, e.g. if the backend does not implement this function.
#### Finding a Backend#
When a decorated function is called without a `backend` kwarg, it tries to find a dispatchable backend function. The backend type of each input graph parameter is resolved (using the `__networkx_backend__` attribute) and if they all agree, that backend’s function is called if possible. Otherwise the backends listed in the config `backend_priority` are considered one at a time in order. If that backend supports the function and can convert the input graphs to its backend type, that backend function is called. Otherwise the next backend is considered.
During this process, the backends can provide helpful information to the dispatcher via helper methods in the backend’s interface. Backend methods `can_run` and `should_run` are used by the dispatcher to determine whether to use the backend function. If the number of nodes is small, it might be faster to run the NetworkX version of the function. This is how backends can provide info about whether to run.
#### Falling Back to NetworkX#
If none of the backends are appropriate, we “fall back” to the NetworkX function. That means we resolve the backends of all input graphs and if all are NetworkX graphs we call the NetworkX function. If any are not NetworkX graphs, we raise an exception unless the `fallback_to_nx` config is set. If it is, we convert all graph types to NetworkX graph types before calling the NetworkX function.
#### Functions that mutate the graph#
Any function decorated with the option that indicates it mutates the graph goes through a slightly different path to automatically find backends. These functions typically generate a graph, or add attributes or change the graph structure. The config `backend_priority.generators` holds a list of backend names similar to the config `backend_priority`. The process is similar for finding a matching backend. Once found, the backend function is called and a backend graph is returned (instead of a NetworkX graph). You can then use this backend graph in any function supported by the backend. And you can use it for functions not supported by the backend if you set the config `fallback_to_nx` to allow it to convert the backend graph to a NetworkX graph before calling the function.
#### Optional keyword arguments#
Backends can add optional keyword parameters to NetworkX functions to allow you to control aspects of the backend algorithm. Thus the function signatures can be extended beyond the NetworkX function signature. For example, the `parallel` backend might have a parameter to specify how many CPUs to use. These parameters are collected by the dispatchable decorator code at the start of the function call and used when calling the backend function.
#### Existing Backends#
NetworkX does not know all the backends that have been created. In fact, the NetworkX library does not need to know that a backend exists for it to work. As long as the backend package creates the `entry_point`, and provides the correct interface, it will be called when the user requests it using one of the three approaches described above. Some backends have been working with the NetworkX developers to ensure smooth operation.
Refer to the Backends section to see a list of available backends known to work with the current stable release of NetworkX.
### Introspection and Logging#
Introspection techniques aim to demystify dispatching and backend graph conversion behaviors.
The primary way to see what the dispatch machinery is doing is by enabling logging. This can help you verify that the backend you specified is being used. You can enable NetworkX’s backend logger to print to `sys.stderr` like this:
    
    import logging
    nxl = logging.getLogger("networkx")
    nxl.addHandler(logging.StreamHandler())
    nxl.setLevel(logging.DEBUG)
    
And you can disable it by running this:
    
    nxl.setLevel(logging.CRITICAL)
    
Refer to `logging` to learn more about the logging facilities in Python.
By looking at the `.backends` attribute, you can get the set of all currently installed backends that implement a particular function. For example:
    
    >>> nx.betweenness_centrality.backends
    {'parallel'}
    
The function docstring will also show which installed backends support it along with any backend-specific notes and keyword arguments:
    
    >>> help(nx.betweenness_centrality)
    ...
    Backends
    --------
    parallel : Parallel backend for NetworkX algorithms
      The parallel computation is implemented by dividing the nodes into chunks
      and computing betweenness centrality for each chunk concurrently.
    ...
    
The NetworkX documentation website also includes info about trusted backends of NetworkX in function references. For example, see `all_pairs_bellman_ford_path_length()`.
Introspection capabilities are currently limited, but we are working to improve them. We plan to make it easier to answer questions such as:
  * What happened (and why)?
  * What will happen (and why)?
  * Where was time spent (including conversions)?
  * What is in the cache and how much memory is it using?


Transparency is essential to allow for greater understanding, debug-ability, and customization. After all, NetworkX dispatching is extremely flexible and can support advanced workflows with multiple backends and fine-tuned configuration, but introspection can be helpful by describing when and how to evolve your workflow to meet your needs. If you have suggestions for how to improve introspection, please let us know!
## Docs for backend developers#
### Creating a custom backend#
  1. Defining a `BackendInterface` object:
Note that the `BackendInterface` doesn’t need to be a class. It can be an instance of a class, or a module as well. You can define the following methods or functions in your backend’s `BackendInterface` object.:
     1. `convert_from_nx` and `convert_to_nx` methods or functions are required for backend dispatching to work. The arguments to `convert_from_nx` are:
        * `G` : NetworkX Graph
        * `edge_attrs`dict, optional
    
Dictionary mapping edge attributes to default values if missing in `G`. If None, then no edge attributes will be converted and default may be 1.
        * `node_attrs`: dict, optional
    
Dictionary mapping node attributes to default values if missing in `G`. If None, then no node attributes will be converted.
        * `preserve_edge_attrs`bool
    
Whether to preserve all edge attributes.
        * `preserve_node_attrs`bool
    
Whether to preserve all node attributes.
        * `preserve_graph_attrs`bool
    
Whether to preserve all graph attributes.
        * `preserve_all_attrs`bool
    
Whether to preserve all graph, node, and edge attributes.
        * `name`str
    
The name of the algorithm.
        * `graph_name`str
    
The name of the graph argument being converted.
     2. `can_run` (Optional):
    
If your backend only partially implements an algorithm, you can define a `can_run(name, args, kwargs)` function in your `BackendInterface` object that returns True or False indicating whether the backend can run the algorithm with the given arguments or not. Instead of a boolean you can also return a string message to inform the user why that algorithm can’t be run.
     3. `should_run` (Optional):
    
A backend may also define `should_run(name, args, kwargs)` that is similar to `can_run`, but answers whether the backend should be run. `should_run` is only run when performing backend graph conversions. Like `can_run`, it receives the original arguments so it can decide whether it should be run by inspecting the arguments. `can_run` runs before `should_run`, so `should_run` may assume `can_run` is True. If not implemented by the backend, `can_run` and `should_run` are assumed to always return True if the backend implements the algorithm.
     4. `on_start_tests` (Optional):
    
A special `on_start_tests(items)` function may be defined by the backend. It will be called with the list of NetworkX tests discovered. Each item is a test object that can be marked as xfail if the backend does not support the test using `item.add_marker(pytest.mark.xfail(reason=...))`.
  2. Adding entry points
To be discoverable by NetworkX, your package must register an entry-point `networkx.backends` in the package’s metadata, with a key pointing to your dispatch object . For example, if you are using `setuptools` to manage your backend package, you can add the following to your pyproject.toml file:
         [project.entry-points."networkx.backends"]
         backend_name = "your_backend_interface_object"
         
You can also add the `backend_info` entry-point. It points towards the `get_info` function that returns all the backend information, which is then used to build the “Additional Backend Implementation” box at the end of algorithm’s documentation page. Note that the `get_info` function shouldn’t import your backend package.:
         [project.entry-points."networkx.backend_info"]
         backend_name = "your_get_info_function"
         
The `get_info` should return a dictionary with following key-value pairs:
    
     * `backend_name`str or None
    
It is the name passed in the `backend` kwarg and must be a valid Python identifier.
     * `project`str or None
    
The name of your backend project.
     * `package`str or None
    
The name of your backend package.
     * `url`str or None
    
This is the url to either your backend’s codebase or documentation, and will be displayed as a hyperlink to the `backend_name`, in the “Additional backend implementations” section.
     * `short_summary`str or None
    
One line summary of your backend which will be displayed in the “Additional backend implementations” section.
     * `default_config`dict
    
A dictionary mapping the backend config parameter names to their default values. This is used to automatically initialize the default configs for all the installed backends at the time of networkx’s import.
See also
`Config`
     * `functions`dict or None
    
A dictionary mapping function names to a dictionary of information about the function. The information can include the following keys:
       * `url` : str or None The url to `function`’s source code or documentation.
       * `additional_docs` : str or None A short description or note about the backend function’s implementation.
       * `additional_parameters` : dict or None A dictionary mapping additional parameters headers to their short descriptions. For example:
             "additional_parameters": {
                 'param1 : str, function (default = "chunks")' : "...",
                 'param2 : int' : "...",
             }
             
If any of these keys are not present, the corresponding information will not be displayed in the “Additional backend implementations” section on NetworkX docs website.
Note that your backend’s docs would only appear on the official NetworkX docs only if your backend is a trusted backend of NetworkX, and is present in the `circleci/config.yml` and `github/workflows/deploy-docs.yml` files in the NetworkX repository.
  3. Defining a Backend Graph class
The backend must create an object with an attribute `__networkx_backend__` that holds a string with the entry point name, which must be a valid Python identifier:
         class BackendGraph:
             __networkx_backend__ = "backend_name"
             ...
         
Backend graph objects are also required to implement the methods `is_directed()` and `is_multigraph()`. These methods return boolean values indicating the type of the graph:
     * `is_directed()` should return True if the graph is directed, and False otherwise.
     * `is_multigraph()` should return True if the graph allows multiple (parallel) edges between node pairs, and False otherwise.
These methods are used by NetworkX utilities such as the `@not_implemented_for` decorator to determine whether a graph meets certain type constraints and to raise an error if the function is not applicable to that graph type.
A backend graph instance may have a `G.__networkx_cache__` dict to enable caching, and care should be taken to clear the cache when appropriate.


### Testing the Custom backend#
To test your custom backend, you can run the NetworkX test suite on your backend. This also ensures that the custom backend is compatible with NetworkX’s API. The following steps will help you run the tests:
  1. Setting Backend Environment Variables:
    
     * `NETWORKX_TEST_BACKEND` : Setting this to your backend’s `backend_name` will let NetworkX’s dispatch machinery to automatically convert a regular NetworkX `Graph`, `DiGraph`, `MultiGraph`, etc. to their backend equivalents, using `your_backend_interface_object.convert_from_nx(G, ...)` function.
     * `NETWORKX_FALLBACK_TO_NX` (default=False) : Setting this variable to `True` will instruct tests to use a NetworkX `Graph` for algorithms not implemented by your custom backend. Setting this to `False` will only run the tests for algorithms implemented by your custom backend and tests for other algorithms will `xfail`.
  2. Running Tests:
    
You can invoke NetworkX tests for your custom backend with the following commands:
         NETWORKX_TEST_BACKEND=<backend_name>
         NETWORKX_FALLBACK_TO_NX=True # or False
         pytest --pyargs networkx
         


### How tests are run?#
  1. While dispatching to the backend implementation the `_convert_and_call` function is used and while testing the `_convert_and_call_for_tests` function is used. Other than testing it also checks for functions that return numpy scalars, and for functions that return graphs it runs the backend implementation and the networkx implementation and then converts the backend graph into a NetworkX graph and then compares them, and returns the networkx graph. This can be regarded as (pragmatic) technical debt. We may replace these checks in the future.
  2. Conversions while running tests:
    
     * Convert NetworkX graphs using `<your_backend_interface_object>.convert_from_nx(G, ...)` into the backend graph.
     * Pass the backend graph objects to the backend implementation of the algorithm.
     * Convert the result back to a form expected by NetworkX tests using `<your_backend_interface_object>.convert_to_nx(result, ...)`.
     * For nx_loopback, the graph is copied using the dispatchable metadata
  3. Dispatchable algorithms that are not implemented by the backend will cause a `pytest.xfail`, when the `NETWORKX_FALLBACK_TO_NX` environment variable is set to `False`, giving some indication that not all tests are running, while avoiding causing an explicit failure.


`_dispatchable`([func, name, graphs, ...])
A decorator function that is used to redirect the execution of `func` function to its backend implementation.
# common_neighbor_centrality#  
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# common_neighbor_centrality#
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# common_neighbor_centrality#
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# common_neighbor_centrality#
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# common_neighbor_centrality#  
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# Drawing#
NetworkX provides basic functionality for visualizing graphs, but its main goal is to enable graph analysis rather than perform graph visualization. In the future, graph visualization functionality may be removed from NetworkX or only available as an add-on package.
Proper graph visualization is hard, and we highly recommend that people visualize their graphs with tools dedicated to that task. Notable examples of dedicated and fully-featured graph visualization tools are Cytoscape, Gephi, Graphviz and, for LaTeX typesetting, PGF/TikZ. To use these and other such tools, you should export your NetworkX graph into a format that can be read by those tools. For example, Cytoscape can read the GraphML format, and so, `networkx.write_graphml(G, path)` might be an appropriate choice.
More information on the features provided here are available at
    
  * matplotlib: http://matplotlib.org/
  * pygraphviz: http://pygraphviz.github.io/


## Matplotlib#
Draw networks with matplotlib.
### Examples#
    
    >>> G = nx.complete_graph(5)
    >>> nx.draw(G)
    
### See Also#
>   * matplotlib
>   * `matplotlib.pyplot.scatter()`
>   * `matplotlib.patches.FancyArrowPatch`
> 

`display`(G[, canvas])
Draw the graph G.  
`apply_matplotlib_colors`(G, src_attr, ...[, ...])
Apply colors from a matplotlib colormap to a graph.  
`draw`(G[, pos, ax])
Draw the graph G with Matplotlib.  
`draw_networkx`(G[, pos, arrows, with_labels])
Draw the graph G using Matplotlib.  
`draw_networkx_nodes`(G, pos[, nodelist, ...])
Draw the nodes of the graph G.  
`draw_networkx_edges`(G, pos[, edgelist, ...])
Draw the edges of the graph G.  
`draw_networkx_labels`(G, pos[, labels, ...])
Draw node labels on the graph G.  
`draw_networkx_edge_labels`(G, pos[, ...])
Draw edge labels.  
`draw_bipartite`(G, **kwargs)
Draw the graph `G` with a bipartite layout.  
`draw_circular`(G, **kwargs)
Draw the graph `G` with a circular layout.  
`draw_kamada_kawai`(G, **kwargs)
Draw the graph `G` with a Kamada-Kawai force-directed layout.  
`draw_planar`(G, **kwargs)
Draw a planar networkx graph `G` with planar layout.  
`draw_random`(G, **kwargs)
Draw the graph `G` with a random layout.  
`draw_spectral`(G, **kwargs)
Draw the graph `G` with a spectral 2D layout.  
`draw_spring`(G, **kwargs)
Draw the graph `G` with a spring layout.  
`draw_shell`(G[, nlist])
Draw networkx graph `G` with shell layout.  
## Graphviz AGraph (dot)#
Interface to pygraphviz AGraph class.
### Examples#
    
    >>> G = nx.complete_graph(5)
    >>> A = nx.nx_agraph.to_agraph(G)
    >>> H = nx.nx_agraph.from_agraph(A)
    
### See Also#
>   * Pygraphviz: http://pygraphviz.github.io/
>   * Graphviz: https://www.graphviz.org
>   * DOT Language: http://www.graphviz.org/doc/info/lang.html
> 

`from_agraph`(A[, create_using])
Returns a NetworkX Graph or DiGraph from a PyGraphviz graph.  
`to_agraph`(N)
Returns a pygraphviz graph from a NetworkX graph N.  
`write_dot`(G, path)
Write NetworkX graph G to Graphviz dot format on path.  
`read_dot`(path)
Returns a NetworkX graph from a dot file on path.  
`graphviz_layout`(G[, prog, root, args])
Create node positions for G using Graphviz.  
`pygraphviz_layout`(G[, prog, root, args])
Create node positions for G using Graphviz.  
## Graphviz with pydot#
Import and export NetworkX graphs in Graphviz dot format using pydot.
Either this module or nx_agraph can be used to interface with graphviz.
### Examples#
    
    >>> G = nx.complete_graph(5)
    >>> PG = nx.nx_pydot.to_pydot(G)
    >>> H = nx.nx_pydot.from_pydot(PG)
    
### See Also#
>   * pydot: erocarrera/pydot
>   * Graphviz: https://www.graphviz.org
>   * DOT Language: http://www.graphviz.org/doc/info/lang.html
> 

`from_pydot`(P)
Returns a NetworkX graph from a Pydot graph.  
`to_pydot`(N)
Returns a pydot graph from a NetworkX graph N.  
`write_dot`(G, path)
Write NetworkX graph G to Graphviz dot format on path.  
`read_dot`(path)
Returns a NetworkX `MultiGraph` or `MultiDiGraph` from the dot file with the passed path.  
`graphviz_layout`(G[, prog, root])
Create node positions using Pydot and Graphviz.  
`pydot_layout`(G[, prog, root])
Create node positions using `pydot` and Graphviz.  
## Graph Layout#
Node positioning algorithms for graph drawing.
For `random_layout()` the possible resulting shape is a square of side [0, scale] (default: [0, 1]) Changing `center` shifts the layout by that amount.
For the other layout routines, the extent is [center - scale, center + scale] (default: [-1, 1]).
Warning: Most layout routines have only been tested in 2-dimensions.
`arf_layout`(G[, pos, scaling, a, etol, dt, ...])
Arf layout for networkx  
`bipartite_layout`(G[, nodes, align, scale, ...])
Position nodes in two straight lines.  
`bfs_layout`(G, start, *[, align, scale, ...])
Position nodes according to breadth-first search algorithm.  
`circular_layout`(G[, scale, center, dim, ...])
Position nodes on a circle.  
`forceatlas2_layout`(G[, pos, max_iter, ...])
Position nodes using the ForceAtlas2 force-directed layout algorithm.  
`kamada_kawai_layout`(G[, dist, pos, weight, ...])
Position nodes using Kamada-Kawai path-length cost-function.  
`planar_layout`(G[, scale, center, dim, ...])
Position nodes without edge intersections.  
`random_layout`(G[, center, dim, seed, ...])
Position nodes uniformly at random in the unit square.  
`rescale_layout`(pos[, scale])
Returns scaled position array to (-scale, scale) in all axes.  
`rescale_layout_dict`(pos[, scale])
Return a dictionary of scaled positions keyed by node  
`shell_layout`(G[, nlist, rotate, scale, ...])
Position nodes in concentric circles.  
`spring_layout`(G[, k, pos, fixed, ...])
Position nodes using Fruchterman-Reingold force-directed algorithm.  
`spectral_layout`(G[, weight, scale, center, ...])
Position nodes using the eigenvectors of the graph Laplacian.  
`spiral_layout`(G[, scale, center, dim, ...])
Position nodes in a spiral layout.  
`multipartite_layout`(G[, subset_key, align, ...])
Position nodes in layers of straight lines.  
## LaTeX Code#
Export NetworkX graphs in LaTeX format using the TikZ library within TeX/LaTeX. Usually, you will want the drawing to appear in a figure environment so you use `to_latex(G, caption="A caption")`. If you want the raw drawing commands without a figure environment use `to_latex_raw()`. And if you want to write to a file instead of just returning the latex code as a string, use `write_latex(G, "filename.tex", caption="A caption")`.
To construct a figure with subfigures for each graph to be shown, provide `to_latex` or `write_latex` a list of graphs, a list of subcaptions, and a number of rows of subfigures inside the figure.
To be able to refer to the figures or subfigures in latex using `\\ref`, the keyword `latex_label` is available for figures and `sub_labels` for a list of labels, one for each subfigure.
We intend to eventually provide an interface to the TikZ Graph features which include e.g. layout algorithms.
Let us know via github what you’d like to see available, or better yet give us some code to do it, or even better make a github pull request to add the feature.
### The TikZ approach#
Drawing options can be stored on the graph as node/edge attributes, or can be provided as dicts keyed by node/edge to a string of the options for that node/edge. Similarly a label can be shown for each node/edge by specifying the labels as graph node/edge attributes or by providing a dict keyed by node/edge to the text to be written for that node/edge.
Options for the tikzpicture environment (e.g. “[scale=2]”) can be provided via a keyword argument. Similarly default node and edge options can be provided through keywords arguments. The default node options are applied to the single TikZ “path” that draws all nodes (and no edges). The default edge options are applied to a TikZ “scope” which contains a path for each edge.
### Examples#
    
    >>> G = nx.path_graph(3)
    >>> nx.write_latex(G, "just_my_figure.tex", as_document=True)
    >>> nx.write_latex(G, "my_figure.tex", caption="A path graph", latex_label="fig1")
    >>> latex_code = nx.to_latex(G)  # a string rather than a file
    
You can change many features of the nodes and edges.
    
    >>> G = nx.path_graph(4, create_using=nx.DiGraph)
    >>> pos = {n: (n, n) for n in G}  # nodes set on a line
    
    
    >>> G.nodes[0]["style"] = "blue"
    >>> G.nodes[2]["style"] = "line width=3,draw"
    >>> G.nodes[3]["label"] = "Stop"
    >>> G.edges[(0, 1)]["label"] = "1st Step"
    >>> G.edges[(0, 1)]["label_opts"] = "near start"
    >>> G.edges[(1, 2)]["style"] = "line width=3"
    >>> G.edges[(1, 2)]["label"] = "2nd Step"
    >>> G.edges[(2, 3)]["style"] = "green"
    >>> G.edges[(2, 3)]["label"] = "3rd Step"
    >>> G.edges[(2, 3)]["label_opts"] = "near end"
    
    
    >>> nx.write_latex(G, "latex_graph.tex", pos=pos, as_document=True)
    
Then compile the LaTeX using something like `pdflatex latex_graph.tex` and view the pdf file created: `latex_graph.pdf`.
If you want subfigures each containing one graph, you can input a list of graphs.
    
    >>> H1 = nx.path_graph(4)
    >>> H2 = nx.complete_graph(4)
    >>> H3 = nx.path_graph(8)
    >>> H4 = nx.complete_graph(8)
    >>> graphs = [H1, H2, H3, H4]
    >>> caps = ["Path 4", "Complete graph 4", "Path 8", "Complete graph 8"]
    >>> lbls = ["fig2a", "fig2b", "fig2c", "fig2d"]
    >>> nx.write_latex(graphs, "subfigs.tex", n_rows=2, sub_captions=caps, sub_labels=lbls)
    >>> latex_code = nx.to_latex(graphs, n_rows=2, sub_captions=caps, sub_labels=lbls)
    
    
    >>> node_color = {0: "red", 1: "orange", 2: "blue", 3: "gray!90"}
    >>> edge_width = {e: "line width=1.5" for e in H3.edges}
    >>> pos = nx.circular_layout(H3)
    >>> latex_code = nx.to_latex(H3, pos, node_options=node_color, edge_options=edge_width)
    >>> print(latex_code)
    \documentclass{report}
    \usepackage{tikz}
    \usepackage{subcaption}
    
    \begin{document}
    \begin{figure}
      \begin{tikzpicture}
          \draw
            (1.0, 0.0) node[red] (0){0}
            (0.707, 0.707) node[orange] (1){1}
            (-0.0, 1.0) node[blue] (2){2}
            (-0.707, 0.707) node[gray!90] (3){3}
            (-1.0, -0.0) node (4){4}
            (-0.707, -0.707) node (5){5}
            (0.0, -1.0) node (6){6}
            (0.707, -0.707) node (7){7};
          \begin{scope}[-]
            \draw[line width=1.5] (0) to (1);
            \draw[line width=1.5] (1) to (2);
            \draw[line width=1.5] (2) to (3);
            \draw[line width=1.5] (3) to (4);
            \draw[line width=1.5] (4) to (5);
            \draw[line width=1.5] (5) to (6);
            \draw[line width=1.5] (6) to (7);
          \end{scope}
        \end{tikzpicture}
    \end{figure}
    \end{document}
    
#### Notes#
If you want to change the preamble/postamble of the figure/document/subfigure environment, use the keyword arguments: `figure_wrapper`, `document_wrapper`, `subfigure_wrapper`. The default values are stored in private variables e.g. `nx.nx_layout._DOCUMENT_WRAPPER`
#### References#
TikZ: https://tikz.dev/
TikZ options details: https://tikz.dev/tikz-actions
`to_latex_raw`(G[, pos, tikz_options, ...])
Return a string of the LaTeX/TikZ code to draw `G`  
`to_latex`(Gbunch[, pos, tikz_options, ...])
Return latex code to draw the graph(s) in `Gbunch`  
`write_latex`(Gbunch, path, **options)
Write the latex code to draw the graph(s) onto `path`.
# common_neighbor_centrality#
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# common_neighbor_centrality#
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# common_neighbor_centrality#
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# PlanarEmbedding.check_structure#
PlanarEmbedding.check_structure()[source]#
    
Runs without exceptions if this object is valid.
Checks that the following properties are fulfilled:
  * Edges go in both directions (because the edge attributes differ).
  * Every edge has a ‘cw’ and ‘ccw’ attribute which corresponds to a correct planar embedding.


Running this method verifies that the underlying Graph must be planar.
Raises:
    
NetworkXException
    
This exception is raised with a short explanation if the PlanarEmbedding is invalid.
# common_neighbor_centrality#
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# common_neighbor_centrality#
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# common_neighbor_centrality#
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# common_neighbor_centrality#
common_neighbor_centrality(G, ebunch=None, alpha=0.8)[source]#
    
Return the CCPA score for each pair of nodes.
Compute the Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score of all node pairs in ebunch.
CCPA score of `u` and `v` is defined as
\\[\alpha \cdot (|\Gamma (u){\cap }^{}\Gamma (v)|)+(1-\alpha )\cdot \frac{N}{{d}_{uv}}\\]
where \\(\Gamma(u)\\) denotes the set of neighbors of \\(u\\), \\(\Gamma(v)\\) denotes the set of neighbors of \\(v\\), \\(\alpha\\) is parameter varies between [0,1], \\(N\\) denotes total number of nodes in the Graph and \\({d}_{uv}\\) denotes shortest distance between \\(u\\) and \\(v\\).
This algorithm is based on two vital properties of nodes, namely the number of common neighbors and their centrality. Common neighbor refers to the common nodes between two nodes. Centrality refers to the prestige that a node enjoys in a network.
See also
`common_neighbors()`
Parameters:
    
Ggraph
    
NetworkX undirected graph.
ebunchiterable of node pairs, optional (default = None)
    
Preferential attachment score will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all nonexistent edges in the graph will be used. Default value: None.
alphaParameter defined for participation of Common Neighbor
    
and Centrality Algorithm share. Values for alpha should normally be between 0 and 1. Default value set to 0.8 because author found better performance at 0.8 for all the dataset. Default value: 0.8
Returns:
    
piteriterator
    
An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Common Neighbor and Centrality based Parameterized Algorithm(CCPA) score.
Raises:
    
NetworkXNotImplemented
    
If `G` is a `DiGraph`, a `Multigraph` or a `MultiDiGraph`.
NetworkXAlgorithmError
    
If self loops exist in `ebunch` or in `G` (if `ebunch` is `None`).
NodeNotFound
    
If `ebunch` has a node that is not in `G`.
References
[1]
Ahmad, I., Akhtar, M.U., Noor, S. et al. Missing Link Prediction using Common Neighbor and Centrality based Parameterized Algorithm. Sci Rep 10, 364 (2020). https://doi.org/10.1038/s41598-019-57304-y
Examples
    
    >>> G = nx.complete_graph(5)
    >>> preds = nx.common_neighbor_centrality(G, [(0, 1), (2, 3)])
    >>> for u, v, p in preds:
    ...     print(f"({u}, {v}) -> {p}")
    (0, 1) -> 3.4000000000000004
    (2, 3) -> 3.4000000000000004
    
# PlanarEmbedding.check_structure#
PlanarEmbedding.check_structure()[source]#
    
Runs without exceptions if this object is valid.
Checks that the following properties are fulfilled:
  * Edges go in both directions (because the edge attributes differ).
  * Every edge has a ‘cw’ and ‘ccw’ attribute which corresponds to a correct planar embedding.


Running this method verifies that the underlying Graph must be planar.
Raises:
    
NetworkXException
    
This exception is raised with a short explanation if the PlanarEmbedding is invalid.
# PlanarEmbedding.check_structure#
PlanarEmbedding.check_structure()[source]#
    
Runs without exceptions if this object is valid.
Checks that the following properties are fulfilled:
  * Edges go in both directions (because the edge attributes differ).
  * Every edge has a ‘cw’ and ‘ccw’ attribute which corresponds to a correct planar embedding.


Running this method verifies that the underlying Graph must be planar.
Raises:
    
NetworkXException
    
This exception is raised with a short explanation if the PlanarEmbedding is invalid.
# PlanarEmbedding.check_structure#
PlanarEmbedding.check_structure()[source]#
    
Runs without exceptions if this object is valid.
Checks that the following properties are fulfilled:
  * Edges go in both directions (because the edge attributes differ).
  * Every edge has a ‘cw’ and ‘ccw’ attribute which corresponds to a correct planar embedding.


Running this method verifies that the underlying Graph must be planar.
Raises:
    
NetworkXException
    
This exception is raised with a short explanation if the PlanarEmbedding is invalid.
# MultiDiGraph.edge_subgraph#
MultiDiGraph.edge_subgraph(edges)#
    
Returns the subgraph induced by the specified edges.
The induced subgraph contains each edge in `edges` and each node incident to any one of those edges.
Parameters:
    
edgesiterable
    
An iterable of edges in this graph.
Returns:
    
GGraph
    
An edge-induced subgraph of this graph with the same edge attributes.
Notes
The graph, edge, and node attributes in the returned subgraph view are references to the corresponding attributes in the original graph. The view is read-only.
To create a full graph version of the subgraph with its own copy of the edge or node attributes, use:
    
    G.edge_subgraph(edges).copy()
    
Examples
    
    >>> G = nx.path_graph(5)
    >>> H = G.edge_subgraph([(0, 1), (3, 4)])
    >>> list(H.nodes)
    [0, 1, 3, 4]
    >>> list(H.edges)
    [(0, 1), (3, 4)]
    
# MultiDiGraph—Directed graphs with self loops and parallel edges#
## Overview#
class MultiDiGraph(incoming_graph_data=None, multigraph_input=None, **attr)[source]#
    
A directed graph class that can store multiedges.
Multiedges are multiple edges between two nodes. Each edge can hold optional data or attributes.
A MultiDiGraph holds directed edges. Self loops are allowed.
Nodes can be arbitrary (hashable) Python objects with optional key/value attributes. By convention `None` is not used as a node.
Edges are represented as links between nodes with optional key/value attributes.
Parameters:
    
incoming_graph_datainput graph (optional, default: None)
    
Data to initialize graph. If None (default) an empty graph is created. The data can be any format that is supported by the to_networkx_graph() function, currently including edge list, dict of dicts, dict of lists, NetworkX graph, 2D NumPy array, SciPy sparse matrix, or PyGraphviz graph.
multigraph_inputbool or None (default None)
    
Note: Only used when `incoming_graph_data` is a dict. If True, `incoming_graph_data` is assumed to be a dict-of-dict-of-dict-of-dict structure keyed by node to neighbor to edge keys to edge data for multi-edges. A NetworkXError is raised if this is not the case. If False, `to_networkx_graph()` is used to try to determine the dict’s graph data structure as either a dict-of-dict-of-dict keyed by node to neighbor to edge data, or a dict-of-iterable keyed by node to neighbors. If None, the treatment for True is tried, but if it fails, the treatment for False is tried.
attrkeyword arguments, optional (default= no attributes)
    
Attributes to add to graph as key=value pairs.
See also
`Graph`
    
`DiGraph`
    
`MultiGraph`
    
Examples
Create an empty graph structure (a “null graph”) with no nodes and no edges.
    
    >>> G = nx.MultiDiGraph()
    
G can be grown in several ways.
Nodes:
Add one node at a time:
    
    >>> G.add_node(1)
    
Add the nodes from any container (a list, dict, set or even the lines from a file or the nodes from another graph).
    
    >>> G.add_nodes_from([2, 3])
    >>> G.add_nodes_from(range(100, 110))
    >>> H = nx.path_graph(10)
    >>> G.add_nodes_from(H)
    
In addition to strings and integers any hashable Python object (except None) can represent a node, e.g. a customized node object, or even another Graph.
    
    >>> G.add_node(H)
    
Edges:
G can also be grown by adding edges.
Add one edge,
    
    >>> key = G.add_edge(1, 2)
    
a list of edges,
    
    >>> keys = G.add_edges_from([(1, 2), (1, 3)])
    
or a collection of edges,
    
    >>> keys = G.add_edges_from(H.edges)
    
If some edges connect nodes not yet in the graph, the nodes are added automatically. If an edge already exists, an additional edge is created and stored using a key to identify the edge. By default the key is the lowest unused integer.
    
    >>> keys = G.add_edges_from([(4, 5, dict(route=282)), (4, 5, dict(route=37))])
    >>> G[4]
    AdjacencyView({5: {0: {}, 1: {'route': 282}, 2: {'route': 37}}})
    
Attributes:
Each graph, node, and edge can hold key/value attribute pairs in an associated attribute dictionary (the keys must be hashable). By default these are empty, but can be added or changed using add_edge, add_node or direct manipulation of the attribute dictionaries named graph, node and edge respectively.
    
    >>> G = nx.MultiDiGraph(day="Friday")
    >>> G.graph
    {'day': 'Friday'}
    
Add node attributes using add_node(), add_nodes_from() or G.nodes
    
    >>> G.add_node(1, time="5pm")
    >>> G.add_nodes_from([3], time="2pm")
    >>> G.nodes[1]
    {'time': '5pm'}
    >>> G.nodes[1]["room"] = 714
    >>> del G.nodes[1]["room"]  # remove attribute
    >>> list(G.nodes(data=True))
    [(1, {'time': '5pm'}), (3, {'time': '2pm'})]
    
Add edge attributes using add_edge(), add_edges_from(), subscript notation, or G.edges.
    
    >>> key = G.add_edge(1, 2, weight=4.7)
    >>> keys = G.add_edges_from([(3, 4), (4, 5)], color="red")
    >>> keys = G.add_edges_from([(1, 2, {"color": "blue"}), (2, 3, {"weight": 8})])
    >>> G[1][2][0]["weight"] = 4.7
    >>> G.edges[1, 2, 0]["weight"] = 4
    
Warning: we protect the graph data structure by making `G.edges[1, 2, 0]` a read-only dict-like structure. However, you can assign to attributes in e.g. `G.edges[1, 2, 0]`. Thus, use 2 sets of brackets to add/change data attributes: `G.edges[1, 2, 0]['weight'] = 4` (for multigraphs the edge key is required: `MG.edges[u, v, key][name] = value`).
Shortcuts:
Many common graph features allow python syntax to speed reporting.
    
    >>> 1 in G  # check if node in graph
    True
    >>> [n for n in G if n < 3]  # iterate through nodes
    [1, 2]
    >>> len(G)  # number of nodes in graph
    5
    >>> G[1]  # adjacency dict-like view mapping neighbor -> edge key -> edge attributes
    AdjacencyView({2: {0: {'weight': 4}, 1: {'color': 'blue'}}})
    
Often the best way to traverse all edges of a graph is via the neighbors. The neighbors are available as an adjacency-view `G.adj` object or via the method `G.adjacency()`.
    
    >>> for n, nbrsdict in G.adjacency():
    ...     for nbr, keydict in nbrsdict.items():
    ...         for key, eattr in keydict.items():
    ...             if "weight" in eattr:
    ...                 # Do something useful with the edges
    ...                 pass
    
But the edges() method is often more convenient:
    
    >>> for u, v, keys, weight in G.edges(data="weight", keys=True):
    ...     if weight is not None:
    ...         # Do something useful with the edges
    ...         pass
    
Reporting:
Simple graph information is obtained using methods and object-attributes. Reporting usually provides views instead of containers to reduce memory usage. The views update as the graph is updated similarly to dict-views. The objects `nodes`, `edges` and `adj` provide access to data attributes via lookup (e.g. `nodes[n]`, `edges[u, v, k]`, `adj[u][v]`) and iteration (e.g. `nodes.items()`, `nodes.data('color')`, `nodes.data('color', default='blue')` and similarly for `edges`) Views exist for `nodes`, `edges`, `neighbors()`/`adj` and `degree`.
For details on these and other miscellaneous methods, see below.
Subclasses (Advanced):
The MultiDiGraph class uses a dict-of-dict-of-dict-of-dict structure. The outer dict (node_dict) holds adjacency information keyed by node. The next dict (adjlist_dict) represents the adjacency information and holds edge_key dicts keyed by neighbor. The edge_key dict holds each edge_attr dict keyed by edge key. The inner dict (edge_attr_dict) represents the edge data and holds edge attribute values keyed by attribute names.
Each of these four dicts in the dict-of-dict-of-dict-of-dict structure can be replaced by a user defined dict-like object. In general, the dict-like features should be maintained but extra features can be added. To replace one of the dicts create a new graph class by changing the class(!) variable holding the factory for that dict-like structure. The variable names are node_dict_factory, node_attr_dict_factory, adjlist_inner_dict_factory, adjlist_outer_dict_factory, edge_key_dict_factory, edge_attr_dict_factory and graph_attr_dict_factory.
node_dict_factoryfunction, (default: dict)
    
Factory function to be used to create the dict containing node attributes, keyed by node id. It should require no arguments and return a dict-like object
node_attr_dict_factory: function, (default: dict)
    
Factory function to be used to create the node attribute dict which holds attribute values keyed by attribute name. It should require no arguments and return a dict-like object
adjlist_outer_dict_factoryfunction, (default: dict)
    
Factory function to be used to create the outer-most dict in the data structure that holds adjacency info keyed by node. It should require no arguments and return a dict-like object.
adjlist_inner_dict_factoryfunction, (default: dict)
    
Factory function to be used to create the adjacency list dict which holds multiedge key dicts keyed by neighbor. It should require no arguments and return a dict-like object.
edge_key_dict_factoryfunction, (default: dict)
    
Factory function to be used to create the edge key dict which holds edge data keyed by edge key. It should require no arguments and return a dict-like object.
edge_attr_dict_factoryfunction, (default: dict)
    
Factory function to be used to create the edge attribute dict which holds attribute values keyed by attribute name. It should require no arguments and return a dict-like object.
graph_attr_dict_factoryfunction, (default: dict)
    
Factory function to be used to create the graph attribute dict which holds attribute values keyed by attribute name. It should require no arguments and return a dict-like object.
Typically, if your extension doesn’t impact the data structure all methods will inherited without issue except: `to_directed/to_undirected`. By default these methods create a DiGraph/Graph class and you probably want them to create your extension of a DiGraph/Graph. To facilitate this we define two class variables that you can set in your subclass.
to_directed_classcallable, (default: DiGraph or MultiDiGraph)
    
Class to create a new graph structure in the `to_directed` method. If `None`, a NetworkX class (DiGraph or MultiDiGraph) is used.
to_undirected_classcallable, (default: Graph or MultiGraph)
    
Class to create a new graph structure in the `to_undirected` method. If `None`, a NetworkX class (Graph or MultiGraph) is used.
Subclassing Example
Create a low memory graph class that effectively disallows edge attributes by using a single attribute dict for all edges. This reduces the memory used, but you lose edge attributes.
    
    >>> class ThinGraph(nx.Graph):
    ...     all_edge_dict = {"weight": 1}
    ...
    ...     def single_edge_dict(self):
    ...         return self.all_edge_dict
    ...
    ...     edge_attr_dict_factory = single_edge_dict
    >>> G = ThinGraph()
    >>> G.add_edge(2, 1)
    >>> G[2][1]
    {'weight': 1}
    >>> G.add_edge(2, 2)
    >>> G[2][1] is G[2][2]
    True
    
## Methods#
### Adding and Removing Nodes and Edges#
`MultiDiGraph.__init__`([incoming_graph_data, ...])
Initialize a graph with edges, name, or graph attributes.  
`MultiDiGraph.add_node`(node_for_adding, **attr)
Add a single node `node_for_adding` and update node attributes.  
`MultiDiGraph.add_nodes_from`(...)
Add multiple nodes.  
`MultiDiGraph.remove_node`(n)
Remove node n.  
`MultiDiGraph.remove_nodes_from`(nodes)
Remove multiple nodes.  
`MultiDiGraph.add_edge`(u_for_edge, v_for_edge)
Add an edge between u and v.  
`MultiDiGraph.add_edges_from`(ebunch_to_add, ...)
Add all the edges in ebunch_to_add.  
`MultiDiGraph.add_weighted_edges_from`(...[, ...])
Add weighted edges in `ebunch_to_add` with specified weight attr  
`MultiDiGraph.new_edge_key`(u, v)
Returns an unused key for edges between nodes `u` and `v`.  
`MultiDiGraph.remove_edge`(u, v[, key])
Remove an edge between u and v.  
`MultiDiGraph.remove_edges_from`(ebunch)
Remove all edges specified in ebunch.  
`MultiDiGraph.update`([edges, nodes])
Update the graph using nodes/edges/graphs as input.  
`MultiDiGraph.clear`()
Remove all nodes and edges from the graph.  
`MultiDiGraph.clear_edges`()
Remove all edges from the graph without altering nodes.  
### Reporting nodes edges and neighbors#
`MultiDiGraph.nodes`
A NodeView of the Graph as G.nodes or G.nodes().  
`MultiDiGraph.__iter__`()
Iterate over the nodes.  
`MultiDiGraph.has_node`(n)
Returns True if the graph contains the node n.  
`MultiDiGraph.__contains__`(n)
Returns True if n is a node, False otherwise.  
`MultiDiGraph.edges`
An OutMultiEdgeView of the Graph as G.edges or G.edges().  
`MultiDiGraph.out_edges`
An OutMultiEdgeView of the Graph as G.edges or G.edges().  
`MultiDiGraph.in_edges`
A view of the in edges of the graph as G.in_edges or G.in_edges().  
`MultiDiGraph.has_edge`(u, v[, key])
Returns True if the graph has an edge between nodes u and v.  
`MultiDiGraph.get_edge_data`(u, v[, key, default])
Returns the attribute dictionary associated with edge (u, v, key).  
`MultiDiGraph.neighbors`(n)
Returns an iterator over successor nodes of n.  
`MultiDiGraph.adj`
Graph adjacency object holding the neighbors of each node.  
`MultiDiGraph.__getitem__`(n)
Returns a dict of neighbors of node n.  
`MultiDiGraph.successors`(n)
Returns an iterator over successor nodes of n.  
`MultiDiGraph.succ`
Graph adjacency object holding the successors of each node.  
`MultiDiGraph.predecessors`(n)
Returns an iterator over predecessor nodes of n.  
`MultiDiGraph.pred`
Graph adjacency object holding the predecessors of each node.  
`MultiDiGraph.adjacency`()
Returns an iterator over (node, adjacency dict) tuples for all nodes.  
`MultiDiGraph.nbunch_iter`([nbunch])
Returns an iterator over nodes contained in nbunch that are also in the graph.  
### Counting nodes edges and neighbors#
`MultiDiGraph.order`()
Returns the number of nodes in the graph.  
`MultiDiGraph.number_of_nodes`()
Returns the number of nodes in the graph.  
`MultiDiGraph.__len__`()
Returns the number of nodes in the graph.  
`MultiDiGraph.degree`
A DegreeView for the Graph as G.degree or G.degree().  
`MultiDiGraph.in_degree`
A DegreeView for (node, in_degree) or in_degree for single node.  
`MultiDiGraph.out_degree`
Returns an iterator for (node, out-degree) or out-degree for single node.  
`MultiDiGraph.size`([weight])
Returns the number of edges or total of all edge weights.  
`MultiDiGraph.number_of_edges`([u, v])
Returns the number of edges between two nodes.  
### Making copies and subgraphs#
`MultiDiGraph.copy`([as_view])
Returns a copy of the graph.  
`MultiDiGraph.to_undirected`([reciprocal, as_view])
Returns an undirected representation of the digraph.  
`MultiDiGraph.to_directed`([as_view])
Returns a directed representation of the graph.  
`MultiDiGraph.subgraph`(nodes)
Returns a SubGraph view of the subgraph induced on `nodes`.  
`MultiDiGraph.edge_subgraph`(edges)
Returns the subgraph induced by the specified edges.  
`MultiDiGraph.reverse`([copy])
Returns the reverse of the graph.
# MultiDiGraph.edge_subgraph#  
MultiDiGraph.edge_subgraph(edges)#
    
Returns the subgraph induced by the specified edges.
The induced subgraph contains each edge in `edges` and each node incident to any one of those edges.
Parameters:
    
edgesiterable
    
An iterable of edges in this graph.
Returns:
    
GGraph
    
An edge-induced subgraph of this graph with the same edge attributes.
Notes
The graph, edge, and node attributes in the returned subgraph view are references to the corresponding attributes in the original graph. The view is read-only.
To create a full graph version of the subgraph with its own copy of the edge or node attributes, use:
    
    G.edge_subgraph(edges).copy()
    
Examples
    
    >>> G = nx.path_graph(5)
    >>> H = G.edge_subgraph([(0, 1), (3, 4)])
    >>> list(H.nodes)
    [0, 1, 3, 4]
    >>> list(H.edges)
    [(0, 1), (3, 4)]
    
# UnionMultiAdjacency.copy#
UnionMultiAdjacency.copy()#
    
# UnionMultiAdjacency.copy#
UnionMultiAdjacency.copy()#
    
# MultiDiGraph.edge_subgraph#
MultiDiGraph.edge_subgraph(edges)#
    
Returns the subgraph induced by the specified edges.
The induced subgraph contains each edge in `edges` and each node incident to any one of those edges.
Parameters:
    
edgesiterable
    
An iterable of edges in this graph.
Returns:
    
GGraph
    
An edge-induced subgraph of this graph with the same edge attributes.
Notes
The graph, edge, and node attributes in the returned subgraph view are references to the corresponding attributes in the original graph. The view is read-only.
To create a full graph version of the subgraph with its own copy of the edge or node attributes, use:
    
    G.edge_subgraph(edges).copy()
    
Examples
    
    >>> G = nx.path_graph(5)
    >>> H = G.edge_subgraph([(0, 1), (3, 4)])
    >>> list(H.nodes)
    [0, 1, 3, 4]
    >>> list(H.edges)
    [(0, 1), (3, 4)]
    
# MultiDiGraph.edge_subgraph#
MultiDiGraph.edge_subgraph(edges)#
    
Returns the subgraph induced by the specified edges.
The induced subgraph contains each edge in `edges` and each node incident to any one of those edges.
Parameters:
    
edgesiterable
    
An iterable of edges in this graph.
Returns:
    
GGraph
    
An edge-induced subgraph of this graph with the same edge attributes.
Notes
The graph, edge, and node attributes in the returned subgraph view are references to the corresponding attributes in the original graph. The view is read-only.
To create a full graph version of the subgraph with its own copy of the edge or node attributes, use:
    
    G.edge_subgraph(edges).copy()
    
Examples
    
    >>> G = nx.path_graph(5)
    >>> H = G.edge_subgraph([(0, 1), (3, 4)])
    >>> list(H.nodes)
    [0, 1, 3, 4]
    >>> list(H.edges)
    [(0, 1), (3, 4)]
    
# UnionMultiAdjacency.copy#
UnionMultiAdjacency.copy()#
    
# UnionMultiAdjacency.copy#
UnionMultiAdjacency.copy()#
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# read_adjlist#
read_adjlist(path, comments='#', delimiter=None, create_using=None, nodetype=None, encoding='utf-8')[source]#
    
Read graph in adjacency list format from path.
Parameters:
    
pathstring or file
    
Filename or file handle to read. Filenames ending in .gz or .bz2 will be decompressed.
create_usingNetworkX graph constructor, optional (default=nx.Graph)
    
Graph type to create. If graph instance, then cleared before populated.
nodetypePython type, optional
    
Convert nodes to this type.
commentsstring, optional
    
Marker for comment lines
delimiterstring, optional
    
Separator for node labels. The default is whitespace.
Returns:
    
G: NetworkX graph
    
The graph corresponding to the lines in adjacency list format.
See also
`write_adjlist`
    
Notes
This format does not store graph or node data.
Examples
    
    >>> G = nx.path_graph(4)
    >>> nx.write_adjlist(G, "test.adjlist")
    >>> G = nx.read_adjlist("test.adjlist")
    
The path can be a filehandle or a string with the name of the file. If a filehandle is provided, it has to be opened in ‘rb’ mode.
    
    >>> fh = open("test.adjlist", "rb")
    >>> G = nx.read_adjlist(fh)
    
Filenames ending in .gz or .bz2 will be compressed.
    
    >>> nx.write_adjlist(G, "test.adjlist.gz")
    >>> G = nx.read_adjlist("test.adjlist.gz")
    
The optional nodetype is a function to convert node strings to nodetype.
For example
    
    >>> G = nx.read_adjlist("test.adjlist", nodetype=int)
    
will attempt to convert all nodes to integer type.
Since nodes must be hashable, the function nodetype must return hashable types (e.g. int, float, str, frozenset - or tuples of those, etc.)
The optional create_using parameter indicates the type of NetworkX graph created. The default is `nx.Graph`, an undirected graph. To read the data as a directed graph use
    
    >>> G = nx.read_adjlist("test.adjlist", create_using=nx.DiGraph)
    
# argmap.signature#
classmethod argmap.signature(f)[source]#
    
Construct a Signature object describing `f`
Compute a Signature so that we can write a function wrapping f with the same signature and call-type.
Parameters:
    
fcallable
    
A function to be decorated
Returns:
    
sigargmap.Signature
    
The Signature of f
Notes
The Signature is a namedtuple with names:
> name : a unique version of the name of the decorated function signature : the inspect.signature of the decorated function def_sig : a string used as code to define the new function call_sig : a string used as code to call the decorated function names : a dict keyed by argument name and index to the argument’s name n_positional : the number of positional arguments in the signature args : the name of the VAR_POSITIONAL argument if any, i.e. *theseargs kwargs : the name of the VAR_KEYWORDS argument if any, i.e. **kwargs
These named attributes of the signature are used in `assemble` and `compile` to construct a string of source code for the decorated function.
# Graph generators#
## Atlas#
Generators for the small graph atlas.
`graph_atlas`(i)
Returns graph number `i` from the Graph Atlas.  
`graph_atlas_g`()
Returns the list of all graphs with up to seven nodes named in the Graph Atlas.  
## Classic#
Generators for some classic graphs.
The typical graph builder function is called as follows:
    
    >>> G = nx.complete_graph(100)
    
returning the complete graph on n nodes labeled 0, .., 99 as a simple graph. Except for `empty_graph`, all the functions in this module return a Graph class (i.e. a simple, undirected graph).
`balanced_tree`(r, h[, create_using])
Returns the perfectly balanced `r`-ary tree of height `h`.  
`barbell_graph`(m1, m2[, create_using])
Returns the Barbell Graph: two complete graphs connected by a path.  
`binomial_tree`(n[, create_using])
Returns the Binomial Tree of order n.  
`complete_graph`(n[, create_using])
Return the complete graph `K_n` with n nodes.  
`complete_multipartite_graph`(*subset_sizes)
Returns the complete multipartite graph with the specified subset sizes.  
`circular_ladder_graph`(n[, create_using])
Returns the circular ladder graph \\(CL_n\\) of length n.  
`circulant_graph`(n, offsets[, create_using])
Returns the circulant graph \\(Ci_n(x_1, x_2, ..., x_m)\\) with \\(n\\) nodes.  
`cycle_graph`(n[, create_using])
Returns the cycle graph \\(C_n\\) of cyclically connected nodes.  
`dorogovtsev_goltsev_mendes_graph`(n[, ...])
Returns the hierarchically constructed Dorogovtsev--Goltsev--Mendes graph.  
`empty_graph`([n, create_using, default])
Returns the empty graph with n nodes and zero edges.  
`full_rary_tree`(r, n[, create_using])
Creates a full r-ary tree of `n` nodes.  
`kneser_graph`(n, k)
Returns the Kneser Graph with parameters `n` and `k`.  
`ladder_graph`(n[, create_using])
Returns the Ladder graph of length n.  
`lollipop_graph`(m, n[, create_using])
Returns the Lollipop Graph; `K_m` connected to `P_n`.  
`null_graph`([create_using])
Returns the Null graph with no nodes or edges.  
`path_graph`(n[, create_using])
Returns the Path graph `P_n` of linearly connected nodes.  
`star_graph`(n[, create_using])
Return a star graph.  
`tadpole_graph`(m, n[, create_using])
Returns the (m,n)-tadpole graph; `C_m` connected to `P_n`.  
`trivial_graph`([create_using])
Return the Trivial graph with one node (with label 0) and no edges.  
`turan_graph`(n, r)
Return the Turan Graph  
`wheel_graph`(n[, create_using])
Return the wheel graph  
## Expanders#
Provides explicit constructions of expander graphs.
`margulis_gabber_galil_graph`(n[, create_using])
Returns the Margulis-Gabber-Galil undirected MultiGraph on `n^2` nodes.  
`chordal_cycle_graph`(p[, create_using])
Returns the chordal cycle graph on `p` nodes.  
`paley_graph`(p[, create_using])
Returns the Paley \\(\frac{(p-1)}{2}\\) -regular graph on \\(p\\) nodes.  
`maybe_regular_expander`(n, d, *[, ...])  
`is_regular_expander`(G, *[, epsilon])
Determines whether the graph G is a regular expander.  
`random_regular_expander_graph`(n, d, *[, ...])
Returns a random regular expander graph on \\(n\\) nodes with degree \\(d\\).  
## Lattice#
Functions for generating grid graphs and lattices
The `grid_2d_graph()`, `triangular_lattice_graph()`, and `hexagonal_lattice_graph()` functions correspond to the three regular tilings of the plane, the square, triangular, and hexagonal tilings, respectively. `grid_graph()` and `hypercube_graph()` are similar for arbitrary dimensions. Useful relevant discussion can be found about Triangular Tiling, and Square, Hex and Triangle Grids
`grid_2d_graph`(m, n[, periodic, create_using])
Returns the two-dimensional grid graph.  
`grid_graph`(dim[, periodic])
Returns the n-dimensional grid graph.  
`hexagonal_lattice_graph`(m, n[, periodic, ...])
Returns an `m` by `n` hexagonal lattice graph.  
`hypercube_graph`(n)
Returns the n-dimensional hypercube graph.  
`triangular_lattice_graph`(m, n[, periodic, ...])
Returns the \\(m\\) by \\(n\\) triangular lattice graph.  
## Small#
Various small and named graphs, together with some compact generators.
`LCF_graph`(n, shift_list, repeats[, create_using])
Return the cubic graph specified in LCF notation.  
`bull_graph`([create_using])
Returns the Bull Graph  
`chvatal_graph`([create_using])
Returns the Chvátal Graph  
`cubical_graph`([create_using])
Returns the 3-regular Platonic Cubical Graph  
`desargues_graph`([create_using])
Returns the Desargues Graph  
`diamond_graph`([create_using])
Returns the Diamond graph  
`dodecahedral_graph`([create_using])
Returns the Platonic Dodecahedral graph.  
`frucht_graph`([create_using])
Returns the Frucht Graph.  
`heawood_graph`([create_using])
Returns the Heawood Graph, a (3,6) cage.  
`hoffman_singleton_graph`()
Returns the Hoffman-Singleton Graph.  
`house_graph`([create_using])
Returns the House graph (square with triangle on top)  
`house_x_graph`([create_using])
Returns the House graph with a cross inside the house square.  
`icosahedral_graph`([create_using])
Returns the Platonic Icosahedral graph.  
`krackhardt_kite_graph`([create_using])
Returns the Krackhardt Kite Social Network.  
`moebius_kantor_graph`([create_using])
Returns the Moebius-Kantor graph.  
`octahedral_graph`([create_using])
Returns the Platonic Octahedral graph.  
`pappus_graph`()
Returns the Pappus graph.  
`petersen_graph`([create_using])
Returns the Petersen graph.  
`sedgewick_maze_graph`([create_using])
Return a small maze with a cycle.  
`tetrahedral_graph`([create_using])
Returns the 3-regular Platonic Tetrahedral graph.  
`truncated_cube_graph`([create_using])
Returns the skeleton of the truncated cube.  
`truncated_tetrahedron_graph`([create_using])
Returns the skeleton of the truncated Platonic tetrahedron.  
`tutte_graph`([create_using])
Returns the Tutte graph.  
## Random Graphs#
Generators for random graphs.
`fast_gnp_random_graph`(n, p[, seed, ...])
Returns a \\(G_{n,p}\\) random graph, also known as an Erdős-Rényi graph or a binomial graph.  
`gnp_random_graph`(n, p[, seed, directed, ...])
Returns a \\(G_{n,p}\\) random graph, also known as an Erdős-Rényi graph or a binomial graph.  
`dense_gnm_random_graph`(n, m[, seed, ...])
Returns a \\(G_{n,m}\\) random graph.  
`gnm_random_graph`(n, m[, seed, directed, ...])
Returns a \\(G_{n,m}\\) random graph.  
`erdos_renyi_graph`(n, p[, seed, directed, ...])
Returns a \\(G_{n,p}\\) random graph, also known as an Erdős-Rényi graph or a binomial graph.  
`binomial_graph`(n, p[, seed, directed, ...])
Returns a \\(G_{n,p}\\) random graph, also known as an Erdős-Rényi graph or a binomial graph.  
`newman_watts_strogatz_graph`(n, k, p[, seed, ...])
Returns a Newman–Watts–Strogatz small-world graph.  
`watts_strogatz_graph`(n, k, p[, seed, ...])
Returns a Watts–Strogatz small-world graph.  
`connected_watts_strogatz_graph`(n, k, p[, ...])
Returns a connected Watts–Strogatz small-world graph.  
`random_regular_graph`(d, n[, seed, create_using])
Returns a random \\(d\\)-regular graph on \\(n\\) nodes.  
`barabasi_albert_graph`(n, m[, seed, ...])
Returns a random graph using Barabási–Albert preferential attachment  
`dual_barabasi_albert_graph`(n, m1, m2, p[, ...])
Returns a random graph using dual Barabási–Albert preferential attachment  
`extended_barabasi_albert_graph`(n, m, p, q[, ...])
Returns an extended Barabási–Albert model graph.  
`powerlaw_cluster_graph`(n, m, p[, seed, ...])
Holme and Kim algorithm for growing graphs with powerlaw degree distribution and approximate average clustering.  
`random_kernel_graph`(n, kernel_integral[, ...])
Returns an random graph based on the specified kernel.  
`random_lobster`(n, p1, p2[, seed, create_using])  
`random_shell_graph`(constructor[, seed, ...])
Returns a random shell graph for the constructor given.  
`random_powerlaw_tree`(n[, gamma, seed, ...])
Returns a tree with a power law degree distribution.  
`random_powerlaw_tree_sequence`(n[, gamma, ...])
Returns a degree sequence for a tree with a power law distribution.  
`random_kernel_graph`(n, kernel_integral[, ...])
Returns an random graph based on the specified kernel.  
## Duplication Divergence#
Functions for generating graphs based on the “duplication” method.
These graph generators start with a small initial graph then duplicate nodes and (partially) duplicate their edges. These functions are generally inspired by biological networks.
`duplication_divergence_graph`(n, p[, seed, ...])
Returns an undirected graph using the duplication-divergence model.  
`partial_duplication_graph`(N, n, p, q[, ...])
Returns a random graph using the partial duplication model.  
## Degree Sequence#
Generate graphs with a given degree sequence or expected degree sequence.
`configuration_model`(deg_sequence[, ...])
Returns a random graph with the given degree sequence.  
`directed_configuration_model`(...[, ...])
Returns a directed_random graph with the given degree sequences.  
`expected_degree_graph`(w[, seed, selfloops])
Returns a random graph with given expected degrees.  
`havel_hakimi_graph`(deg_sequence[, create_using])
Returns a simple graph with given degree sequence constructed using the Havel-Hakimi algorithm.  
`directed_havel_hakimi_graph`(in_deg_sequence, ...)
Returns a directed graph with the given degree sequences.  
`degree_sequence_tree`(deg_sequence[, ...])
Make a tree for the given degree sequence.  
`random_degree_sequence_graph`(sequence[, ...])
Returns a simple random graph with the given degree sequence.  
## Random Clustered#
Generate graphs with given degree and triangle sequence.
`random_clustered_graph`(joint_degree_sequence)
Generate a random graph with the given joint independent edge degree and triangle degree sequence.  
## Directed#
Generators for some directed graphs, including growing network (GN) graphs and scale-free graphs.
`gn_graph`(n[, kernel, create_using, seed])
Returns the growing network (GN) digraph with `n` nodes.  
`gnr_graph`(n, p[, create_using, seed])
Returns the growing network with redirection (GNR) digraph with `n` nodes and redirection probability `p`.  
`gnc_graph`(n[, create_using, seed])
Returns the growing network with copying (GNC) digraph with `n` nodes.  
`random_k_out_graph`(n, k, alpha[, ...])
Returns a random `k`-out graph with preferential attachment.  
`scale_free_graph`(n[, alpha, beta, gamma, ...])
Returns a scale-free directed graph.  
## Geometric#
Generators for geometric graphs.
`geometric_edges`(G, radius[, p, pos_name])
Returns edge list of node pairs within `radius` of each other.  
`geographical_threshold_graph`(n, theta[, ...])
Returns a geographical threshold graph.  
`navigable_small_world_graph`(n[, p, q, r, ...])
Returns a navigable small-world graph.  
`random_geometric_graph`(n, radius[, dim, ...])
Returns a random geometric graph in the unit cube of dimensions `dim`.  
`soft_random_geometric_graph`(n, radius[, ...])
Returns a soft random geometric graph in the unit cube.  
`thresholded_random_geometric_graph`(n, ...[, ...])
Returns a thresholded random geometric graph in the unit cube.  
`waxman_graph`(n[, beta, alpha, L, domain, ...])
Returns a Waxman random graph.  
`geometric_soft_configuration_graph`(*, beta)
Returns a random graph from the geometric soft configuration model.  
## Line Graph#
Functions for generating line graphs.
`line_graph`(G[, create_using])
Returns the line graph of the graph or digraph `G`.  
`inverse_line_graph`(G)
Returns the inverse line graph of graph G.  
## Ego Graph#
Ego graph.
`ego_graph`(G, n[, radius, center, ...])
Returns induced subgraph of neighbors centered at node n within a given radius.  
## Stochastic#
Functions for generating stochastic graphs from a given weighted directed graph.
`stochastic_graph`(G[, copy, weight])
Returns a right-stochastic representation of directed graph `G`.  
## AS graph#
Generates graphs resembling the Internet Autonomous System network
`random_internet_as_graph`(n[, seed])
Generates a random undirected graph resembling the Internet AS network  
## Intersection#
Generators for random intersection graphs.
`uniform_random_intersection_graph`(n, m, p[, ...])
Returns a uniform random intersection graph.  
`k_random_intersection_graph`(n, m, k[, seed])
Returns a intersection graph with randomly chosen attribute sets for each node that are of equal size (k).  
`general_random_intersection_graph`(n, m, p[, ...])
Returns a random intersection graph with independent probabilities for connections between node and attribute sets.  
## Social Networks#
Famous social networks.
`karate_club_graph`()
Returns Zachary's Karate Club graph.  
`davis_southern_women_graph`()
Returns Davis Southern women social network.  
`florentine_families_graph`()
Returns Florentine families graph.  
`les_miserables_graph`()
Returns coappearance network of characters in the novel Les Miserables.  
## Community#
Generators for classes of graphs used in studying social networks.
`caveman_graph`(l, k)
Returns a caveman graph of `l` cliques of size `k`.  
`connected_caveman_graph`(l, k)
Returns a connected caveman graph of `l` cliques of size `k`.  
`gaussian_random_partition_graph`(n, s, v, ...)
Generate a Gaussian random partition graph.  
`LFR_benchmark_graph`(n, tau1, tau2, mu[, ...])
Returns the LFR benchmark graph.  
`planted_partition_graph`(l, k, p_in, p_out[, ...])
Returns the planted l-partition graph.  
`random_partition_graph`(sizes, p_in, p_out[, ...])
Returns the random partition graph with a partition of sizes.  
`relaxed_caveman_graph`(l, k, p[, seed])
Returns a relaxed caveman graph.  
`ring_of_cliques`(num_cliques, clique_size)
Defines a "ring of cliques" graph.  
`stochastic_block_model`(sizes, p[, nodelist, ...])
Returns a stochastic block model graph.  
`windmill_graph`(n, k)
Generate a windmill graph.  
## Spectral#
Generates graphs with a given eigenvector structure
`spectral_graph_forge`(G, alpha[, ...])
Returns a random simple graph with spectrum resembling that of `G`  
## Trees#
Functions for generating trees.
The functions sampling trees at random in this module come in two variants: labeled and unlabeled. The labeled variants sample from every possible tree with the given number of nodes uniformly at random. The unlabeled variants sample from every possible isomorphism class of trees with the given number of nodes uniformly at random.
To understand the difference, consider the following example. There are two isomorphism classes of trees with four nodes. One is that of the path graph, the other is that of the star graph. The unlabeled variant will return a line graph or a star graph with probability 1/2.
The labeled variant will return the line graph with probability 3/4 and the star graph with probability 1/4, because there are more labeled variants of the line graph than of the star graph. More precisely, the line graph has an automorphism group of order 2, whereas the star graph has an automorphism group of order 6, so the line graph has three times as many labeled variants as the star graph, and thus three more chances to be drawn.
Additionally, some functions in this module can sample rooted trees and forests uniformly at random. A rooted tree is a tree with a designated root node. A rooted forest is a disjoint union of rooted trees.
`prefix_tree`(paths)
Creates a directed prefix tree from a list of paths.  
`random_labeled_tree`(n, *[, seed])
Returns a labeled tree on `n` nodes chosen uniformly at random.  
`random_labeled_rooted_tree`(n, *[, seed])
Returns a labeled rooted tree with `n` nodes.  
`random_labeled_rooted_forest`(n, *[, seed])
Returns a labeled rooted forest with `n` nodes.  
`random_unlabeled_tree`(n, *[, ...])
Returns a tree or list of trees chosen randomly.  
`random_unlabeled_rooted_tree`(n, *[, ...])
Returns a number of unlabeled rooted trees uniformly at random  
`random_unlabeled_rooted_forest`(n, *[, q, ...])
Returns a forest or list of forests selected at random.  
## Non Isomorphic Trees#
Implementation of the Wright, Richmond, Odlyzko and McKay (WROM) algorithm for the enumeration of all non-isomorphic free trees of a given order. Rooted trees are represented by level sequences, i.e., lists in which the i-th element specifies the distance of vertex i to the root.
`nonisomorphic_trees`(order)
Generate nonisomorphic trees of specified `order`.  
`number_of_nonisomorphic_trees`(order)
Returns the number of nonisomorphic trees of the specified `order`.  
## Triads#
Functions that generate the triad graphs, that is, the possible digraphs on three nodes.
`triad_graph`(triad_name)
Returns the triad graph with the given name.  
## Joint Degree Sequence#
Generate graphs with a given joint degree and directed joint degree
`is_valid_joint_degree`(joint_degrees)
Checks whether the given joint degree dictionary is realizable.  
`joint_degree_graph`(joint_degrees[, seed])
Generates a random simple graph with the given joint degree dictionary.  
`is_valid_directed_joint_degree`(in_degrees, ...)
Checks whether the given directed joint degree input is realizable  
`directed_joint_degree_graph`(in_degrees, ...)
Generates a random simple directed graph with the joint degree.  
## Mycielski#
Functions related to the Mycielski Operation and the Mycielskian family of graphs.
`mycielskian`(G[, iterations])
Returns the Mycielskian of a simple, undirected graph G  
`mycielski_graph`(n)
Generator for the n_th Mycielski Graph.  
## Harary Graph#
Generators for Harary graphs
This module gives two generators for the Harary graph, which was introduced by the famous mathematician Frank Harary in his 1962 work [H]. The first generator gives the Harary graph that maximizes the node connectivity with given number of nodes and given number of edges. The second generator gives the Harary graph that minimizes the number of edges in the graph with given node connectivity and number of nodes.
### References#
[H]
Harary, F. “The Maximum Connectivity of a Graph.” Proc. Nat. Acad. Sci. USA 48, 1142-1146, 1962.
`hnm_harary_graph`(n, m[, create_using])
Returns the Harary graph with given numbers of nodes and edges.  
`hkn_harary_graph`(k, n[, create_using])
Returns the Harary graph with given node connectivity and node number.  
## Cographs#
Generators for cographs
A cograph is a graph containing no path on four vertices. Cographs or \\(P_4\\)-free graphs can be obtained from a single vertex by disjoint union and complementation operations.
### References#
[0]
D.G. Corneil, H. Lerchs, L.Stewart Burlingham, “Complement reducible graphs”, Discrete Applied Mathematics, Volume 3, Issue 3, 1981, Pages 163-174, ISSN 0166-218X.
`random_cograph`(n[, seed])
Returns a random cograph with \\(2 ^ n\\) nodes.  
## Interval Graph#
Generators for interval graph.
`interval_graph`(intervals)
Generates an interval graph for a list of intervals given.  
## Sudoku#
Generator for Sudoku graphs
This module gives a generator for n-Sudoku graphs. It can be used to develop algorithms for solving or generating Sudoku puzzles.
A completed Sudoku grid is a 9x9 array of integers between 1 and 9, with no number appearing twice in the same row, column, or 3x3 box.
8 6 4
3 2 5
9 7 1
3 7 1
8 4 9
2 6 5
2 5 9
7 6 1
8 4 3  
4 3 6
1 9 8
2 5 7
1 9 2
6 5 7
4 8 3
5 8 7
4 3 2
9 1 6  
6 8 9
7 1 3
5 4 2
7 3 4
5 2 8
9 1 6
1 2 5
6 9 4
3 7 8  
The Sudoku graph is an undirected graph with 81 vertices, corresponding to the cells of a Sudoku grid. It is a regular graph of degree 20. Two distinct vertices are adjacent if and only if the corresponding cells belong to the same row, column, or box. A completed Sudoku grid corresponds to a vertex coloring of the Sudoku graph with nine colors.
More generally, the n-Sudoku graph is a graph with n^4 vertices, corresponding to the cells of an n^2 by n^2 grid. Two distinct vertices are adjacent if and only if they belong to the same row, column, or n by n box.
### References#
[1]
Herzberg, A. M., & Murty, M. R. (2007). Sudoku squares and chromatic polynomials. Notices of the AMS, 54(6), 708-717.
[2]
Sander, Torsten (2009), “Sudoku graphs are integral”, Electronic Journal of Combinatorics, 16 (1): Note 25, 7pp, MR 2529816
[3]
Wikipedia contributors. “Glossary of Sudoku.” Wikipedia, The Free Encyclopedia, 3 Dec. 2019. Web. 22 Dec. 2019.
`sudoku_graph`([n])
Returns the n-Sudoku graph.  
## Time Series#
Time Series Graphs
`visibility_graph`(series)
Return a Visibility Graph of an input Time Series.
Note  
Go to the end to download the full example code.
# Atlas#
Atlas of all connected graphs with up to 6 nodes.
This example uses Graphviz via PyGraphviz.
The image should show 142 graphs. We don’t plot the empty graph nor the single node graph. (142 is the sum of values 2 to n=6 in sequence oeis.org/A001349).
    
    import random
    
    import matplotlib.pyplot as plt
    import networkx as nx
    
    
    GraphMatcher = nx.isomorphism.vf2userfunc.GraphMatcher
    
    
    def atlas6():
        """Return the atlas of all connected graphs with at most 6 nodes"""
    
        Atlas = nx.graph_atlas_g()[3:209]  # 0, 1, 2 => no edges. 208 is last 6 node graph
        U = nx.Graph()  # graph for union of all graphs in atlas
        for G in Atlas:
            # check if connected
            if nx.number_connected_components(G) == 1:
                # check if isomorphic to a previous graph
                if not GraphMatcher(U, G).subgraph_is_isomorphic():
                    U = nx.disjoint_union(U, G)
        return U
    
    
    G = atlas6()
    
    print(G)
    print(nx.number_connected_components(G), "connected components")
    
    plt.figure(1, figsize=(8, 8))
    # layout graphs with positions using graphviz neato
    pos = nx.nx_agraph.graphviz_layout(G, prog="neato")
    # color nodes the same in each connected subgraph
    C = (G.subgraph(c) for c in nx.connected_components(G))
    for g in C:
        c = [random.random()] * nx.number_of_nodes(g)  # random color...
        nx.draw(g, pos, node_size=40, node_color=c, vmin=0.0, vmax=1.0, with_labels=False)
    plt.show()
    
`Download Jupyter notebook: plot_atlas.ipynb`
`Download Python source code: plot_atlas.py`
`Download zipped: plot_atlas.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# Atlas#
Atlas of all connected graphs with up to 6 nodes.
This example uses Graphviz via PyGraphviz.
The image should show 142 graphs. We don’t plot the empty graph nor the single node graph. (142 is the sum of values 2 to n=6 in sequence oeis.org/A001349).
    
    import random
    
    import matplotlib.pyplot as plt
    import networkx as nx
    
    
    GraphMatcher = nx.isomorphism.vf2userfunc.GraphMatcher
    
    
    def atlas6():
        """Return the atlas of all connected graphs with at most 6 nodes"""
    
        Atlas = nx.graph_atlas_g()[3:209]  # 0, 1, 2 => no edges. 208 is last 6 node graph
        U = nx.Graph()  # graph for union of all graphs in atlas
        for G in Atlas:
            # check if connected
            if nx.number_connected_components(G) == 1:
                # check if isomorphic to a previous graph
                if not GraphMatcher(U, G).subgraph_is_isomorphic():
                    U = nx.disjoint_union(U, G)
        return U
    
    
    G = atlas6()
    
    print(G)
    print(nx.number_connected_components(G), "connected components")
    
    plt.figure(1, figsize=(8, 8))
    # layout graphs with positions using graphviz neato
    pos = nx.nx_agraph.graphviz_layout(G, prog="neato")
    # color nodes the same in each connected subgraph
    C = (G.subgraph(c) for c in nx.connected_components(G))
    for g in C:
        c = [random.random()] * nx.number_of_nodes(g)  # random color...
        nx.draw(g, pos, node_size=40, node_color=c, vmin=0.0, vmax=1.0, with_labels=False)
    plt.show()
    
`Download Jupyter notebook: plot_atlas.ipynb`
`Download Python source code: plot_atlas.py`
`Download zipped: plot_atlas.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# House With Colors#
Draw a graph with matplotlib.
    
    import matplotlib.pyplot as plt
    import networkx as nx
    
    G = nx.house_graph()
    # explicitly set positions
    pos = {0: (0, 0), 1: (1, 0), 2: (0, 1), 3: (1, 1), 4: (0.5, 2.0)}
    
    # Plot nodes with different properties for the "wall" and "roof" nodes
    nx.draw_networkx_nodes(
        G, pos, node_size=3000, nodelist=[0, 1, 2, 3], node_color="tab:blue"
    )
    nx.draw_networkx_nodes(G, pos, node_size=2000, nodelist=[4], node_color="tab:orange")
    nx.draw_networkx_edges(G, pos, alpha=0.5, width=6)
    # Customize axes
    ax = plt.gca()
    ax.margins(0.11)
    plt.tight_layout()
    plt.axis("off")
    plt.show()
    
Total running time of the script: (0 minutes 0.014 seconds)
`Download Jupyter notebook: plot_house_with_colors.ipynb`
`Download Python source code: plot_house_with_colors.py`
`Download zipped: plot_house_with_colors.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# Atlas#
An example showing how to write first 20 graphs from the graph atlas as graphviz dot files Gn.dot where n=0,19.
TODO: does nx_agraph.draw support multiple graphs in one png?
    
    import networkx as nx
    
    atlas = nx.graph_atlas_g()[0:20]
    
    for G in atlas:
        print(G)
        A = nx.nx_agraph.to_agraph(G)
        A.graph_attr["label"] = G.name
        # set default node attributes
        A.node_attr["color"] = "red"
        A.node_attr["style"] = "filled"
        A.node_attr["shape"] = "circle"
        A.write(G.name + ".dot")
    
    # Draw the 20th graph from the atlas to png
    A.draw("A20.png", prog="neato")
    
`Download Jupyter notebook: plot_mini_atlas.ipynb`
`Download Python source code: plot_mini_atlas.py`
`Download zipped: plot_mini_atlas.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# JavaScript#
Example of writing JSON format graph data and using the D3 JavaScript library to produce an HTML/JavaScript drawing.
You will need to download the following directory:
  * networkx/networkx


    
    import json
    
    import flask
    import networkx as nx
    
    G = nx.barbell_graph(6, 3)
    # this d3 example uses the name attribute for the mouse-hover value,
    # so add a name to each node
    for n in G:
        G.nodes[n]["name"] = n
    # write json formatted data
    d = nx.json_graph.node_link_data(G)  # node-link format to serialize
    # write json
    json.dump(d, open("force/force.json", "w"))
    print("Wrote node-link JSON data to force/force.json")
    
    # Serve the file over http to allow for cross origin requests
    app = flask.Flask(__name__, static_folder="force")
    
    
    @app.route("/")
    def static_proxy():
        return app.send_static_file("force.html")
    
    
    print("\nGo to http://localhost:8000 to see the example\n")
    app.run(port=8000)
    
`Download Jupyter notebook: javascript_force.ipynb`
`Download Python source code: javascript_force.py`
`Download zipped: javascript_force.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# Properties#
Compute some network properties for the lollipop graph.
    
    source vertex {target:length, }
    0 {0: 0, 1: 1, 2: 1, 3: 1, 4: 2, 5: 3, 6: 4, 7: 5, 8: 6, 9: 7}
    1 {1: 0, 0: 1, 2: 1, 3: 1, 4: 2, 5: 3, 6: 4, 7: 5, 8: 6, 9: 7}
    2 {2: 0, 0: 1, 1: 1, 3: 1, 4: 2, 5: 3, 6: 4, 7: 5, 8: 6, 9: 7}
    3 {3: 0, 0: 1, 1: 1, 2: 1, 4: 1, 5: 2, 6: 3, 7: 4, 8: 5, 9: 6}
    4 {4: 0, 5: 1, 3: 1, 6: 2, 0: 2, 1: 2, 2: 2, 7: 3, 8: 4, 9: 5}
    5 {5: 0, 4: 1, 6: 1, 3: 2, 7: 2, 0: 3, 1: 3, 2: 3, 8: 3, 9: 4}
    6 {6: 0, 5: 1, 7: 1, 4: 2, 8: 2, 3: 3, 9: 3, 0: 4, 1: 4, 2: 4}
    7 {7: 0, 6: 1, 8: 1, 5: 2, 9: 2, 4: 3, 3: 4, 0: 5, 1: 5, 2: 5}
    8 {8: 0, 7: 1, 9: 1, 6: 2, 5: 3, 4: 4, 3: 5, 0: 6, 1: 6, 2: 6}
    9 {9: 0, 8: 1, 7: 2, 6: 3, 5: 4, 4: 5, 3: 6, 0: 7, 1: 7, 2: 7}
    
    average shortest path length 2.86
    
    length #paths
    0 10
    1 24
    2 16
    3 14
    4 12
    5 10
    6 8
    7 6
    radius: 4
    diameter: 7
    eccentricity: {0: 7, 1: 7, 2: 7, 3: 6, 4: 5, 5: 4, 6: 4, 7: 5, 8: 6, 9: 7}
    center: [5, 6]
    periphery: [0, 1, 2, 9]
    density: 0.26666666666666666
    
  

    
    import matplotlib.pyplot as plt
    import networkx as nx
    
    G = nx.lollipop_graph(4, 6)
    
    pathlengths = []
    
    print("source vertex {target:length, }")
    for v in G.nodes():
        spl = nx.single_source_shortest_path_length(G, v)
        print(f"{v} {spl} ")
        for p in spl:
            pathlengths.append(spl[p])
    
    print()
    print(f"average shortest path length {sum(pathlengths) / len(pathlengths)}")
    
    # histogram of path lengths
    dist = {}
    for p in pathlengths:
        if p in dist:
            dist[p] += 1
        else:
            dist[p] = 1
    
    print()
    print("length #paths")
    verts = dist.keys()
    for d in sorted(verts):
        print(f"{d} {dist[d]}")
    
    print(f"radius: {nx.radius(G)}")
    print(f"diameter: {nx.diameter(G)}")
    print(f"eccentricity: {nx.eccentricity(G)}")
    print(f"center: {nx.center(G)}")
    print(f"periphery: {nx.periphery(G)}")
    print(f"density: {nx.density(G)}")
    
    pos = nx.spring_layout(G, seed=3068)  # Seed layout for reproducibility
    nx.draw(G, pos=pos, with_labels=True)
    plt.show()
    
Total running time of the script: (0 minutes 0.968 seconds)
`Download Jupyter notebook: plot_properties.ipynb`
`Download Python source code: plot_properties.py`
`Download zipped: plot_properties.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# Words/Ladder Graph#
Generate an undirected graph over the 5757 5-letter words in the datafile `words_dat.txt.gz`. Two words are connected by an edge if they differ in one letter, resulting in 14,135 edges. This example is described in Section 1.1 of
> Donald E. Knuth, “The Stanford GraphBase: A Platform for Combinatorial Computing”, ACM Press, New York, 1993. http://www-cs-faculty.stanford.edu/~knuth/sgb.html
The data file can be found at:
  * networkx/networkx


    
    Loaded words_dat.txt containing 5757 five-letter English words.
    Two words are connected if they differ in one letter.
    Graph named 'words' with 5757 nodes and 14135 edges
    853 connected components
    Shortest path between chaos and order is
    chaos
    choos
    shoos
    shoes
    shoed
    shred
    sired
    sided
    aided
    added
    adder
    odder
    order
    Shortest path between nodes and graph is
    nodes
    lodes
    lores
    lords
    loads
    goads
    grads
    grade
    grape
    graph
    Shortest path between pound and marks is
    None
    
  

    
    import gzip
    from string import ascii_lowercase as lowercase
    
    import matplotlib.pyplot as plt
    import networkx as nx
    
    
    def generate_graph(words):
        G = nx.Graph(name="words")
        lookup = {c: lowercase.index(c) for c in lowercase}
    
        def edit_distance_one(word):
            for i in range(len(word)):
                left, c, right = word[0:i], word[i], word[i + 1 :]
                j = lookup[c]  # lowercase.index(c)
                for cc in lowercase[j + 1 :]:
                    yield left + cc + right
    
        candgen = (
            (word, cand)
            for word in sorted(words)
            for cand in edit_distance_one(word)
            if cand in words
        )
        G.add_nodes_from(words)
        for word, cand in candgen:
            G.add_edge(word, cand)
        return G
    
    
    def words_graph():
        """Return the words example graph from the Stanford GraphBase"""
        fh = gzip.open("words_dat.txt.gz", "r")
        words = set()
        for line in fh.readlines():
            line = line.decode()
            if line.startswith("*"):
                continue
            w = str(line[0:5])
            words.add(w)
        return generate_graph(words)
    
    
    G = words_graph()
    print("Loaded words_dat.txt containing 5757 five-letter English words.")
    print("Two words are connected if they differ in one letter.")
    print(G)
    print(f"{nx.number_connected_components(G)} connected components")
    
    for source, target in [("chaos", "order"), ("nodes", "graph"), ("pound", "marks")]:
        print(f"Shortest path between {source} and {target} is")
        try:
            shortest_path = nx.shortest_path(G, source, target)
            for n in shortest_path:
                print(n)
        except nx.NetworkXNoPath:
            print("None")
    
    
    # draw a subset of the graph
    boundary = list(nx.node_boundary(G, shortest_path))
    G.add_nodes_from(shortest_path, color="red")
    G.add_nodes_from(boundary, color="blue")
    H = G.subgraph(shortest_path + boundary)
    colors = nx.get_node_attributes(H, "color")
    options = {"node_size": 1500, "alpha": 0.3, "node_color": colors.values()}
    pos = nx.kamada_kawai_layout(H)
    nx.draw(H, pos, **options)
    nx.draw_networkx_labels(H, pos, font_weight="bold")
    plt.show()
    
Total running time of the script: (0 minutes 0.083 seconds)
`Download Jupyter notebook: plot_words.ipynb`
`Download Python source code: plot_words.py`
`Download zipped: plot_words.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# Properties#
Compute some network properties for the lollipop graph.
    
    source vertex {target:length, }
    0 {0: 0, 1: 1, 2: 1, 3: 1, 4: 2, 5: 3, 6: 4, 7: 5, 8: 6, 9: 7}
    1 {1: 0, 0: 1, 2: 1, 3: 1, 4: 2, 5: 3, 6: 4, 7: 5, 8: 6, 9: 7}
    2 {2: 0, 0: 1, 1: 1, 3: 1, 4: 2, 5: 3, 6: 4, 7: 5, 8: 6, 9: 7}
    3 {3: 0, 0: 1, 1: 1, 2: 1, 4: 1, 5: 2, 6: 3, 7: 4, 8: 5, 9: 6}
    4 {4: 0, 5: 1, 3: 1, 6: 2, 0: 2, 1: 2, 2: 2, 7: 3, 8: 4, 9: 5}
    5 {5: 0, 4: 1, 6: 1, 3: 2, 7: 2, 0: 3, 1: 3, 2: 3, 8: 3, 9: 4}
    6 {6: 0, 5: 1, 7: 1, 4: 2, 8: 2, 3: 3, 9: 3, 0: 4, 1: 4, 2: 4}
    7 {7: 0, 6: 1, 8: 1, 5: 2, 9: 2, 4: 3, 3: 4, 0: 5, 1: 5, 2: 5}
    8 {8: 0, 7: 1, 9: 1, 6: 2, 5: 3, 4: 4, 3: 5, 0: 6, 1: 6, 2: 6}
    9 {9: 0, 8: 1, 7: 2, 6: 3, 5: 4, 4: 5, 3: 6, 0: 7, 1: 7, 2: 7}
    
    average shortest path length 2.86
    
    length #paths
    0 10
    1 24
    2 16
    3 14
    4 12
    5 10
    6 8
    7 6
    radius: 4
    diameter: 7
    eccentricity: {0: 7, 1: 7, 2: 7, 3: 6, 4: 5, 5: 4, 6: 4, 7: 5, 8: 6, 9: 7}
    center: [5, 6]
    periphery: [0, 1, 2, 9]
    density: 0.26666666666666666
    
  

    
    import matplotlib.pyplot as plt
    import networkx as nx
    
    G = nx.lollipop_graph(4, 6)
    
    pathlengths = []
    
    print("source vertex {target:length, }")
    for v in G.nodes():
        spl = nx.single_source_shortest_path_length(G, v)
        print(f"{v} {spl} ")
        for p in spl:
            pathlengths.append(spl[p])
    
    print()
    print(f"average shortest path length {sum(pathlengths) / len(pathlengths)}")
    
    # histogram of path lengths
    dist = {}
    for p in pathlengths:
        if p in dist:
            dist[p] += 1
        else:
            dist[p] = 1
    
    print()
    print("length #paths")
    verts = dist.keys()
    for d in sorted(verts):
        print(f"{d} {dist[d]}")
    
    print(f"radius: {nx.radius(G)}")
    print(f"diameter: {nx.diameter(G)}")
    print(f"eccentricity: {nx.eccentricity(G)}")
    print(f"center: {nx.center(G)}")
    print(f"periphery: {nx.periphery(G)}")
    print(f"density: {nx.density(G)}")
    
    pos = nx.spring_layout(G, seed=3068)  # Seed layout for reproducibility
    nx.draw(G, pos=pos, with_labels=True)
    plt.show()
    
Total running time of the script: (0 minutes 0.968 seconds)
`Download Jupyter notebook: plot_properties.ipynb`
`Download Python source code: plot_properties.py`
`Download zipped: plot_properties.zip`
Gallery generated by Sphinx-Gallery
# Gallery#
General-purpose and introductory examples for NetworkX. The tutorial introduces conventions and basic graph manipulations.
## Basic#
Properties
Properties
Read and write graphs.
Read and write graphs.
Simple graph
Simple graph
## Drawing#
Custom Node Position
Custom Node Position
Chess Masters
Chess Masters
Cluster Layout
Cluster Layout
Custom node icons
Custom node icons
Degree Analysis
Degree Analysis
Directed Graph
Directed Graph
Edge Colormap
Edge Colormap
Ego Graph
Ego Graph
Eigenvalues
Eigenvalues
Four Grids
Four Grids
House With Colors
House With Colors
Knuth Miles
Knuth Miles
Labels And Colors
Labels And Colors
Plotting MultiDiGraph Edges and Labels
Plotting MultiDiGraph Edges and Labels
Multipartite Layout
Multipartite Layout
Node Colormap
Node Colormap
Rainbow Coloring
Rainbow Coloring
Random Geometric Graph
Random Geometric Graph
Sampson
Sampson
Self-loops
Self-loops
Simple Path
Simple Path
Spectral Embedding
Spectral Embedding
Spring Layout
Spring Layout
Traveling Salesman Problem
Traveling Salesman Problem
Unix Email
Unix Email
Weighted Graph
Weighted Graph
## 3D Drawing#
Mayavi2
Mayavi2
Basic Animation
Basic Animation
Animation: Node Walk
Animation: Node Walk
Basic matplotlib
Basic matplotlib
3D Facebook Network
3D Facebook Network
## Graphviz Layout#
Examples using Graphviz layouts with `nx_pylab` for drawing. These examples need Graphviz and PyGraphviz.
Atlas
Atlas
Circular Tree
Circular Tree
Decomposition
Decomposition
Giant Component
Giant Component
Lanl Routes
Lanl Routes
## Graphviz Drawing#
Examples using Graphviz for layout and drawing via `nx_agraph`. These examples need Graphviz and PyGraphviz.
Attributes
Attributes
Conversion
Conversion
2D Grid
2D Grid
Atlas
Atlas
## Graph#
DAG - Topological Layout
DAG - Topological Layout
Degree Sequence
Degree Sequence
Erdos Renyi
Erdos Renyi
Expected Degree Sequence
Expected Degree Sequence
Football
Football
Karate Club
Karate Club
Morse Trie
Morse Trie
Minimum Spanning Tree
Minimum Spanning Tree
Napoleon Russian Campaign
Napoleon Russian Campaign
Roget
Roget
Triads
Triads
Visibility Graph
Visibility Graph
Words/Ladder Graph
Words/Ladder Graph
## Algorithms#
Beam Search
Beam Search
Betweenness Centrality
Betweenness Centrality
Bipartite Motifs: α/β-core
Bipartite Motifs: α/β-core
Blockmodel
Blockmodel
Circuits
Circuits
Cycle Detection
Cycle Detection
Davis Club
Davis Club
Dedensification
Dedensification
Community Detection using Girvan-Newman
Community Detection using Girvan-Newman
Greedy Coloring
Greedy Coloring
Image Segmentation via Spectral Graph Partitioning
Image Segmentation via Spectral Graph Partitioning
Iterated Dynamical Systems
Iterated Dynamical Systems
Krackhardt Centrality
Krackhardt Centrality
Lowest Common Ancestors
Lowest Common Ancestors
Maximum Independent Set
Maximum Independent Set
Parallel Betweenness
Parallel Betweenness
Reverse Cuthill–McKee
Reverse Cuthill--McKee
Find Shortest Path
Find Shortest Path
SNAP Graph Summary
SNAP Graph Summary
Subgraphs
Subgraphs
TrustRank
TrustRank
## External libraries#
Examples of using NetworkX with external libraries.
JavaScript
JavaScript
igraph
igraph
## Geospatial#
The following geospatial examples showcase different ways of performing network analyses using packages within the geospatial Python ecosystem. Example spatial files are stored directly in this directory. See the extended description for more details.
Delaunay graphs from geographic points
Delaunay graphs from geographic points
Graphs from a set of lines
Graphs from a set of lines
OpenStreetMap with OSMnx
OpenStreetMap with OSMnx
Graphs from geographic points
Graphs from geographic points
Graphs from Polygons
Graphs from Polygons
## Subclass#
Antigraph
Antigraph
Print Graph
Print Graph
`Download all examples in Python source code: auto_examples_python.zip`
`Download all examples in Jupyter notebooks: auto_examples_jupyter.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# Words/Ladder Graph#
Generate an undirected graph over the 5757 5-letter words in the datafile `words_dat.txt.gz`. Two words are connected by an edge if they differ in one letter, resulting in 14,135 edges. This example is described in Section 1.1 of
> Donald E. Knuth, “The Stanford GraphBase: A Platform for Combinatorial Computing”, ACM Press, New York, 1993. http://www-cs-faculty.stanford.edu/~knuth/sgb.html
The data file can be found at:
  * networkx/networkx


    
    Loaded words_dat.txt containing 5757 five-letter English words.
    Two words are connected if they differ in one letter.
    Graph named 'words' with 5757 nodes and 14135 edges
    853 connected components
    Shortest path between chaos and order is
    chaos
    choos
    shoos
    shoes
    shoed
    shred
    sired
    sided
    aided
    added
    adder
    odder
    order
    Shortest path between nodes and graph is
    nodes
    lodes
    lores
    lords
    loads
    goads
    grads
    grade
    grape
    graph
    Shortest path between pound and marks is
    None
    
  

    
    import gzip
    from string import ascii_lowercase as lowercase
    
    import matplotlib.pyplot as plt
    import networkx as nx
    
    
    def generate_graph(words):
        G = nx.Graph(name="words")
        lookup = {c: lowercase.index(c) for c in lowercase}
    
        def edit_distance_one(word):
            for i in range(len(word)):
                left, c, right = word[0:i], word[i], word[i + 1 :]
                j = lookup[c]  # lowercase.index(c)
                for cc in lowercase[j + 1 :]:
                    yield left + cc + right
    
        candgen = (
            (word, cand)
            for word in sorted(words)
            for cand in edit_distance_one(word)
            if cand in words
        )
        G.add_nodes_from(words)
        for word, cand in candgen:
            G.add_edge(word, cand)
        return G
    
    
    def words_graph():
        """Return the words example graph from the Stanford GraphBase"""
        fh = gzip.open("words_dat.txt.gz", "r")
        words = set()
        for line in fh.readlines():
            line = line.decode()
            if line.startswith("*"):
                continue
            w = str(line[0:5])
            words.add(w)
        return generate_graph(words)
    
    
    G = words_graph()
    print("Loaded words_dat.txt containing 5757 five-letter English words.")
    print("Two words are connected if they differ in one letter.")
    print(G)
    print(f"{nx.number_connected_components(G)} connected components")
    
    for source, target in [("chaos", "order"), ("nodes", "graph"), ("pound", "marks")]:
        print(f"Shortest path between {source} and {target} is")
        try:
            shortest_path = nx.shortest_path(G, source, target)
            for n in shortest_path:
                print(n)
        except nx.NetworkXNoPath:
            print("None")
    
    
    # draw a subset of the graph
    boundary = list(nx.node_boundary(G, shortest_path))
    G.add_nodes_from(shortest_path, color="red")
    G.add_nodes_from(boundary, color="blue")
    H = G.subgraph(shortest_path + boundary)
    colors = nx.get_node_attributes(H, "color")
    options = {"node_size": 1500, "alpha": 0.3, "node_color": colors.values()}
    pos = nx.kamada_kawai_layout(H)
    nx.draw(H, pos, **options)
    nx.draw_networkx_labels(H, pos, font_weight="bold")
    plt.show()
    
Total running time of the script: (0 minutes 0.083 seconds)
`Download Jupyter notebook: plot_words.ipynb`
`Download Python source code: plot_words.py`
`Download zipped: plot_words.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
Note
Go to the end to download the full example code.
# OpenStreetMap with OSMnx#
This example shows how to use OSMnx to download and model a street network from OpenStreetMap, visualize centrality, then save the graph as a GeoPackage, or GraphML file.
OSMnx is a Python package to download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap. You can download and model walking, driving, or biking networks with a single line of code then easily analyze and visualize them. You can just as easily work with urban amenities/points of interest, building footprints, transit stops, elevation data, street orientations, speed/travel time, and routing.
See https://osmnx.readthedocs.io for the OSMnx documentation. See gboeing/osmnx-examples for the OSMnx Examples gallery.
    
    import networkx as nx
    import osmnx as ox
    
    ox.settings.use_cache = True
    
    # download street network data from OSM and construct a MultiDiGraph model
    G = ox.graph.graph_from_point((37.79, -122.41), dist=750, network_type="drive")
    
    # impute edge (driving) speeds and calculate edge travel times
    G = ox.routing.add_edge_speeds(G)
    G = ox.routing.add_edge_travel_times(G)
    
    # you can convert MultiDiGraph to/from GeoPandas GeoDataFrames
    gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)
    G = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)
    
    # convert MultiDiGraph to DiGraph to use nx.betweenness_centrality function
    # choose between parallel edges by minimizing travel_time attribute value
    D = ox.convert.to_digraph(G, weight="travel_time")
    
    # calculate node betweenness centrality, weighted by travel time
    bc = nx.betweenness_centrality(D, weight="travel_time", normalized=True)
    nx.set_node_attributes(G, values=bc, name="bc")
    
    # plot the graph, coloring nodes by betweenness centrality
    nc = ox.plot.get_node_colors_by_attr(G, "bc", cmap="plasma")
    fig, ax = ox.plot.plot_graph(
        G, bgcolor="k", node_color=nc, node_size=50, edge_linewidth=2, edge_color="#333333"
    )
    
    # save graph as a geopackage or graphml file
    ox.io.save_graph_geopackage(G, filepath="./graph.gpkg")
    ox.io.save_graphml(G, filepath="./graph.graphml")
    
`Download Jupyter notebook: plot_osmnx.ipynb`
`Download Python source code: plot_osmnx.py`
`Download zipped: plot_osmnx.zip`
Gallery generated by Sphinx-Gallery
