Skip to main content
11 votes
Accepted

PgRouting : Shortest path starting from the closest vertex not the closest node

While still not in the official release, the withPoints family of functions is in a stable state since pgRouting 2.2 (?) and provides a dynamic interface for temporary nodes in a graph, i.e. routing ...
geozelot's user avatar
  • 30.3k
6 votes
Accepted

pgrouting no result // topology problem

EDIT 3: After a long discussion in the comments I reviewed my answer, taking the sample data and it´s upload into PostgreSQL from within QGIS into account. I deleted my EDIT 2 as it became useless. ...
geozelot's user avatar
  • 30.3k
5 votes

pgr_dijkstra function with geometry column in result

Join to table ways is as for now only solution (BTW recommended in all official documentation and workshops)
Jendrusk's user avatar
  • 2,617
5 votes
Accepted

How to convert a shapefile into a graph in which use Dijkstra

The sg module uses Fiona to read the shapefiles (see shapegraph.py ) and if you can use the module, therefore Fiona is installed. If you cannot use nx_shp.py (because of osgeo) and you have problems ...
gene's user avatar
  • 55.1k
3 votes
Accepted

How can I calculate the shortest path between 2 points and insert the line result as a feature in a layer?

Your code is working for me without problem. I've try it in the QGIS python console. When i run it with a first start and end point, i get the red line in the cable layer then i run the script with ...
YoLecomte's user avatar
  • 2,895
3 votes

Using python QGIS network analysis library to calculate short path based on speed and distance?

I'm using Ubuntu 14.04, QGIS 2.8.1-Wien and python2.7. Feature.attributeMap() does not work. After much struggles with the undocumented way of implementing new ArcProperter's, here is my working ...
ErnestScribbler's user avatar
3 votes
Accepted

Projects points to lines inside a polygon

Your line layer has a different CRS to your point layer, which is likely the reason the shortest_line function is not working. You can collect together your line segments and perform a transformation ...
Matt's user avatar
  • 17.4k
2 votes

Using python QGIS network analysis library to calculate short path based on speed and distance?

I think you don't need QVariant. I'm trying to create my own Properter for bike trips which (as a start) excludes freeways and roads that haven't been built yet. In my road layer, these are ...
Steve's user avatar
  • 361
2 votes
Accepted

Shortest path problem from A to B on routing engines

You can get rid of such subnetworks otherwise it is harder as you'll need to decide for a 'cost factor' such distances need to be multiplied with. E.g. if you have A' and A'' and B' and B'' there are ...
Karussell's user avatar
  • 707
2 votes
Accepted

PGrouting costs

The cost of pgRouting is used for the cost function. In your case the cost is "score * penalty". The pgr_dijkstraCost() function is mainly for convenience, for example when you request multiple ...
dkastl's user avatar
  • 4,796
2 votes
Accepted

Bounding box in Dijkstra algorithm (many to many)

