2

I have a road network 'TR_ROAD' with EPSG:4283 crs and 1219 features. Based on geospatial theory, the road network is combination of nodes and edges.

  1. I am trying to count the number of nodes and edges in a network.
  2. Also, the I am trying to calulate the number of nodes connected to specific street/road as shown in image 2.

What I tried: Searched for exisiting answers (1, 2) but couldn,t found the relevant solution.

enter image description here

enter image description here

0

1 Answer 1

3

Count the number of nodes

Count no. of edges see below

  1. Extract the vertices of your lines - you get a point layer Vertices. Run delete duplicate geometries.

  2. Explode the lines - you get a line layer Exploded.

  3. On the Vertices layer, create a new Boolean field with Field calculator and this expression - it return 1 (true) for nodes, 0 (false) for all other vertices. The expression evaluates if 3 or more (>2) lines from the layer Exploded touch the current point: in this case, it is a node, otherwise just a simple vertex. If you also want to include end-points of lines (dangles), simply change >2 to <>2, then also points that touch just one line will be included:

     if (
         array_length (
             overlay_touches( 
                 'Exploded', 
                 buffer ($geometry,1)
             )
         )>2,
         1,
         0
     )
    
  4. If you enclose the expression in a sum() statement, you get the number of nodes - 9 in the example from the screenshot below.

Screenshot: The label (0/1) is created dynamically with the expression above:

enter image description here

Count no. of edges

This is based on the steps above:

  1. Create a new, empty multiline layer called network. Copy/paste all features from the Layer Exploded to this layer, select and merge all lines. So the whole network (all lines) consist of only one multipart feature.

  2. Use Select by expression to select all those features from the field created in step 3 above with value=1: thus get all nodes. Copy these nodes and paste them to a new point layer called only_nodes.

  3. Split the layer network with the layer only_nodes. To split a line with points, use SAGA's "Split Lines at Points" or the solution here.

  4. Based on the data and method you use, you might have to see if you don't get duplicate geometries or lines with a length of 0. Delete these and then the number of features you have in the layer corresponds to the no. of edges. You can also calculate this number using count($id).

This is the result: 17 edges, styled in different colors:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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