0

I use driving_distance function in pgRouting to work with my river network. There are 12 vertices in my river network, and I want to get the distance between all of these 12 vertices, starting from vertex_id No.1.

The result is fine, but I want to get other results using other vertices as starting point. I know it would not cost much time to change the SQL code everytime, but thereafter I would have more than 500 vertices in this river network, so I need to do this more efficiently.

How to use python to get what I want? How can I write a python script to do this? Or there are existing python script that I want?

I am a novice with programming language, please give me any detailed advice, thank you.

Heinz
  • 2,415
  • 6
  • 26
  • 34

1 Answers1

1

pyscopg2 Is an excellent python module that allows your scripts to connect to your postgres database and run SQL whether as inputs or as fetch queries. You can have python walk through the number of possible combinations between vertices and have it build the individual SQL queries as strings. It can then run through them and print your output into a text file.

AlienAnarchist
  • 186
  • 4
  • 15
  • thank you, and I want to ask one question: Do I have to use psycopg2 to connect python and postgresql? or I can access in postgresql directly using python (IDLE)? – Heinz Mar 15 '14 at 05:09
  • 1
    IDLE is just an IDE(Integrated Development Environment) for python. FOr the ask you are building I would expect you to make a .py file and build out the script in it's entirety, then run it. pyscopg is just a module that has a lot of useful functionality for postgres. – AlienAnarchist Mar 17 '14 at 16:25