Outline for a spline – but with a dashed pen?

Dear Gurus,

When plotting lines over colorful background (i.e. elevation model) the line can be sometimes hard to see due to the color of the background and the pen used. It is not always possible to choose a pen color which has adequate contrast to the background.

Therefore I’m currently experimenting with ways to give the lines an outline. This is rather straightforward with solid lines but more difficult with dashed or dotted lines. I didn’t find an easy solution. Maybe you have some input for me on how to achieve this?

Here is what I got so far:

  • The goal here is to have a 4p wide line (white) with a 0.5p wide outline (black) making the whole thing 5p wide including said outline.

  • All lines run from bottom right to upper left.

  • All lines end “in” a dash to see the behavior when a dash is truncated.

How it was achieved:

  1. Is just a solid white line on top of a solid black line. Minor ugliness are the open ends.

  2. basically the same as 1 but used the build-in - option for a dashed line. Results in different gait for white and black line. Not usable.

  3. Made the dash pattern myself to have control over the length of dashes and gaps. The black dashes are as long as the white dashes. Way better than 2 but the open ends are somewhat ugly.

  4. Black dashes are 1p (2 x outline width) longer, to compensate the black gaps are 1p smaller. The white dash and gap remains the same but with a 0.5p offset to allow for the outline at the beginning. Works nicely except for the end of line which is just cut off.

  5. To get the black line to extend beyond the terminating coordinate I came up with the use of --PS_LINE_CAP=square for the black line. The dash length and gap width needed adjustment to keep the dimensions the same. The offset of the white line needed some love as well. All that for a nicer look of the end. Found it to be uglier than 4.

  6. basically the same as 4 but --PS_LINE_CAP=round was used. Generally working fine but the black border bulges outwards at the dash ends. Except for the last cutoff dash. Not sure why.

  7. Pretty much the same as 6 but with different offsets. I don’t fully understand why those multiples work. Looks good.

Conclusion:

There is – in my understanding – no build-in way in GMT to get lines with outlines. My experimentation showed some usable ways (examples 4 and 7) but they are rather difficult as the offsets are dependent on line width, dash and gap length.

Is there an easier way to achieve this? Did I miss something in the docs? Your input is greatly appreciated.

All the best,
Kristof

And I forgot to include the example code:

cat > path_1.txt << END
 1.8 -0.7
 0.2  1.2
-0.8  0.9
-1.8  1.3
END

cat > path_2.txt << END
 1.8 -0.9
 0.2  1
-0.8  0.7
-1.8  1.1
END

cat > path_3.txt << END
 1.8 -1.1
 0.2  0.8
-0.8  0.5
-1.8  0.9
END

cat > path_4.txt << END
 1.8 -1.3
 0.2  0.6
-0.8  0.3
-1.8  0.7
END

cat > path_5.txt << END
 1.8 -1.5
 0.2  0.4
-0.8  0.1
-1.8  0.5
END

cat > path_6.txt << END
 1.8 -1.7
 0.2  0.2
-0.8 -0.1
-1.8  0.3
END

cat > path_7.txt << END
 1.8 -1.9
 0.2  0
-0.8 -0.3
-1.8  0.1
END

cat > noise.txt << END
> -W60p,black
-1.5 -1.5
-0.5  1.5
> -W60p,white
-0.5 -1.5
 0.5  1.5
> -W60p,red
 0.5 -1.5
 1.5  1.5
END

cat > numbers.txt << END
-1.9  0.1 7
-1.9  0.3 6
-1.9  0.5 5
-1.9  0.7 4
-1.9  0.9 3
-1.9  1.1 2
-1.9  1.3 1
#
 1.9 -1.9 7
 1.9 -1.7 6
 1.9 -1.5 5
 1.9 -1.3 4
 1.9 -1.1 3
 1.9 -0.9 2
 1.9 -0.7 1
END


gmt begin outlines
  gmt basemap -R-2/2/-2/2 -JM6i -Bafg1 --PS_PAGE_COLOR=lightgrey
  gmt plot noise.txt
  gmt text numbers.txt
  # solid
  gmt plot path_1.txt -W5p,black+s
  gmt plot path_1.txt -W4p,white+s
  # dash build in
  gmt plot path_2.txt -W5p,black,-+s
  gmt plot path_2.txt -W4p,white,-+s
  # dash home made
  gmt plot path_3.txt -W5p,black,32_16+s
  gmt plot path_3.txt -W4p,white,32_16+s
  # dash home made
  gmt plot path_4.txt -W5p,black,33_15+s
  gmt plot path_4.txt -W4p,white,32_16:-0.5+s
  # dash home made
  gmt plot path_5.txt -W5p,black,28_20:-2.5+s --PS_LINE_CAP=square
  gmt plot path_5.txt -W4p,white,32_16:-0.5+s
  # dash home made
  gmt plot path_6.txt -W5p,black,33_15+s --PS_LINE_CAP=round
  gmt plot path_6.txt -W4p,white,32_16:-0.5+s --PS_LINE_CAP=round
  # dash home made
  gmt plot path_7.txt -W5p,black,32.125_15.875+s --PS_LINE_CAP=round
  gmt plot path_7.txt -W4p,white,32_16:-0.0625+s --PS_LINE_CAP=round
gmt end show

Stepping away for a few hours gave me some new ideas:

Have a look at at lines 5b & 7b which are improved versions of lines 5 & 7.

