4

Note: This is basically the same question that I asked before in Summing attribute values of overlapping polyline portions in ArcGIS Desktop?, but this time, I'm trying to solve the same problem using QGIS. The reason is, I need to be able to teach/explain the solution to users in a developing country who cannot afford ArcGIS. I'm not an expert in QGIS either. So here is the question:

I have polylines of 80+ bus routes operating in a city. The polylines have attribute values for the number of passengers, number of trips, etc. Many of the polylines overlap at certain areas of the road network.

enter image description here

For example in the image above, the Green Route has 1,000 passengers and travels 20 trips a day while the Orange Route has 500 passengers and 10 trips a day. I'd like to have a final shapefile with data on 1,500 passengers and 30 trips (overlapping areas), but also data on the 1,000 passengers with 20 trips and 500 passengers with 10 trips (non-overlapping areas). This is just a simple example with two routes but I have 80+ in all that overlap in many locations with each other.

What I have done so far:

Step 1: Run "Merge vector layers" to combine all the individual polylines into one shapefile.

What I want to do next:

Step 2: I want to cut/split the overlapping features exactly where the overlaps occur.

Step 3: I want to fuse/merge/join (whatever the correct term is in QGIS) all overlapping line segments, AND add up their numbers of passengers and trips into the resulting feature. 1,500 passengers and 30 trips in the above example.

Step 4: Lastly, I want to, somehow be able to find out which routes whose values have been added together. In the above example, a column saying "Green, Orange" would be nice, but doesn't matter if I get "GreenOrange".

What I have tried so far for Steps 2, 3 and 4:

Multipart to singleparts

Tried to split all overlapping segments, but the splits did not occur exactly where the overlaps start and end.

Line-polygon intersection

Created a polygon that covers entire area to try to get all overlapping segments split. Splits did not occur exactly where the overlaps start and end.

Aggregate

Seems to be able to sum up the numbers of passengers and trips, and also able to concatenate the Route Name, but the result is only one feature. In the example, I need to have 5 features as the result.

Join attributes by location

Referring to Merging overlapping lines into one line. QGIS. Requires an Input Layer and a Join Layer. I only have one layer since Step 1, so this can't be it, unless I'm doing it wrong from Step 1.

Dissolve

This just returns the separated lines into one, back to Step 1. I was hoping that it dissolve the overlapping segments.

Collect geometries

Same as above.

EDIT:

Sample Data:

Shp file, Shx file, Dbf file

enter image description here

Result of Step 2: v.clean

Shp file, Shx file, Dbf file

enter image description here

Result of Step 3: Aggregate

Shp file, Shx file, Dbf file

enter image description here

Final Result, Step 4: Delete Duplicate Geometries

Shp file, Shx file, Dbf file

enter image description here

In above image I selected the overlapping line segments. This is how the map looks like:

enter image description here

Two line segments North of the loop are supposed to overlap, but they are now missing. Only a tiny chunk is left.

  • Any chance of a simple sample dataset? It would make it much easier for everyone who wants to help you since it saves us all having to create something from scratch. – Spacedman Sep 5 '18 at 6:54
  • @Spacedman Please see attached sample data. I noticed that Step 2 didn't actually work so I had to use ArcGIS to prepare this sample data. – DXV Sep 5 '18 at 8:11
1

This is just a follow-up on your Aggregate strategy for the Steps 3/4.

(1) Aggregate

Create three new fields by the Field calculator.

  • total_trip by sum("No_of_Trip", group_by:= geom_to_wkt($geometry))
  • total_pax by sum("No_of_Pax", group_by:= geom_to_wkt($geometry))
  • routes by concatenate(to_string("Route_No"), group_by:= geom_to_wkt($geometry), concatenator:=', ')

You will obtain table below:

enter image description here

(2) Delete duplicate geometries

Row 5 and 6 are ovelapping. Delete one of them by running Delete duplicate geometries tool (in QGIS processing toolbox | QGIS geoalgorithms | Vector general tools).

It will return a new layer Cleaned (below), without row 6 of previous data (above).

enter image description here


[Edit] as per request for the Step-2:

I would suggest GRASS v.clean with break option as the cleaning tool. It can be found in QGIS processing toolbox | GRASS GIS7 | Vector.

It is similar to QGIS Explode lines tool, but unlike Explode lines which breaks all segments of the polyline, v.clean cuts the line only at intersecting nodes.

It does not specifically search for duplicates, so it may not be perfect.

  • Thank you so much! Can you please also advise me on Step 2? "Multipart to singleparts" or "Line-polygon intersection" did not split the features neatly where the overlaps start and end. I had to use ArcGIS for this, but would like to know how to do it in QGIS. – DXV Sep 6 '18 at 1:45
  • @DXV I recommend v.clean to work on your Step 2. It may not be ideal, but it usually gives me satisfactory output. Let me know if it does not give you what you need. – Kazuhito Sep 6 '18 at 4:53
  • 1
    Thanks again Kazuhito! I run v.clean + break, then proceeded to the rest of the steps. I noticed that the lines are split into multiple, shorter segments so I now have 12 features instead of 5. I do not mind this as they still contain the desired values. However, a big portion of the overlapping segment (North of the loop) has also been deleted in the final result, so this will be an issue when I work with the complete data set. Any idea on why this happened? I appreciate the help. – DXV Sep 6 '18 at 7:38
  • @DXV Unfortunately I could not reproduce the situation you've seen (missing loop segment) with my quick test on your data. Could you post a screenshot or upload the problematic files? – Kazuhito Sep 6 '18 at 9:48
  • this is what I did this morning. First I lost the problematic files (temporary files) so I repeated the process but I was surprised t get the desired results! I thought problem solved, but I repeated it one more time but this time I got the same problem as yesterday. I made sure to do exactly the same procedures, but got different results. I added the files for Steps 2-4 with screen shots. Please take a look. – DXV Sep 7 '18 at 2:31

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.