3

I am creating a fiber cable network from a distribution point to the homes, the shortest path algorithm has created the path routing for me, but the cable routes are stacked on top of each other. I am looking to write an expression to offset the lines a bit to give some visual context. The main thing here is I need this process automated, as it will be used to many home, in groups of up to 32 cables per distribution point.

Example SHP file link: https://1drv.ms/f/s!Aptt6hMRhlKQhTrY0F97MbyHwdZu?e=fDabMH

**10/11/23 - I implimented a suggested solution from she_weeds (see image below), but it takes atleast a minute to draw out all the offset lines and everytime you change zoom, the process repeats. Am I doing someting wrong or is this to be expected? Any suggestions?

enter image description here

enter image description here

This is what I have:

Using suggested solution, but it takes a long time to draw out.  Any suggestions?

This is what I am looking for, but not being created by going in and manually offsetting each line

3
  • could you share the data as it is?
    – GforGIS
    Commented Oct 10, 2023 at 3:26
  • Maybe have a look here: gis.stackexchange.com/a/426595/88814
    – Babel
    Commented Oct 10, 2023 at 10:18
  • @GforGIS added SHP file link 10/10/23
    – Joe G
    Commented Oct 10, 2023 at 15:16

3 Answers 3

4

The question of offsetting only overlapping parallel line segments has been a long standing issue. Many solutions suggest using processing tools which will actually change the geometry of your lines, but I suspect you want the geometry to stay the same, just the visualisation to be different.

Taras's answer here appeared to be the closest match, however perhaps due to changes in QGIS since 2020 I couldn't get it to work. The fundamental idea from Kazuhito's answer is the same though - (1) explode the lines into segments so you can compare identical geometries, and (2) get a count of how many lines overlap.

If you are willing to first explode your lines into segments as part of your workflow, this might work:


Sample data below - 3 lines with unique line_id value.

NOTE: In this example, Lines 1 (green) and 2 (blue) only partially overlap with Line 3 (pink), but Lines 1 and 2 do NOT have a vertex in the red circled area where Line 3 splits off. If your data is like this, please make sure you follow step 1A instead.

![enter image description here


Explode lines

Step 1. Explode your line layer into segments using Processing Tools > Explode Lines.

Step 1A. (ALTERNATIVE TO 1) If your data is like the sample shown above, instead use Processing Tools > Split Lines with Lines. You will need SAGA (from QGIS 3.28 you may need to install it as a plugin).

For some reason I also ended up with a lot of zero-length lines and one extremely short line that I couldn't clean using processing tools, so I used Select Features by Expression > round($length,3) = 0 > Delete Selected Features on the result.

Either way your result should now look like this - one feature between each section that overlaps

enter image description here


Generate offset for overlapping lines

Step 2. In the layer symbology for your exploded lines, go to Offset and use the following expression in the data defined override:

array_find(array_agg($id,geom_to_wkt($geometry)),$id)

If you would like the line stacking to follow a certain order, e.g. based on line_id (so the lowest line_id always stays the most interior), you can use this expression - change line_id to desired field:

array_find(array_agg($id,geom_to_wkt($geometry),order_by:="line_id"),$id)

You can use this in combination with categorised/graduated symbology by clicking on the main symbol as shown below, and then editing the offset in there.

enter image description here

enter image description here

Note either way the non-overlapping lines (eg in your example the lines going to the houses) are not offset.

Result:

enter image description here

3
  • Nice idea, I implimented it, but it takes atleast a minute to draw out all the poffset lines and everytime you change zoom, the process repeats. Am I doing someting wrong or is this to be expected? Recall my application will have 20+ lines overlapping
    – Joe G
    Commented Oct 11, 2023 at 15:44
  • 1
    It might depend on the size of your full dataset and your computer's specs. Maybe it isn't so great for 20+ overlapping lines. One alternative perhaps is to use the above offset expression in Field Calculator and instead create a new (static) field to store the offset value, then reference that field in your style. And when you have new features just run the expression again in Field Calculator (you could also try a Virtual Field in Field Calculator which will automatically recalculate every time but I think this might be slow as well)
    – she_weeds
    Commented Oct 13, 2023 at 1:29
  • 1
    I think that is what I ended up doing. all the hints from everyone helped push me to a custom solution
    – Joe G
    Commented Oct 13, 2023 at 1:41
2

You can create an array of offset lines using the "Array of Offset (Parallel) Lines" tool/algorithm:

enter image description here

enter image description here

enter image description here

But depending on how is your data organized you may have to do some manual work because even the line going to the house will be offset.

0

I was able to solve the issue by doing a simple offset using existing whole number values in the attribute table. To help break up the offset a little (so it didn't go too far right or left) I did this expression:

if( "FID" <=2, "FID" *-.5, "FID" *.25)

enter image description here

enter image description here

Not the most elegant solution, but it works fine for my application, basically the customer just needs to see a little offset in the cables

I created a video: QGIS FTTH - Shortest Route with Cable Offset

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.