osmnx | street networks . | Map library

 by   gboeing Python Version: 1.8.0 License: MIT

kandi X-RAY | osmnx Summary

kandi X-RAY | osmnx Summary

osmnx is a Python library typically used in Geo, Map applications. osmnx has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can install using 'pip install osmnx' or download it from GitHub, PyPI.

OSMnx is a Python package that lets you download geospatial data from OpenStreetMap and model, project, visualize, and analyze real-world street networks and any other geospatial geometries. You can download and model walkable, drivable, or bikeable urban networks with a single line of Python code then easily analyze and visualize them. You can just as easily download and work with other infrastructure types, amenities/points of interest, building footprints, elevation data, street bearings/orientations, and speed/travel time. If you use OSMnx in your work, please cite the journal article. Citation info: Boeing, G. 2017. "OSMnx: New Methods for Acquiring, Constructing, Analyzing, and Visualizing Complex Street Networks." Computers, Environment and Urban Systems 65, 126-139. doi:10.1016/j.compenvurbsys.2017.05.004.

            kandi-support Support

              osmnx has a highly active ecosystem.
              It has 4222 star(s) with 767 fork(s). There are 121 watchers for this library.
              There were 7 major release(s) in the last 6 months.
              There are 3 open issues and 588 have been closed. On average issues are closed in 27 days. There are 1 open pull requests and 0 closed requests.
              It has a positive sentiment in the developer community.
              The latest version of osmnx is 1.8.0

            kandi-Quality Quality

              osmnx has 0 bugs and 0 code smells.

            kandi-Security Security

              osmnx has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              osmnx code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              osmnx is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              osmnx releases are not available. You will need to build from source code and install.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions are available. Examples and code snippets are not available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed osmnx and discovered the below as its top functions. This is intended to give you an instant insight into osmnx implemented functionality, and help decide if they suit your requirements.
            • Plot a figure
            • Geocode a query
            • Create a networkx graph from an address
            • Make a request to the Nominatim API
            • Saves the given data into a graph
            • Appends way edges to the root node
            • Compute the unique nodes in a directed graph
            • Append node attributes to root node
            • Extract geometries from place query
            • R Return the shortest shortest path between orig and dest
            • Truncate a graph according to a bounding box
            • Add node elevation to raster
            • Project the nodes of a graph
            • Save a graph as a networkx graph
            • Save graph_shapefile to file
            • Calculate edge travel time
            • Save graph as GeoPackage layer
            • Extract geometries within a bounding box
            • Plot footprints
            • Plot an orientation distribution
            • Add edge speeds to the graph
            • Find the nearest neighbors between two points
            • Load a graphml file
            • Construct a GeoDataFrame from a place query
            • Add node elevations from G
            • Calculate basic statistics
            Get all kandi verified functions for this library.

            osmnx Key Features

            No Key Features are available at this moment for osmnx.

            osmnx Examples and Code Snippets

            copy iconCopy
            import osmnx as ox
            # get a graph and geodataframes
            G = ox.graph_from_address('Guangzhou, China', network_type= "drive")
            gdf_nodes, gdf_edges = ox.graph_to_gdfs(G)
            # this will make nodes inconsistent, x & y not equal to geometry
            GeoDataFrame Value Error: 'data' should be a 1-dimensional array of geometry objects'
            Pythondot img2Lines of Code : 69dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import osmnx as ox
            import geopandas as gpd
            import pandas as pd
            import io
            df = pd.read_csv(
            Merging Pandas-File with OSMNX
            Pythondot img3Lines of Code : 110dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import geopandas as gpd
            import pandas as pd
            import osmnx as ox
            import folium
            import requests
            from pathlib import Path
            from zipfile import ZipFile
            url = "https://data.geo.admin.ch/ch.astra.unfaelle-personenschaeden_alle/unfaelle-personensc
            How to see city map when ploting with Geopandas lib
            Pythondot img4Lines of Code : 36dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from pathlib import Path
            import pandas as pd
            import geopandas as gpd
            import shapely
            import folium
            # downloaded data
            df = pd.read_csv(
                names=["ID", "Date,Time", "E", "N", "Out
            Convert geopandas.geodataframe to geojson
            Pythondot img5Lines of Code : 3dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            with open('dataframe.geojson' , 'w') as file:
            Networkx: how to combine edges together with condition?
            Pythondot img6Lines of Code : 291dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            def _is_endpoint(G, node, strict=True):
                Is node a true endpoint of an edge.
                Return True if the node is a "real" endpoint of an edge in the network,
                otherwise False. OSM data includes lots of nodes that exist only as poi
            OSMNx : get coordinates of nodes/corners/edges of polygons/buildings
            Pythondot img7Lines of Code : 17dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import osmnx as ox
            # get the building footprints in Macclesfield
            place = 'Macclesfield, Cheshire, England, UK'
            tags = {'building': 'commercial'}
            gdf = ox.geometries_from_place(place, tags)
            # how many did we get?
            print(gdf.shape)  # (57, 
            Excluding points within list of buildings' shapes in Python
            Pythondot img8Lines of Code : 35dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import geopandas as gpd
            import matplotlib.pyplot as plt
            import osmnx as ox
            import pandas as pd
            # the coordinates you provided
            df = pd.DataFrame({'lat': [38.897221,38.888100,38.915390,38.895100,38.895100,38.901005,38.960491,38.996342,38.91
            How to simply compute the travel time from one point to an other? (Without a plot)
            Pythondot img9Lines of Code : 24dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import osmnx as ox
            # get boundaries of West Midlands region by its OSM ID
            gdf = ox.geocode_to_gdf('R151283', by_osmid=True)
            polygon = gdf.iloc[0]['geometry']
            # get network of motorways and trunk roads, with speed and travel time
            cf = '["
            Is there a way to download only vehicle networks from OSM as .osm file?
            Pythondot img10Lines of Code : 2dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            osmfilter input.osm --keep-ways="highway=primary =primary_link =secondary =secondary_link =trunk =trunk_link =motorway =motorway_link" --keep-nodes= --keep-relations= > output.osm

            Community Discussions


            Creating graph using OSMNX from geodataframe and shows error 'TypeError: cannot unpack non-iterable int object'
            Asked 2022-Apr-01 at 10:19

            I used osmnx to download a map and export as geopackages so that I can edit it in QGIS. After edit(mainly change CRS to GCJ-02) , I want to import the edited edges and nodes into osmnx as a graph to do some routing.

            I imported them using



            Answered 2022-Apr-01 at 10:19

            Given what you describe, this warning is fully expected. If you have modified the geometry of the nodes and have not made x and y attributes consistent. Best illustrated by sample code below.

            • first conversion back to a graph generates a warning
            • second conversion after ensuring denormalised columns are consistent with geometry does not generate a warning

            Source https://stackoverflow.com/questions/71701565


            Can I add random nodes on edges manually in OSMNX?
            Asked 2022-Mar-18 at 03:32

            I am new to OSMnx and to NetworkX packages in python.

            Let's say I have the following example:



            Answered 2022-Mar-18 at 03:32

            You can do this in the following way.

            Import nodes and edges as geodataframes.

            Source https://stackoverflow.com/questions/71437958


            OSMNX - what "part" of an edge is considered the nearest
            Asked 2021-Oct-25 at 17:13

            I am using the nearest_edges function in OSMNX. It isn't clear to me what "part" of the edge is used when making this calculation. Is it any part of the edge? Is it the midway point?

            For long edges in the network it would make quite a big difference.



            Answered 2021-Oct-25 at 17:13

            It depends on how you parameterized the function. From the nearest_edges function documentation:

            Find the nearest edge to a point or to each of several points.

            If X and Y are single coordinate values, this will return the nearest edge to that point. If X and Y are lists of coordinate values, this will return the nearest edge to each point.

            If interpolate is None, search for the nearest edge to each point, one at a time, using an r-tree and minimizing the euclidean distances from the point to the possible matches. For accuracy, use a projected graph and points. This method is precise and also fastest if searching for few points relative to the graph’s size.

            For a faster method if searching for many points relative to the graph’s size, use the interpolate argument to interpolate points along the edges and index them. If the graph is projected, this uses a k-d tree for euclidean nearest neighbor search, which requires that scipy is installed as an optional dependency. If graph is unprojected, this uses a ball tree for haversine nearest neighbor search, which requires that scikit-learn is installed as an optional dependency.

            So if you leave interpolate=None (ideally using a projected graph and projected points for accuracy), the function will find the nearest edge(s) to your point(s) based on the point's minimum distance to any part of the edge's geometry. This is geometrically precise and is fastest if only searching for a few points in a big graph.

            Alternatively, if you pass an interpolate argument value, the function will interpolate evenly spaced points along the edges, then find the nearest edge(s) to your point(s) based on the point's minimum distance to any interpolated point along the edge's geometry. This is slightly geometrically imprecise (with this imprecision varying with your interpolate value) but is fastest when searching for many points, particularly in a smaller or mid-sized graph.

            Source https://stackoverflow.com/questions/69673649


            Extremely long response time with graph_from_place OSMNX
            Asked 2021-Oct-14 at 20:09

            I'm trying to download the map of Mexico to avoid querying using save_graphml and avoiding long response times in the graph_from_place, but I've already left this code running for almost six hours and absolutely nothing happens.



            Answered 2021-Oct-14 at 20:09

            I've already left this code running for almost six hours and absolutely nothing happens.

            A lot has been happening! Don't believe me? You ran ox.config(log_console=True), so look at your terminal and watch what's happening while it runs. You'll see a line like "2021-10-14 13:05:39 Requesting data within polygon from API in 1827 request(s)"... so you are making 1,827 requests to the Overpass server and the server is asking you to pause for rate limiting between many of those requests.

            I know that due to the stipulated area the time is long, but what I wanted to know is if there is an alternative to this procedure or if there is a way to optimize so that the creation of the map is a little faster or if there is another way to load maps to route with osmnx and networkx without using queries to servers

            Yes. This answer provides more details. There are tradeoffs between 1) model precision vs 2) area size vs 3) memory/speed. For faster modeling, you can load the network data from a .osm XML file instead of having to make numerous calls to the Overpass API. I'd also recommend using a custom_filter as described in the linked answer. OSMnx by default divides your query area into 50km x 50km pieces, then queries Overpass for each piece one a time to not exceed the server's per-query memory limits. You can configure this max_query_area_size parameter, as well as the server memory allocation, if you prefer to use OSMnx's API querying functions rather than its from-file functionality.

            Source https://stackoverflow.com/questions/69571863


            How to simply compute the travel time from one point to an other? (Without a plot)
            Asked 2021-Oct-14 at 19:23

            I spent a lot of time reading and testing the example notebooks of OSMnx but I couldn't figure out a way to simply calculate the travel time from a given point (GPS coordonates) to an other one. I would like to estimate, for each point from my list, how long it takes to go to a specific point (sometimes 100km away). I don't need to generate a graph/map/plot, as I only need the duration of each trip (and I think that OSMnx maps render better at a city-scale).

            I am pretty desperate as I could not find a simple way to do this across different Python libraries... If doing this calculation for +-10k points within a country-scale map is asking too much from OSMnx, could a locally stored pbf file of the country be helpful for another solution?



            Answered 2021-Oct-14 at 19:23

            There are inherent trade-offs when you want to model a large study area such as an entire region or an entire country: 1) model precision vs 2) area size vs 3) memory/speed. You need to trade off one of these three.

            For the first, you can model a coarser-grained network, such as only major roads in the region/country, rather than millions of fine-grained residential streets and paths. For the second, you can study a smaller area. For the third, you can provision a machine with lots of memory and then let the script run for a while to complete the process. What you trade off will be up to your own needs for this analysis.

            In the example code below, I chose to trade off #1: I've modeled this region (West Midlands) by its motorways and trunk roads. Given a different analytical goal, you may trade off other things instead. After creating the model, I randomly sample 1000 origin and destination lat-long points, snap them to the nearest nodes in the graph, and solve the shortest paths by travel time (accounting for speed limits) with multiprocessing.

            Source https://stackoverflow.com/questions/69511305


            OSMNX does not return graph for all European capitals
            Asked 2021-Sep-06 at 04:56

            I am confused by the fact that some European capitals do not return a graph when queried with osmnx. It works perfectly for Lisbon, Berlin, Paris, etc., but when I try to run it with Brussels or Athens, I get a NetworkXPointlessConcept: Connectivity is undefined for the null graph. error.

            I don't think this is expected and would appreciate any help if someone knows how to solve this.
            I already checked the docs and ensured that all packages are up to date (osmnx is 1.1.1).



            Answered 2021-Sep-06 at 04:56

            I do not know the reason why it cannot be obtained. When I looked into it, I was able to get geopandas, and from there I was able to get the latitude and longitude information.

            Source https://stackoverflow.com/questions/68987386


            OSMNX geocoder returning incorrect coordinates
            Asked 2021-Aug-21 at 15:25

            When using the osmnx geocoder module, it seems that the wrong Latitude and Longitude is returned. I have cross checked the coordinates returned with multiple websites and it is not correct. This is the only relevant code being used:



            Answered 2021-Aug-20 at 18:01

            so the answer to your question might be because you are not projecting your Network. Take a look at this similar question I posted which was answered by the creator of the library: Node found is too far from my lat, lon coordinates (osmnx)

            Source https://stackoverflow.com/questions/68866139


            Selecting buildings from multiple locations in osmnx python
            Asked 2021-Jun-28 at 11:17

            I am new to python as well as in osmnx package.

            Lets say I have two locations, islands: Nauro and Lakeba Island. What I want to achieve is to have a one dataframe (or geodataframe) which will include buildings from both islands. I have this code but it only prints the results, but do not unite them.



            Answered 2021-Jun-28 at 11:17

            You need to load all dataframes you need, store them and then concatenate them together.

            Source https://stackoverflow.com/questions/68161963


            Issues running OSMnx on conda
            Asked 2021-Jun-12 at 02:13

            I'm trying to get the Python package OSMnx running on my Windows10 machine. I'm still new to python so struggling with the basics. I've followed the instructions here https://osmnx.readthedocs.io/en/stable/ and have successfully created a new conda environment for it to run in. The installation seems to have gone ok. However, as soon as I try and import it, I get the following error



            Answered 2021-Apr-28 at 10:07

            The module fractions is part of the Python standard library. There used to be a function gcd, which, as the linked documentation says, is:

            Deprecated since version 3.5: Use math.gcd() instead.

            Since the function gcd was removed from the module fractions in Python 3.9, it seems that the question uses Python 3.9, not Python 3.7.6 as the question notes, because that Python version still had fractions.gcd.

            The error is raised by networkx. Upgrading to the latest version of networkx is expected to avoid this issue:

            Source https://stackoverflow.com/questions/67297792


            How to download buildings data from OSM with a polygon (shapefile) as the bounding box?
            Asked 2021-Apr-22 at 05:02

            I am struggling to complete this task. I am trying OSMnx which can be used to download data from OSM above however I am getting an error when using its from_polygon feature when trying to download data. Also I am not sure if this data will include Buildings data.

            I load my shapefile into geopandas and can then view and interact with it

            This is the code



            Answered 2021-Apr-22 at 05:02

            I wasn't able to download buildings data from OSM with a polygon (shapefile) as the bounding box however I was able to using distance from a point with the following code:

            Source https://stackoverflow.com/questions/66084198

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install osmnx

            How do I install OSMnx? Follow the installation instructions. How do I use OSMnx? Check out the usage examples/tutorials in the examples repo. How does this or that function work? Read its documentation. What can I do with OSMnx? Check out recent projects and blog posts that use OSMnx. I have a usage question. Please ask it on StackOverflow.


            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • PyPI

            pip install osmnx

          • CLONE
          • HTTPS


          • CLI

            gh repo clone gboeing/osmnx

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Map Libraries


            by zhaoolee


            by openlayers


            by CesiumGS


            by mapbox


            by Turfjs

            Try Top Libraries by gboeing


            by gboeingJupyter Notebook


            by gboeingJupyter Notebook


            by gboeingJupyter Notebook


            by gboeingPython


            by gboeingJupyter Notebook