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.
Menu Processing / Toolbox / Network Analysis / Service area (from layer), set the line used as
network layerand the
Vector layer with start points, select
Path type to calculateand for
Travel cost (distance for "Shortest", time for "Fastest")set 400.
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.
Use Field calculator to create a new field
shops_within_400mon the buffer layer using text field format that is long enough with this expression:
array_to_string (overlay_intersects( 'shop', shop_id))(change
shop_idto 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.
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
bufferwith the name of your buffer-layer and
idwith the name of the unique id of the
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:
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
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).