I have a layer with (several thousand) addresses, for every one I need to find the number of shops (155 total) within a 400 meter road network. Because of the large number I need to find a tool to use here but I can only find ones where it gives me the closest one, but not the distance from all the addresses to all the shops (or at least the ones within 400 meters). How do I solve this?


I guess your points (addresses as well as shops) are snapped to the network - otherwise see at the bottom of this solution how to do this. Be sure both your shop and address layer contain a unique id for identification.

  1. Use Menu Processing / Toolbox / Network Analysis / Service area (from layer), set the line used as network layer and the address layer as Vector layer with start points, select shortest for Path type to calculate and for Travel cost (distance for "Shortest", time for "Fastest") set 400.

  2. You get a line-layer with a line for each point that represents that part of the network reachable within max. 400m. Apply a buffer (very small like 0.1 m) around these lines (Menu Vector / Geoprocessing tools / Buffer) so that the shops for sure foll inside the buffer.

  3. Use Field calculator to create a new field shops_within_400m on the buffer layer using text field format that is long enough with this expression: array_to_string (overlay_intersects( 'shop', shop_id)) (change shop and shop_id to the names of your layer and it's id field). For overlay_intersects() you need QGIS 3.16 or higher. Now each buffer has assigned a list of shops that is reachable in max. 400m over the network form the respective address.

  4. If you want, join the attribute created to the address layer. Use Field calculator to create a new field with this expression, where you replace buffer with the name of your buffer-layer and id with the name of the unique id of the address-layer: attribute (get_feature_by_id ('buffer',id),'shop_within_400m')

Screenshot, showing the result: network (black lines), shops (red dots, labeled with their shop_id) and addresses (blue dots), labeled with the field created in step 4 that shows the id's of the shop within 200 m (the value I used here - see the scale at the top of how long 200 m is on this canvas). One example is highlighted with red ellipses (blue address plus corresponding shops within 200m), with the orange service area showing the part of the network reachable in max. 200m:

enter image description here

  • Sometimes I am wondering how many templates you have to create for each different question. You probably have plenty of them now, do not you :)
    – Taras
    Jul 9 at 8:00
  • Hahaha, not yet. Even if problems are similar, details of the answers are too different to be able to cover all that by a template.
    – Babel
    Jul 9 at 14:34

To get only the distance from each address to each shop, you can use QNEAT3-Plugin with the algorithm OD Matrix from Layers as Table (m:n) (see documentation). You can select it from Menu Processing / Toolbar when the plugin is installed. Select Network layer, From-Point layer (addresses) with unique point ID field as well as To-Point layer (shops), again with unique point ID field. For optimization criteria, use Shortest path (distance optimization).

When you run the tool, you get a table with the distance from each address-point to each shop-point, see screenshot. By the way: entry-cost and exit-cost is the bee-line distance from the point to the network (thus the distance to the nearest point of the network, if the point do not lie on the network).

enter image description here

  • 1
    thanks for the explaination of entry- and exit-cost, I found nothing in plugin-doku
    – Kurt
    Nov 10 at 22:00

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.