Osmnx Download Graph

0 views
Skip to first unread message

Nugroho Salem

unread,
Jul 22, 2024, 2:34:26 PM7/22/24
to starfiedramcoa

OSMnx only adds a geometry attribute to simplified edges. If an edge is unsimplified, its geometry is a trivial straight line between its incident nodes u and v. In your code, you parameterized graph_from_point with simplify=False, hence none of your edges are simplified and none of them have geometry attributes:

If you simplify the graph, some or all of its edges will have geometry attributes, depending on whether or not a particular street segment linking two intersections spanned multiple OSM nodes originally. The topological simplification methodology is detailed in this paper. More details appear in the docs. Example:

osmnx download graph


Download Filehttps://ssurll.com/2zFID1



You can also manually add geometry attributes to each edge of a simplified or unsimplified graph by calling graph_to_gdfs with fill_edge_geometry=True then reconstructing your graph with graph_from_gdfs, like this:

Finally, in a comment above, you mentioned "I am using what is the latest version, which is osmnx 0.16.1." But, your code snippet can't be using v0.16.1 because the distance parameter was deprecated and eventually replaced with dist 5 or 6 versions ago. Try running print(ox.__version__) to see what version you're actually using.

the following errors:File ../python3.7/site-packages/osmnx/core.py", line 931, in create_graphraise EmptyOverpassResponse('There are no data elements in the response JSON objects')osmnx.errors.EmptyOverpassResponse: There are no data elements in the response JSON objects

Vectorized function to calculate (initial) bearing from origin node todestination node for each edge in a directed, unprojected graph then addthese bearings as new edge attributes. Bearing represents angle in degrees(clockwise) between north and the geodesic line from the origin node tothe destination node. Ignores self-loop edges as their bearings areundefined.

Note: this function is run by all the graph.graph_from_x functionsautomatically to add length attributes to all edges. It calculates edgelengths as the great-circle distance from node u to node v. WhenOSMnx automatically runs this function upon graph creation, it does itbefore simplifying the graph: thus it calculates the straight-line lengthsof edge segments that are themselves all straight. Only aftersimplification do edges take on a (potentially) curvilinear geometry. Ifyou wish to calculate edge lengths later, you are calculatingstraight-line distances which necessarily ignore the curvilinear geometry.You only want to run this function on a graph with all straight edges(such as is the case with an unsimplified graph).

If X and Y are single coordinate values, this will return the nearestedge to that point. If X and Y are lists of coordinate values, thiswill return the nearest edge to each point. This function uses an R-treespatial index and minimizes the euclidean distance from each point to thepossible matches. For accurate results, use a projected graph and points.

If the graph is projected, this uses a k-d tree for euclidean nearestneighbor search, which requires that scipy is installed as an optionaldependency. If it is unprojected, this uses a ball tree for haversinenearest neighbor search, which requires that scikit-learn is installed asan optional dependency.

Vectorized function to calculate the directed grade (ie, rise over run)for each edge in the graph and add it to the edge as an attribute. Nodesmust already have elevation attributes to use this function.

The query must be geocodable and OSM must have polygon boundaries for thegeocode result. If OSM does not have a polygon for this place, you caninstead get its street network using the graph_from_address function,which geocodes the place name to a point and gets the network within somedistance of that point.

Do not load an XML file generated by OSMnx: this use case is not supportedand may not behave as expected. To save/load graphs to/from disk for lateruse in OSMnx, use the io.save_graphml and io.load_graphml functionsinstead.

This function exists only to allow serialization to the .osm file formatfor applications that require it, and has constraints to conform to that.As such, this function has a limited use case which does not includesaving/loading graphs for subsequent OSMnx analysis. To save/load graphsto/from disk for later use in OSMnx, use the io.save_graphml andio.load_graphml functions instead. To load a graph from a .osm file thatyou have downloaded or generated elsewhere, use the graph.graph_from_xmlfunction.

