Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

GMT_Appendix_O.tex 20 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
  1. %------------------------------------------
  2. % $Id$
  3. %
  4. % The GMT Documentation Project
  5. % Copyright (c) 2000-2012.
  6. % P. Wessel, W. H. F. Smith, R. Scharroo, and J. Luis
  7. %------------------------------------------
  8. %
  9. \chapter{Annotation of Contours and ``Quoted Lines''}
  10. \label{app:O}
  11. \thispagestyle{headings}
  12. The \GMT\ programs \GMTprog{grdcontour} (for data given as 2-dimensional grids)
  13. and \GMTprog{pscontour} (for \emph{x,y,z} tables) allow
  14. for contouring of data sets, while \GMTprog{psxy} and \GMTprog{psxyz}
  15. can plot lines based on \emph{x,y}- and \emph{x,y,z}-tables, respectively.
  16. In both cases it may be necessary to attach labels to
  17. these lines. Clever or optimal placements of labels is a very difficult
  18. topic, and \GMT\ provides several algorithms for this placement as well
  19. as complete freedom in specifying the attributes of the labels.
  20. Because of the richness of these choices we present this Appendix which
  21. summarizes the various options and gives several examples of their use.
  22. \section{Label Placement}
  23. While the previous \GMT\ versions 1--3 allowed for a single algorithm that
  24. determined where labels would be placed, \GMT\ 4 allows for five different
  25. algorithms. Furthermore, a new ``symbol'' option (\Opt{Sq} for ``quoted line'')
  26. has been added to \GMTprog{psxy} and \GMTprog{psxyz} and hence the new label
  27. placement mechanisms apply to those programs as well. The contouring programs
  28. expect the algorithm to be specified as arguments to \Opt{G} while the line plotting
  29. programs expect the same arguments to follow \Opt{Sq}. The information appended
  30. to these options is the same in both cases and is of the form [\textbf{code}]\emph{info}.
  31. The five algorithms correspond to the five codes below (some codes will appear in both
  32. upper and lower case; they share the same algorithm but differ in some other ways).
  33. In what follows, the phrase ``line segment'' is taken to mean either a contour or a line
  34. to be labeled. The codes are:
  35. \begin{description}
  36. \item [d:] Full syntax is \textbf{d}\emph{dist}[\textbf{c$|$i$|$p}][/\emph{frac}].
  37. Place labels according to the distance measured along the projected line on the map. Append the
  38. unit you want to measure distances in [Default is taken from \textbf{PROJ\_LENGTH\_UNIT}].
  39. Starting at the beginning of a line, place labels every \emph{dist} increment of
  40. distance along the line. To ensure that closed lines whose total length is less
  41. than \emph{dist} get annotated, we may append \emph{frac} which will place the first
  42. label at the distance $d =$ \emph{dist} $\times$ \emph{frac} from the start of a closed
  43. line (and every \emph{dist} thereafter). If not given, \emph{frac} defaults to 0.25.
  44. \item [D:] Full syntax is \textbf{D}\emph{dist}[\textbf{d$|$m$|$s$|$e$|$f$|$k$|$M$|$n}][/\emph{frac}].
  45. This option is similar to \textbf{d} except the original data must be referred to geographic
  46. coordinates (and a map projection must have been chosen) and actual Earth\footnote{or whatever
  47. planet we are dealing with.} surface distances along the lines are considered. Append the
  48. unit you want to measure distances in; choose among arc \textbf{d}egree, \textbf{m}minute, and \textbf{s}second,
  49. or m\textbf{e}ter [Default], \textbf{f}eet, \textbf{k}ilometer, statute \textbf{M}iles, or \textbf{n}autical miles. Other aspects are similar to code \textbf{d}.
  50. \item [f:] Full syntax is \textbf{f}\emph{fix.d}[/\emph{slop}[\textbf{c$|$i$|$p}]]. Here, an ASCII file \emph{fix.d} is
  51. given which must contain records whose first two columns hold the coordinates of points along
  52. the lines at which locations the labels should be placed. Labels will only be placed if the coordinates
  53. match the line coordinates to within a distance of \emph{slop} (append unit or we use \textbf{PROJ\_LENGTH\_UNIT}).
  54. The default \emph{slop} is zero, meaning only exact coordinate matches will do.
  55. \item [l:] Full syntax is \textbf{l}\emph{line1}[,\emph{line2}[, ...]]. One or more straight line segments
  56. are specified separated by commas, and labels will be placed at the intersections between these lines and
  57. our line segments. Each \emph{line} specification implies a \emph{start} and \emph{stop} point, each
  58. corresponding to a coordinate pair. These pairs can be regular coordinate pairs (i.e., longitude/latitude separated by a slash), or they
  59. can be two-character codes that refer to predetermined points relative to the map region. These codes
  60. are taken from the \GMTprog{pstext} justification keys [\textbf{L$|$C$|$R}][\textbf{B$|$M$|$T}] so that the first
  61. character determines the $x$-coordinate and the second determines the $y$-coordinate. In \GMTprog{grdcontour},
  62. you can also use the two codes \textbf{Z+} and \textbf{Z-} as shorthands for the location of the grid's global
  63. maximum and minimum, respectively. For example, the \emph{line} \textbf{LT}/\textbf{RB} is a diagonal from the
  64. upper left to the lower right map corner, while \textbf{Z-}/135W/15S is a line from the grid minimum to the point
  65. (135\DS W, 15\DS S).
  66. \item [L:] Same as \textbf{l} except we will treat the lines given as great circle start/stop coordinates and fill in
  67. the points between before looking for intersections.
  68. \item [n:] Full syntax is \textbf{n}\emph{number}[/\emph{minlength}[\textbf{c$|$i$|$p}]]. Place
  69. \emph{number} of labels along each line regardless of total line length. The line is divided into \emph{number}
  70. segments and the labels are placed at the centers of these segments. Optionally, you may give a \emph{minlength}
  71. distance to ensure that no labels are placed closer than this distance to its neighbors.
  72. \item [N:] Full syntax is \textbf{N}\emph{number}[/\emph{minlength}[\textbf{c$|$i$|$p}]]. Similar to
  73. code \textbf{n} but here labels are placed at the ends of each segment (for \emph{number} $\geq 2$). A special
  74. case arises for \emph{number} $= 1$ when a single label will be placed according to the sign of \emph{number}:
  75. $-1$ places one label justified at the start of the line, while $+1$ places one label justified at the end of the line.
  76. \item [x:] Full syntax is \textbf{x}\emph{cross.d}. Here, an ASCII file \emph{cross.d} is
  77. a multi-segment file whose lines will intersect our segment lines; labels will be placed at these intersections.
  78. \item [X:] Same as \textbf{x} except we treat the lines given as great circle start/stop coordinates and fill in the
  79. points between before looking for intersections.
  80. \end{description}
  81. Only one algorithm can be specified at any given time.
  82. \section{Label Attributes}
  83. Determining where to place labels is half the battle. The other half is to specify exactly
  84. what are the attributes of the labels. It turns out that there are quite a few possible
  85. attributes that we may want to control, hence understanding how to specify these attributes
  86. becomes important. In the contouring programs, one or more attributes may be appended to the
  87. \Opt{A} option using the format +\emph{code}[\emph{args}] for each attribute, whereas for the line
  88. plotting programs these attributes are appended to the \Opt{Sq} option following a colon (:)
  89. that separates the label codes from the placement algorithm. Several of the attributes do not
  90. apply to contours so we start off with listing those that apply universally. These codes are:
  91. \begin{description}
  92. \item [+a:] Controls the angle of the label relative to the angle of the line. Append \textbf{n}
  93. for normal to the line, give a fixed \emph{angle} measured counter-clockwise relative to the
  94. horizontal. or append \textbf{p} for parallel to the line [Default]. If using \GMTprog{grdcontour}
  95. the latter option you may further append \textbf{u} or \textbf{d} to get annotations whose upper edge
  96. always face the next higher or lower contour line.
  97. \item [+c:] Surrounding each label is an imaginary label ``textbox'' which defines a region in
  98. which no segment lines should be visible. The initial box provides an exact fit to the enclosed
  99. text but clearance may be extended in both the horizontal and vertical directions (relative to the label
  100. baseline) by the given amounts. If these should be different amounts please separate them by
  101. a slash; otherwise the single value applies to both directions. Append the distance units of
  102. your choice (\textbf{c$|$i$|$m$|$p}), or give \% to indicate that the clearance should be this
  103. fixed percentage of the label font size in use. The default is 15\%.
  104. \item [+d:] Debug mode. This is useful when testing contour placement as it will draw the normally
  105. invisible helper lines and points in the label placement algorithms above.
  106. \item [+d:] Delayed mode, to delay the plotting of the text as text clipping is set instead.
  107. \item [+f:] Specifies the desired label font. See \GMTprog{pstext} for font names or numbers. The
  108. default font is given by \textbf{FONT\_ANNOT\_PRIMARY}.
  109. \item [+g:] Selects opaque rather than the default transparent text boxes. You may optionally append
  110. the color you want to fill the label boxes; the default is the same as \textbf{PS\_PAGE\_COLOR}.
  111. \item [+j:] Selects the justification of the label relative to the placement points determined
  112. above. Normally this is center/mid justified (\textbf{CM} in \GMTprog{pstext} justification parlance) and
  113. this is indeed the default setting. Override by using this option and append another justification
  114. key code from [\textbf{L$|$C$|$R}][\textbf{B$|$M$|$T}]. Note for curved text (\textbf{+v}) only vertical
  115. justification will be affected.
  116. \item [+k:] Sets the color of the text labels, which otherwise defaults to that given by \textbf{COLOR\_BACKGROUND}.
  117. \item [+o:] Request a rounded, rectangular label box shape; the default is rectangular. This is only
  118. manifested if the box is filled or outlined, neither of which is implied by this option alone (see \textbf{+g}
  119. and \textbf{+p}). As this option only applies to straight text, it is ignored if \textbf{+v} is given.
  120. \item [+p:] Selects the drawing of the label box outline; append your preferred \emph{pen} unless you
  121. want the default \GMT\ pen [0.25p,black].
  122. \item [+r:] Do not place labels at points along the line whose local radius of curvature falls below
  123. the given threshold value. Append the radius unit of your choice (\textbf{c$|$i$|$p}) [Default is 0].
  124. \item [+s:] Change the font size of the labels, which by default is 9 points.
  125. \item [+u:] Append the chosen \emph{unit} to the label. Normally a space will separate the label
  126. and the unit. If you want to close this gap, append a \emph{unit} that begins with a hyphen (--).
  127. If you are contouring with \GMTprog{grdcontour} and you specify this option without appending a unit, the unit will be taken from the
  128. $z$-unit attribute of the grid header.
  129. \item [+v:] Place curved labels that follow the wiggles of the line segments. This is especially
  130. useful if the labels are long relative to the length-scale of the wiggles. The default places labels
  131. on an invisible straight line at the angle determined.
  132. \item [+w:] The angle of the line at the point of straight label placement is calculated by a least-squares
  133. fit to the \emph{width} closest points. If not specified, \emph{width} defaults to 10.
  134. \item [+=:] Similar in most regards to \textbf{+u} but applies instead to a label \emph{prefix} which
  135. you must append.
  136. \end{description}
  137. For contours, the label will be the value of the contour (possibly modified by \textbf{+u} or \textbf{+=}).
  138. However, for quoted lines other options apply:
  139. \begin{description}
  140. \item [+l:] Append a fixed \emph{label} that will be placed at all label locations. If the label contains
  141. spaces you must place it inside matching quotes.
  142. \item [+L:] Append a code \emph{flag} that will determine the label. Available codes are:
  143. \begin{description}
  144. \item [+Lh:] Take the label from the current multi-segment header (hence it is assumed that the
  145. input line segments are given in the multi-segment file format; if not we pick the single label
  146. from the file's header record). We first scan the header for an embedded
  147. \Opt{L}\emph{label} option; if none is found we instead use the first word following the segment marker [$>$].
  148. \item [+Ld:] Take the Cartesian plot distances along the line as the label; append \textbf{c$|$i$|$p}
  149. as the unit [Default is \textbf{PROJ\_LENGTH\_UNIT}]. The label will be formatted according to the \textbf{FORMAT\_FLOAT\_OUT}
  150. string, \emph{unless} label placement was determined from map distances along the segment lines, in which
  151. case we determine the appropriate format from the distance value itself.
  152. \item [+LD:] Calculate actual Earth surface distances and use the distance at the label placement point as
  153. the label; append \textbf{d$|$e$|$f$|$k$|$m$|$M$|$n$|$s} to specify the unit [If not given we default to \textbf{d}egrees,
  154. \emph{unless} label placement was determined from map distances along the segment lines, in which case we
  155. use the same unit specified for that algorithm]. Requires a map projection to be used.
  156. \item [+Lf:] Use all text after the 2nd column in the fixed label location file \emph{fix.d} as labels.
  157. This choice obviously requires the fixed label location algorithm (code \textbf{f}) to be in effect.
  158. \item [+Ln:] Use the running number of the current multi-segment as label.
  159. \item [+LN:] Use a slash-separated combination of the current file number and the current multi-segment number as label.
  160. \item [+Lx:] As \textbf{h} but use the multi-segment headers in the \emph{cross.d} file instead.
  161. This choice obviously requires the crossing segments location algorithm (code \textbf{x$|$X}) to be in effect.
  162. \end{description}
  163. \end{description}
  164. \section{Examples of Contour Label Placement}
  165. We will demonstrate the use of these options with a few simple examples.
  166. First, we will contour a subset of the global geoid data used in \GMT\ Example 01;
  167. the region selected encompasses the world's strongest ``geoid dipole'': the Indian Low
  168. and the New Guinea High.
  169. \subsection{Equidistant labels}
  170. Our first example uses the default placement algorithm. Because of the size
  171. of the map we request contour labels every 1.5 inches along the lines:
  172. \script{GMT_App_O_1}
  173. \noindent
  174. As seen in Figure~\ref{fig:GMT_App_O_1}, the contours are placed rather arbitrary.
  175. The string of contours for $-40$ to $60$ align well but that is a fortuitous
  176. consequence of reaching the 1.5 inch distance from the start at the bottom of the map.
  177. \GMTfig[H]{GMT_App_O_1}{Equidistant contour label placement with \Opt{Gd}, the only algorithm
  178. available in previous \gmt\ versions.}
  179. \subsection{Fixed number of labels}
  180. We now exercise the option for specifying exactly how many labels each contour line
  181. should have:
  182. \script{GMT_App_O_2}
  183. \noindent
  184. By selecting only one label per contour and requiring that labels only be placed on
  185. contour lines whose length exceed 1 inch, we achieve the effect shown in Figure~\ref{fig:GMT_App_O_2}.
  186. \GMTfig[H]{GMT_App_O_2}{Placing one label per contour that exceed 1 inch in length,
  187. centered on the segment with \Opt{Gn}.}
  188. \subsection{Prescribed label placements}
  189. Here, we specify four points where we would like contour labels to be placed. Our points
  190. are not exactly on the contour lines so we give a nonzero ``slop'' to be used in the
  191. distance calculations: The point on the contour closest to our fixed points and within
  192. the given maximum distance will host the label.
  193. \script{GMT_App_O_3}
  194. \noindent
  195. The angle of the label is evaluated from the contour line geometry, and the final result
  196. is shown in Figure~\ref{fig:GMT_App_O_3}.
  197. \GMTfig[H]{GMT_App_O_3}{Four labels are positioned on the points along the contours that
  198. are closest to the locations given in the file \protect\filename{fix.d} in the \protect\Opt{Gf} option.}
  199. To aid in understanding the algorithm we chose to specify ``debug'' mode (\textbf{+d}) which placed a
  200. small circle at each of the fixed points.
  201. \subsection{Label placement at simple line intersections}
  202. Often, it will suffice to place contours at the imaginary intersections between the
  203. contour lines and a well-placed straight line segment. The \Opt{Gl} or \Opt{GL}
  204. algorithms work well in those cases:
  205. \script{GMT_App_O_4}
  206. \noindent
  207. The obvious choice in this example is to specify a great circle between the high and
  208. the low, thus placing all labels between these extrema.
  209. \GMTfig[H]{GMT_App_O_4}{Labels are placed at the intersections between contours and the
  210. great circle specified in the \protect\Opt{GL} option.}
  211. \noindent
  212. The thin debug line in Figure~\ref{fig:GMT_App_O_4} shows the great circle and the
  213. intersections where labels are plotted. Note that any number of such lines could be specified;
  214. here we are content with just one.
  215. \subsection{Label placement at general line intersections}
  216. If (1) the number of intersecting straight line segments needed to pick the desired label
  217. positions becomes too large to be given conveniently on the command line, or (2) we have
  218. another data set or lines whose intersections we wish to use, the general crossing
  219. algorithm makes more sense:
  220. \script{GMT_App_O_5}
  221. \GMTfig[H]{GMT_App_O_5}{Labels are placed at the intersections between contours and the
  222. multi-segment lines specified in the \protect\Opt{GX} option.}
  223. \noindent
  224. In this case, we have created three strands of lines whose intersections with the contours
  225. define the label placements, presented in Figure~\ref{fig:GMT_App_O_5}.
  226. \section{Examples of Label Attributes}
  227. We will now demonstrate some of the ways to play with the label attributes. To do so we
  228. will use \GMTprog{psxy} on a great-circle line connecting the geoid extrema, along which
  229. we have sampled the ETOPO5 relief data set. The file \filename{transect.d} thus contains
  230. \emph{lon, lat, dist, geoid, relief}, with distances in km.
  231. \subsection{Label placement by along-track distances, 1}
  232. This example will change the orientation of labels from along-track to across-track, and
  233. surrounds the labels with an opaque, outlined text box so that the label is more readable. We choose
  234. the place the labels every 1000 km along the line and use that distance as the label. The
  235. labels are placed normal to the line:
  236. \script{GMT_App_O_6}
  237. \GMTfig[H]{GMT_App_O_6}{Labels attributes are controlled with the arguments to the \protect\Opt{Sq} option.}
  238. \noindent
  239. The composite illustration in Figure~\ref{fig:GMT_App_O_6} shows the new effects. Note that
  240. the line connecting the extrema does not end exactly at the `-' and `+' symbols. This is
  241. because the placements of those symbols are based on the mean coordinates of the contour and
  242. not the locations of the (local or global) extrema.
  243. \subsection{Label placement by along-track distances, 2}
  244. A small variation on this theme is to place the labels parallel to the line, use
  245. spherical degrees for placement, append the degree symbol as a unit for the
  246. labels, choose a rounded rectangular text box, and inverse-video the label:
  247. \script{GMT_App_O_7}
  248. \noindent
  249. The output is presented as Figure~\ref{fig:GMT_App_O_7}.
  250. \GMTfig[H]{GMT_App_O_7}{Another label attribute example.}
  251. \subsection{Using a different data set for labels}
  252. In the next example we will use the bathymetry values along the transect as
  253. our label, with placement determined by the distance along track. We choose
  254. to place labels every 1500 km. To do this we need to pull out those records
  255. whose distances are multiples of 1500 km and create a ``fixed points'' file
  256. that can be used to place labels and specify the labels. This is done with
  257. \progname{awk}.
  258. \script{GMT_App_O_8}
  259. \noindent
  260. The output is presented as Figure~\ref{fig:GMT_App_O_8}.
  261. \GMTfig[H]{GMT_App_O_8}{Labels based on another data set (here bathymetry) while
  262. the placement is based on distances.}
  263. \section{Putting it all together}
  264. Finally, we will make a more complex composite illustration that uses several of the
  265. label placement and label attribute settings discussed in the previous sections. We
  266. make a map showing the tsunami travel times (in hours) from a hypothetical catastrophic
  267. landslide in the Canary Islands\footnote{Travel times were calculated using Geoware's
  268. travel time calculator, \progname{ttt};
  269. see \htmladdnormallink{(http://www.geoware-online.com)}{(http://www.geoware-online.com)}}.
  270. We lay down a color map based on the travel times
  271. and the shape of the seafloor, and travel time contours with curved labels as well
  272. as a few quoted lines. The final script is
  273. \script{GMT_App_O_9}
  274. \noindent
  275. with the complete illustration presented as Figure~\ref{fig:GMT_App_O_9}.
  276. \GMTfig[H]{GMT_App_O_9}{Tsunami travel times from the Canary Islands to places
  277. in the Atlantic, in particular New York. Should a catastrophic landslide occur
  278. it is possible that New York will experience a large tsunami about 8 hours after
  279. the event.}
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...