14 votes

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....
FaCoffee's user avatar
  • 813
5 votes

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 "...
FelixIP's user avatar
  • 22.8k
4 votes
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 ...
gene's user avatar
  • 54.7k
4 votes
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 ...
Martin F's user avatar
  • 8,908
4 votes
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 ...
Jon's user avatar
  • 2,884
4 votes

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 ...
root676's user avatar
  • 2,385
4 votes

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 ...
Serge Norin's user avatar
4 votes
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))...
gene's user avatar
  • 54.7k
4 votes

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 ...
ahmadhanb's user avatar
  • 40.7k
4 votes
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 ...
George Silva's user avatar
  • 6,298
4 votes

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 (...
gene's user avatar
  • 54.7k
4 votes
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 ...
FelixIP's user avatar
  • 22.8k
3 votes

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 ...
Spacedman's user avatar
  • 63.2k
3 votes

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* -...
gene's user avatar
  • 54.7k
3 votes
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 ...
gene's user avatar
  • 54.7k
3 votes

Problem with read_shp() in NetworkX

It seem to me that you don't understand the principles of Nextwokx (see nx_spatial does not read all shapefile features) Networkx generate a networkx.DiGraph from the shapefile, with nodes and edges ...
gene's user avatar
  • 54.7k
2 votes
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 ...
Lowry's user avatar
  • 38
2 votes

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! ...
Alex Leith's user avatar
  • 13.4k
2 votes

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 ...
Bence Mélykúti's user avatar
2 votes

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.
Hornbydd's user avatar
  • 43.2k
2 votes

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 ...
Jeroen123's user avatar
2 votes

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') # ...
gene's user avatar
  • 54.7k
2 votes
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)) ...
aba2s's user avatar
  • 191
2 votes

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 ...
Atm's user avatar
  • 1,509
2 votes
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 ...
XaC's user avatar
  • 407
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), (-...
gene's user avatar
  • 54.7k
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, ...
swiss_knight's user avatar
  • 10.1k
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 ...
daniel's user avatar
  • 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 ...
humperderp's user avatar
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 ...
Saleika's user avatar
  • 1,320

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