Only use if specifically saving to .osm XML file with the save_graph_xmlfunction. If True, forces all ways to be loaded as oneway ways, preservingthe original order of nodes stored in the OSM way XML. This also retainsoriginal OSM string values for oneway attribute values, rather thanconverting them to a True/False bool. Default is False.

If True, download network data from Overpass then raise aCacheOnlyModeInterrupt error for user to catch. This prevents graphbuilding from taking place and instead just saves OSM response data tocache. Useful for sequentially caching lots of raw data (as you canonly query Overpass one request at a time) then using the local cache toquickly build many graphs simultaneously with multiprocessing. Default isFalse.

Merges nearby nodes and returns either their centroids or a rebuilt graphwith consolidated intersections and reconnected edge geometries. Thetolerance argument should be adjusted to approximately match street designstandards in the specific street network, and you should always use aprojected graph to work in meaningful and consistent units like meters.Note the tolerance represents a per-node buffering radius: for example, toconsolidate nodes within 10 meters of each other, use tolerance=5.

if rebuild_graph=True, returns MultiDiGraph with consolidatedintersections and reconnected edge geometries. if rebuild_graph=False,returns GeoSeries of shapely Points representing the centroids ofstreet intersections

Simplifies graph topology by removing all nodes that are not intersectionsor dead-ends. Create an edge directly between the end points thatencapsulate them, but retain the geometry of the original edges, saved asa new geometry attribute on the new edge. Note that only simplifiededges receive a geometry attribute. Some of the resulting consolidatededges may comprise multiple OSM ways, and if so, their multiple attributevalues are stored as a list. Optionally, the simplified edges can receivea merged_edges attribute that contains a list of all the (u, v) nodepairs that were merged together.

By default, this imputes free-flow travel speeds for all edges via themean maxspeed value of the edges of each highway type. For highway typesin the graph that have no maxspeed value on any edge, it assigns themean of all maxspeed values in graph.

This function uses an undirected representation of the graph and specialhandling of self-loops to accurately count physical streets rather thandirected edges. Note: this function is automatically run by all thegraph.graph_from_x functions prior to truncating the graph to therequested boundaries, to add accurate street_count attributes to eachnode even if some of its neighbors are outside the requested graphboundaries.

However, you can convert arbitrary node and edge GeoDataFrames as long as1) gdf_nodes is uniquely indexed by osmid, 2) gdf_nodes contains xand y coordinate columns representing node geometries, 3) gdf_edges isuniquely multi-indexed by u, v, key (following normal MultiDiGraphstructure). This allows you to load any node/edge shapefiles or GeoPackagelayers as GeoDataFrames then convert them to a MultiDiGraph for graphanalysis. Note that any geometry attribute on gdf_nodes is discardedsince x and y provide the necessary node geometry information instead.

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.

(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)

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

OSMNX will allow for a custom filter, so you could use a filter that matches exactly the filter used at Citystrides, that would be a nice touch and keep from trying to route us onto roads inappropriate for running.
Docs: =custom%20filter#osmnx.graph.graph_from_polygon
It appears the details of that query can be found here: Overpass Street Query

Calculate the compass bearing from origin node to destination node for each edge in the directed graph then add each bearing as a new edge attribute. Bearing represents angle in degrees (clockwise) between north and the direction from the origin node to the destination node.

If we overlay the parish boundary, we see that the routes returned correspond to the graph between nodes that lay within the boundary. Some roads pass straight through the boundary, others appear to lay just outside the boundary.

I recently went to a talk at UC Berkeley by the GraphXD group. Their site is here. The presenter of the first seminar, Tselil Schramm gave a great talk on cluster methods on graphs. Specifically, she discussed spectral clustering and the utilization of the Laplacian matrix to represent graphs on a plane.

The operation is easily understood when viewed. Above is an example from Wikipedia that illustrates the operation. With the resulting eigenvector matrix, we can extract the second and third eigenvectors and assign them to their respective node ids. Doing so allows us to assign new x/y values to each node id and, as a result, plot a variation of the original network graph that visually associates nodes more closely to other nodes that it has stronger connections with.

760c119bf3
Reply all
Reply to author
Forward
0 new messages