Prepare the bbox and pass it as text into the edges_sql: Updated SELECT nodes.id, SUM(pgr.cost) AS "Aggregated Cost" FROM ( SELECT pwn.id, pwn."nearest_mz", pwn."...
geozelot's user avatar
  • 30.3k
2 votes

Shortest path between cities without duplicate calculation (many-to-many)

Since no one joined in, and if you don´t mind, I´ll share some thoughts without this being a satisfying answer (I share a work-related intereset in this). I highly doubt you have much of an ...
geozelot's user avatar
  • 30.3k
2 votes
Accepted

The distance between the points of two layers

You can perform your analysis with QGIS by QNEAT3 plugin using OD-Matrix Algorithms, here you find algoritms description QNEAT3 - OD-Matrices . The function OD-Matrix calculates travel distance and/or ...
EFiore's user avatar
  • 421
2 votes
Accepted

pgr_dijkstra select shortest path for pairs

What you are looking for has been added to pgRouting recently and is available under the name "Combinations", for example the Dijkstra implementation: https://docs.pgrouting.org/latest/en/...
dkastl's user avatar
  • 4,796
2 votes
Accepted

Incorrect Shortest Paths

This looks like the correct path, but it is badly drawn on this projection. The route heads north out of Brisbane, then turns right and hits the edge of the map. The red line across the world is ...
Spacedman's user avatar
  • 64.6k
2 votes

After pgr_createTopology, how should I use pgr_dijkstra?

Like explain in the documentation the pgr_dijkstra function need the following parameters : Edges SQL : A string that represents a SQL query for extract the edges from your edge_table. start_vid : An ...
Atm's user avatar
  • 1,537
1 vote

Least cost path from single source to single destination without cost distance (calculating accumulative cost)

To compute least cost path algorithm does calculate accumulative cost => backlink table => path. Yes, no need to memorize cost distance and backlink table when you dealing with single pair: ...
FelixIP's user avatar
  • 23.1k
1 vote
Accepted

Routing only with specified points

My understanding of PGRouting is that when you create a network from a line dataset, it will build a 'ways' table, but most importantly build a 'osm_nodes' table from the nodes of the 'ways'. The ...
DPSSpatial_BoycottingGISSE's user avatar
1 vote

How to limit the search for facilities to only 1 unit with PG Routing? ... Closest Facility in PostGIS?

Well, finally I found a solution, more than a week ago, that works fine for me.. So, I want to share it, if someone else has encountered the same problem. I'm aplying this to cities from Chile......
isidrop's user avatar
  • 66
1 vote

Selecting lines with start and end points inside polygons but do not cross them with PostGIS

St_difference will always return a line in your case, with a "hole" in the city buffers. Your second query returns nothing because each line do intersect with the start/end buffer. To get a working ...
JGH's user avatar
  • 42.2k
1 vote

Selecting lines with start and end points inside polygons but do not cross them with PostGIS

Well, I found an error in my code, I forgot to create a buffer only around cities with an importance < 2. But I also found the right way to select it, by using a join, counting the number of ...
BFlat's user avatar
  • 394
1 vote

Dijkstra/Finding shortest path gives back a tree with only -1 in it

I lost whole week to migrate my old dijkstra code from QGIS/Python 2x to 3x... Finally I found out that some issues in qgis.anylysis (QgsVectorLayerDirector, QgsGraphBuilder, QgsGraphAnalyzer) are ...
Marko Šljivarić's user avatar
1 vote

pgr_dijkstra one to many

try to use the pgr_bdDijkstra function. This function generates a route from one origin to several destinations. --Exemple SELECT * FROM pgr_bdDijkstra('select id, source ,target, cost from edge',...
Rogerio Siqueira's user avatar
1 vote

pgrouting no result // topology problem

I was having problems with pgr_nodenetwork, so I looked at the known issues. It seems that pgr_nodenetwork has not been working properly see here. To overcome these issues, I manually noded my ...
jbalk's user avatar
  • 7,583
1 vote

How can I insert the result of the dijkstra algorithm as a feature in a table with PyQGIS?

This applies for QGIS 2.18: You may first create a (memory) layer (if you don't already have one) and a data provider and add it to the registry and the layer list using the following code: my_lyr = ...
Jochen Schwarze's user avatar
1 vote

Calculate shortest path and distance between multiple OD pairs using pgr_dijkstra one-to-one

do you mean finding the shortest route from all points to all other points on your network? That's possible with the All Pairs Shortest Path, Floyd-Warshall Algorithm but in "big O" notation it's O(...
Steven Kay's user avatar
  • 20.5k
1 vote
Accepted

Syntax of pgr_dijkstraCost()

I wouldn't use a loop because you'll still have the issue that any plpgsql you write has to commit as a transaction so you'd probably still run out of memorty. However, psql has a nice feature called ...
Regina Obe's user avatar
  • 10.5k
1 vote

pgr_dijkstraCost() Many-to-Many exceeding RAM disponibility

I had a similar problem and I solved it like this: You can simply break the job into pieces, by running more than one queries and creating more than one tables. For example, if the values of your "...
arigo's user avatar
  • 11
1 vote

Create shapefile line from a list of point coordinates in a stand-alone python script

The result of the PyQGIS script is a list of points (point_route) In this example, the point_route result is (7 points between pStart = QgsPoint(110579.17281126765, 116585.26070464966), point 7, and ...
gene's user avatar
  • 55.1k
1 vote

Typing path length using shortest path dijkstra()

Basically your question is how long is the path represented as points in p. Since you are using a projection that is in meters it is simply a case of iterating through p and calculating the distance ...
Ian Turton's user avatar
  • 82k

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