Saturday, 15 August 2015

qgis - How to generate line segments between all points


How do I create a vector layer with a network of line segments drawn between every point in another vector layer? Basically, I am trying to create something similar to a hub/spoke network, except that instead of having a single hub and the other points are destinations, I would like every point to be treated as a hub with a direct connection to every other point.


I have managed to get the hub lines from one point to every other using the MMQGIS plugin "Hub Lines" module, but it seems that I would need to re-run it for each individual point. Is there a way to just do it all in one go? It may be worth noting that I don't need to know the distances between the points; I'm looking for the azimuths.


I'd prefer to do this in QGIS, but I've got some experience with SAGA and GRASS as well.



Answer



My technique using the FlowMapper plugin to connect all the points with each other:




  1. In QGIS, save the point layer to a CSV file, checked "skip attribute creation", selected tab delimiter- only the coordinates should be exported. (I'll call this file A)

  2. Change the file suffix from .csv to .txt

  3. Open the file in a text editor and delete “X” and “Y” from the top (save and exit)

  4. Create a dummy magnitude file in excel/libreoffice calc/whatever. The dummy file must have as many rows and columns as there are points in the point layer (20x20, in my case)

  5. Save that file as a .csv with either space or tab delimiter. (I'll call this file B)

  6. Convert the .csv to a .txt

  7. In QGIS, in the FlowMapper plugin menu, select “Generate flow lines and nodes”.

  8. Select file A.txt for the node coordinates

  9. Select file B.txt for the flow magnitudes


  10. Select “gross” for “flow type”

  11. Enter a save file name/location for the output line shapefile

  12. Click “OK”.
    The resulting line layer has several attributes that aren't immediately useful to what I'm doing, so I deleted them, but they may be useful to others.


It's kind of a clunky workflow, but without learning PostGIS or Spatialite, it's the best I've managed to do (and it gets the exact result I was hoping for).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...