1

I have a layer of starting points (people's residences) and a layer of destination points (stores). I also have a roads layer with a cost field calculated from distance and speed of each segment.

What I'd like to end up with is a single layer, or multiple layers, with a cost field for each starting point to each destination point.

So if there are three starting points and three destination points, there should be 9 records in the output. Ultimately, there doesn't need to be any geometry in the output layer, it could just be a csv file. In reality I'm not even sure what type of geometry would be possible as an output.

This could also be run as a batch process, with each starting point as a separate layer. Just a thought if it simplifies things.

I've tried GRASS GIS v.net.distance but I had a bit of trouble with it. A few times it didn't execute properly, and once I ended up with a single line output layer, connecting the starting points to the closest destination. I think this tool does exactly that; finds the closest to feature from each from feature.

  • please provide a link to your data or a sample – the_darkside Feb 18 '17 at 4:12
1

The solution is to use the GRASS algorithm v.net.allpairs.

See here for documentation.

Also see Spatial distance analysis in QGIS - not all steps are necessary for my solution, but it was most helpful in figuring out how to accomplish this.

Note that the starting points (residences) and destination points (stores) will have to be merged into one layer first.

The output of v.net.allpairs will be a polyline layer with from_cat, to_cat, and cost fields. The from_cat and to_cat values represent the row number of the merged input layers. There will be one record per road segment. Each segment in a path (all records with the same from_cat and to_cat field values) will have the exact same cost value.

What I plan to do is export the data table, remove duplicate values in excel (which should leave one record per pair), and remove the following records:

  1. Store to store
  2. Residence to residence
  3. Store to residence

There will also need to be some kind of joining done afterwards to link the cat integer values to an actual name. I haven't quite figured out if there's a proper way to do this through GRASS (and possibly the v.reclass tool) but if anyone knows how to get output cat values other than a sequential (and somewhat meaningless) integer please advise.

  • For the last part, joining an actual name to the cat values, did you check out v.db.join? You can use this to link the original tables to the newly created one. – Ecodiv Feb 20 '17 at 21:39
  • I was just planning on doing a spatial join to the original layer. This would probably work just as well, maybe even better. I appreciate the suggestion! – ge0m3try Feb 20 '17 at 22:01
  • @Paulo so a spatial join would not have worked because it's points and lines (not points and points that would be on top of another). But there was no v.db.join in qgis so I had to use Join attributes table tool. Also want to point out that if you save a v.net.allpairs as a temporary layer and try to join that way, there will be a bunch of extra fields in that layer that aren't really there. – ge0m3try Feb 21 '17 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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