Pen style 5b is rather straightforward: Just some playing around with --PS_LINE_CAP=square and compensation for the increase in length by using +o, decreasing the dash length and increasing the gap width.

7b is basically the same as 5b – I still fail to fully understand those correction factors.

The question remains: Is there an easier way to achieve this?

Example code for playing around:

cat > path_1.txt << END
 1.8 -0.3
 0.2  1.6
-0.8  1.3
-1.8  1.7
END

cat > path_2.txt << END
 1.8 -0.5
 0.2  1.4
-0.8  1.1
-1.8  1.5
END

cat > path_3.txt << END
 1.8 -0.7
 0.2  1.2
-0.8  0.9
-1.8  1.3
END

cat > path_4.txt << END
 1.8 -0.9
 0.2  1
-0.8  0.7
-1.8  1.1
END

cat > path_5.txt << END
 1.8 -1.1
 0.2  0.8
-0.8  0.5
-1.8  0.9
END

cat > path_6.txt << END
 1.8 -1.3
 0.2  0.6
-0.8  0.3
-1.8  0.7
END

cat > path_7.txt << END
 1.8 -1.5
 0.2  0.4
-0.8  0.1
-1.8  0.5
END

cat > path_8.txt << END
 1.8 -1.7
 0.2  0.2
-0.8 -0.1
-1.8  0.3
END

cat > path_9.txt << END
 1.8 -1.9
 0.2  0
-0.8 -0.3
-1.8  0.1
END

cat > path_10.txt << END
 0.2 -0.5
-1.8 -0.5
END

cat > path_11.txt << END
 0.2 -0.7
-1.8 -0.7
END

cat > path_12.txt << END
 0.2 -0.9
-1.8 -0.9
END

cat > noise.txt << END
> -W60p,black
-1.5 -1.5
-0.5  1.5
> -W60p,white
-0.5 -1.5
 0.5  1.5
> -W60p,red
 0.5 -1.5
 1.5  1.5
> -W0.5p,red
-1.8 -1
-1.8  1.8
> -W0.5p,red
 1.8 -2
 1.8 -0.2
> -W0.5p,red
0.2 -0.4
0.2 -1
END

cat > numbers.txt << END
-1.9 -0.9 7b
-1.9 -0.7 5b
-1.9 -0.5 3
-1.9  0.1 7b
-1.9  0.3 7
-1.9  0.5 6
-1.9  0.7 5b
-1.9  0.9 5
-1.9  1.1 4
-1.9  1.3 3
-1.9  1.5 2
-1.9  1.7 1
#
 0.3 -0.9 7b
 0.3 -0.7 5b
 0.3 -0.5 3
 1.9 -1.9 7b
 1.9 -1.7 7
 1.9 -1.5 6
 1.9 -1.3 5b
 1.9 -1.1 5
 1.9 -0.9 4
 1.9 -0.7 3
 1.9 -0.5 2
 1.9 -0.3 1
END


gmt begin outlines
  gmt basemap -R-2/2/-2/2 -JM6i -Bafg1 --PS_PAGE_COLOR=lightgrey
  gmt plot noise.txt
  gmt text numbers.txt
  # 1
  gmt plot path_1.txt -W5p,black+s
  gmt plot path_1.txt -W4p,white+s
  # 2
  gmt plot path_2.txt -W5p,black,-+s
  gmt plot path_2.txt -W4p,white,-+s
  # 3
  gmt plot path_3.txt -W5p,black,32_16+s
  gmt plot path_3.txt -W4p,white,32_16+s
  # 4
  gmt plot path_4.txt -W5p,black,33_15+s
  gmt plot path_4.txt -W4p,white,32_16:-0.5+s
  # 5
  gmt plot path_5.txt -W5p,black,28_20:-2.5+s --PS_LINE_CAP=square
  gmt plot path_5.txt -W4p,white,32_16:-0.5+s
  # 5b
  gmt plot path_6.txt -W5p,black,27_21+s+o2p --PS_LINE_CAP=square
  gmt plot path_6.txt -W4p,white,27_21+s+o2p --PS_LINE_CAP=square
  # 6
  gmt plot path_7.txt -W5p,black,33_15+s --PS_LINE_CAP=round
  gmt plot path_7.txt -W4p,white,32_16:-0.5+s --PS_LINE_CAP=round
  # 7
  gmt plot path_8.txt -W5p,black,32.125_15.875+s --PS_LINE_CAP=round
  gmt plot path_8.txt -W4p,white,32_16:-0.0625+s --PS_LINE_CAP=round
  # 7b
  gmt plot path_9.txt -W5p,black,27.125_20.875+s+o2p --PS_LINE_CAP=round
  gmt plot path_9.txt -W4p,white,27_21:-0.0625+s+o2p --PS_LINE_CAP=round
  # 3 straight
  gmt plot path_10.txt -W5p,black,32_16
  gmt plot path_10.txt -W4p,white,32_16
  # 5b straight
  gmt plot path_11.txt -W5p,black,27_21+o2p --PS_LINE_CAP=square
  gmt plot path_11.txt -W4p,white,27_21+o2p --PS_LINE_CAP=square
  # 7b straight
  gmt plot path_12.txt -W5p,black,27.125_20.875+o2p --PS_LINE_CAP=round
  gmt plot path_12.txt -W4p,white,27_21:-0.0625+o2p --PS_LINE_CAP=round
gmt end show