My starting data :

  • a collection of points which are buildings
  • a collection of points which are electrical transformation plant
  • a network of vectors which is the public electric network from an operator
  • buildings are not connected to the electric network

I use QGIS to find which are the buildings which are located less than 250 meters from an electrical transformation plant by following the network. I need this information more 100.000 buildings.

To do it by hand :

  • trace a line between the building and the nearest electrical network segment,
  • compute the distance by the network between this entry point and the nearest tranformation plant. I have found the RoadGraph plugin (http://gis-lab.info/qa/road-graph-eng.html) which works for that
  • add the two distances and check if < 250m.

Now, my question is: how to automatize it for the 99.999 other buildings ? I know Python a lot but I am a beginner with QGIS. I did not find a way to automatically interact with the RoadGraph plugin and source code seems not to be available anymore.

Maybe I am doing it wrong ?

what it looks like

  • 1
    is your data in PostgreSQL?
    – kttii
    Jun 20, 2016 at 16:05
  • No, they are in fields associated to the layers via attribute tables. If it can help, I think I would be able to export them to pgSQL. Jun 20, 2016 at 16:25
  • so your data comes from shapefiles?
    – kttii
    Jun 20, 2016 at 16:42

1 Answer 1


The PostGIS extension of PostgreSQL contains an executable (shp2pgsql) to import shapefiles (.shp) to PostgreSQL.

The pgRouting extension contains functions for the routing of networks (ways), such as pgr_dijkstra().

You could either write a stored procedure to do the automation or use python to access and automate the functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.