Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have three tables in Postgresql, each table with one layer of lines. I want to show the path of an initial line to another final. Is it possible executing a SQL query? Thanks

My three tables are connected:

Table cables - gid, id, the_geom

Table tubes - gid, id, cable_id, the_geom

Table fibers - gid, id, tube_id, the_geom

If I select the fiber id=1 I want to know (and see in map) the way starting in fiber 1 until the beginning (fiber - tube - cable)

share|improve this question
    
Welcome to gis.SE. Its probably possible, but to show you how it might work (e.g with a sample query), we'll need to see the schema for the tables and possibly the data if that schema isn't very descriptive. Can you update your question (just click "edit" above) to include this information? –  BradHards Apr 12 '13 at 10:30
    
Do you wanna join all three tables ? You can create SQL view and add it from "add postgis layer" to qgis. Im not sure what you want –  simplexio Apr 12 '13 at 10:39
add comment

1 Answer 1

use extention "DB Manager" and there maybe type the SQL-Query (one layer):

    select gid, id, 'cable' as type, the_geom from cables a join tubes b join fibers c on b.id = c.tube_id on a.id = b.cable_id where c.id = 1
    union
    select gid, id, 'tube' as type,`the_geom from tubes d join fibers e on d.id = e.tube_id where e.id = 1
    union
    select gid, id, 'fiber' as type, the_geom from fibers where id = 1;

or type every select (without union) to get three layers.

share|improve this answer
    
How can I save a layer with that instrunctions? You said to "type every select". Where type the queries? The problem is, I want to select a line and it show me the way until the beggining (origin line). cables -> tubes -> fibers ---cable 1---->------tube 1---->-----fiber 1-----> this is an example of route fiber 1 origin in tube 1, and tube 1 origin in cable 1 Thank you –  user1573901 Apr 12 '13 at 16:31
    
In menue click at "Database" and choose "DB Manager". Connect to database and click at "SQL window". Here it's possible to enter SQL-queries and adding as layer. –  Wolf Apr 13 '13 at 16:59
    
It don't accept three registers from three tables, the union don't function –  user1573901 Apr 15 '13 at 9:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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