Tag Info

Hot answers tagged networkx

From shapefile to Python NetworkX?

I might have found a nice Python solution referring to the very shapefile in the question, so I am posting it for future reference. import networkx as nx import matplotlib.pyplot as plt G=nx....
• 843

Generating Steiner tree using Network X in Python?

Steiner tree connects some(!) of the network's nodes (terminals) shown as selected nodes: However don't get over excited about this feature of networkX, there is a good reason they called it "...
• 23.2k
Accepted

From shapefile to Python NetworkX?

That will pretty much depend on how your shapefile is. Is it segmented (the lines break, when they encounter intersections)? I haven't used read_shp for networkx, so I'm not sure. I guess that ...
• 6,310
Accepted

How to load a weighed shapefile in networkX

There are many other solutions proposed in GIS SE to convert a shapefile into a graph with Networkx.. If you use the Networkx solution (nx.read_shp()), the original geometry and the field values are ...
• 55.1k
Accepted

Programmatically infer start and end points from a Polygon with linear characteristics

You may ned to investigate what is often called a medial axis transform and sometimes a skeletonization. From wiki/Medial_axis: The medial axis of a simple polygon is a tree whose leaves are the ...
• 8,981
Accepted

Shortest path between one point to every other points

You first need to define what you mean by shortest path. If you don't weight your graph (G), shortest path is simply the path that connects the nodes that passes through the fewest number of other ...
• 2,894

Shortest path between one point to every other points

You can skip the python part and use the plugin QNEAT3 which is available for QGIS3 (see Distance Matrix with 2 point shapefiles and one street network. It also works in your case offers multiple ...
• 2,385

Shortest path between one point to every other points

NetworkX all_shortest_paths or single_source_dijkstra You need to calculate all the shortest paths from your source and then summarize edges weights fro every path. Also I'm absolutely sure that ...
• 862
Accepted

Inaccurate output (missing features) while reading a shapefile into networkx

It is not complicated. nx.read_shp uses ogr to read a shapefile , look at nx_shp.py line 78-88 then the script use a dictionary to add nodes to the Graph (lines 87-88, net.add_node((g.GetPoint_2D(0))...
• 55.1k

Installing networkx Python package in QGIS

The easiest way to install networkx python module to run it from QGIS is to use OSGeo4W installer. It will handle all the dependencies that networkx rely on. Download OSGeo4W Network installer from ...
• 41.1k

Finding out and editing specific rows of attribute table in line shapefile using Python?

In your script: Why do you work with nodes and not directly edges (= LineString and you want the predicate LineString.contains(LineString)) ? Why Numpy here, you can use the simple zip command (...
• 55.1k
Accepted

Algorithm for recursive network optimization

I used minimum spanning tree of the graph (solid black line) to connect terminals. Note: not all nodes of the graph shown below: And applied following algorithm on 631 terminals. Terminal being a ...
• 23.2k

Reading a shapefile into networkx as undirected graph

A graph is said to be connected if there is a path between every pair of vertex. Therefore create a new full connected Graph with itertools import itertools Road = nx.read_shp('stac_graph.shp') # ...
• 55.1k

Generating Steiner tree using Network X in Python?

The minimum spanning tree is computed on the input graph. Your input graph is the star network from the distribution point to the three premises - it doesn't contain edges from the premises to the ...
• 65.1k
Accepted

How to calculate edge length in Networkx

see Inaccurate output (missing features) while reading a shapefile into networkx) and nx_spatial does not read all shapefile features Networkx generate a networkx.DiGraph with nodes without ...
• 55.1k

How to (re)install gdal in python3 (mac)?

You have a serious problem with your Anaconda installation: All the modules were installed with conda or pip and osgeo/gdal is well supported in 3.6. In your case, why numpy 1.8* -> python 2.6* -...
• 55.1k

How to (re)install gdal in python3 (mac)?

Now, I'm not sure if this will help, but here's how I got gdal for Python installed recently. Note, that I use Homebrew, which will further complicate your system, and really, I don't recommend it! ...
• 13.5k
Accepted

ArcGIS Server Geoprocessing Service failing on repeat call

This same thing occurs for me in ArcMap 10.4.1 Python 2.7.10 32bit and ArcGIS Server 10.5.1. Python 2.7.13 32bit. It occurs for Networkx 2.1 but does not occur for Networkx 1.7 The issue can be ...
• 38

networkx shortest path error

Based upon what @FelixIP said I would check the junctions marked here: See if they are genuinely snapped or its not a multi-part shape which breaks network topology.
• 43.9k

How to load a weighed shapefile in networkX

This didn;t actually work for me (maybe because of updates), but below is the code that worked for me. Updated from the answers above. I post this as a followup from How to load a weighed shapefile ...

Cluster networkx graph with sklearn produces unexpected results

I tried to replicate your setup as best as I could. I downloaded a juncture of two winding secondary highways from OpenStreetMap, loaded them into GeoPandas in Python. For every pair of points I ...
Accepted

Parallel offset on Folium

Finally, I have resolved the problem points = [] for u,v,data in G.edges(keys=False, data=True): if 'geometry' in data: xs,ys = data['geometry'].xy point = list(zip(xs,ys)) ...
• 191
Accepted

How to calculate the length and duration of trip for a GeoDataFrame of points on OpenStreetMap using OSMnX package?

According to the documentation of OSMNX, your line with G = ox.add_edge_speeds(G) will : Add edge speeds (km per hour) to graph as new speed_kph edge attributes. By default, this imputes free-flow ...
• 407

how to genereate isochrone from networkx?

With networkx you can only calculate the shortest distance between the node of the graph, it is not possible to construct an isochrone map directly (This means that we have an estimate of the access ...
• 1,537
1 vote

Convert a list of coordinates to an OSM path using Python

The path must be a list of route lists itineraire = [(-7.5822778, 33.5649577), (-7.5823494, 33.5651468), (-7.582575300000001, 33.5656444), (-7.582148500000001, 33.565812), (-7.5819043, 33.5658939), (-...
• 55.1k
1 vote
Accepted

Showing two roads lane of one road

Your function suffers some tiny bugs, let's fix them one by one and explore the code. # imports import numpy as np import geopandas as gpd import folium import osmnx as ox ox.config(use_cache=True, ...
• 10.5k
1 vote

Steiner Tree optimization

You can contract all nodes of degree 2 except for the terminals (the nodes that should always be in your tree). The reason is that you will never have a non-terminal node as a leaf in an optimal ...
• 11
1 vote

Determining best k node sample to approximate betweenness centrality

Just so that it's clear, k can equal n (your nb_node). From the networkx documentation you link to: "The value of k <= n where n is the number of nodes in the graph. Higher values give better ...
• 837
1 vote
Accepted

No module named networkx

I guess you didn't install networkx in the ArcGIS Python environment you are currently using in ArcGIS. To be sure, that you choose the right enviromnent you should change the working Directory to the ...
• 1,330
1 vote

Getting KeyError when using shortest_path of NetworkX and ShapeFile

I have confirmed that in networkx 1.11, the keys of the network dictionary are the start node coordinates, not the start and end node segments as i would suspect. Though significant changes have been ...
• 295

Only top scored, non community-wiki answers of a minimum length are eligible