osmnx | street networks . | Map library
kandi X-RAY | osmnx Summary
kandi X-RAY | osmnx Summary
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.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- 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
osmnx Key Features
osmnx Examples and Code Snippets
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
gdf_n
import osmnx as ox
import geopandas as gpd
import pandas as pd
import io
df = pd.read_csv(
io.StringIO(
"""AccidentUID,AccidentLocation_CHLV95_E,AccidentLocation_CHLV95_N
99BA5D383B96D02AE0430A865E33D02A,2663985,1213215
9B25C4
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
from pathlib import Path
import pandas as pd
import geopandas as gpd
import shapely
import folium
# downloaded data
df = pd.read_csv(
Path.home().joinpath("Downloads/SaobracajBeograd.csv"),
names=["ID", "Date,Time", "E", "N", "Out
with open('dataframe.geojson' , 'w') as file:
file.write(batiments.to_json())
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
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,
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
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 = '["
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
Trending Discussions on osmnx
QUESTION
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
...ANSWER
Answered 2022-Apr-01 at 10:19Given 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
QUESTION
I am new to OSMnx and to NetworkX packages in python.
Let's say I have the following example:
...ANSWER
Answered 2022-Mar-18 at 03:32You can do this in the following way.
Import nodes and edges as geodataframes.
QUESTION
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.
...ANSWER
Answered 2021-Oct-25 at 17:13It 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.
QUESTION
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.
ANSWER
Answered 2021-Oct-14 at 20:09I'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.
QUESTION
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?
...ANSWER
Answered 2021-Oct-14 at 19:23There 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.
QUESTION
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).
ANSWER
Answered 2021-Sep-06 at 04:56I 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.
QUESTION
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:
...ANSWER
Answered 2021-Aug-20 at 18:01so 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)
QUESTION
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.
...ANSWER
Answered 2021-Jun-28 at 11:17You need to load all dataframes you need, store them and then concatenate them together.
QUESTION
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
...ANSWER
Answered 2021-Apr-28 at 10:07The 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:
QUESTION
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
...ANSWER
Answered 2021-Apr-22 at 05:02I 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:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install osmnx
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page