blob 57e2e15f (12610B) - Raw
1 \documentclass[a4paper]{report} 2 3 \usepackage[T1]{fontenc} 4 %\usepackage[bitstream-charter]{mathdesign} 5 \usepackage[english]{babel} 6 \usepackage[utf8]{inputenc} 7 \usepackage{a4wide} 8 \usepackage{csquotes} 9 \usepackage[maxbibnames=99,style=authoryear]{biblatex} 10 \usepackage[pdfusetitle]{hyperref} 11 \usepackage{enumitem} 12 \usepackage[toc,page,title]{appendix} 13 \addbibresource{bib.bib} 14 \usepackage{caption} 15 \usepackage{subcaption} 16 \usepackage{gensymb} 17 \usepackage{varwidth} 18 \usepackage{tabularx} 19 \usepackage{float} 20 \usepackage{tikz} 21 \usepackage{minted} 22 \usetikzlibrary{er,positioning} 23 \definecolor{mypurple}{RGB}{117,112,179} 24 \input{version} 25 26 \newcommand{\onpage}[1]{\ref{#1} on page~\pageref{#1}} 27 28 \newcommand{\DP}{Douglas \& Peucker} 29 \newcommand{\VW}{Visvalingam--Whyatt} 30 \newcommand{\WM}{Wang--M{\"u}ller} 31 32 \newcommand{\MYTITLE}{Cartographic Generalization of Lines using free software (example of rivers)} 33 \newcommand{\MYAUTHOR}{Motiejus Jakštys} 34 35 \title{\MYTITLE} 36 \author{\MYAUTHOR} 37 \date{\VCDescribe} 38 39 \begin{document} 40 41 \begin{titlepage} 42 \begin{center} 43 \includegraphics[width=0.4\textwidth]{vu} 44 45 \huge 46 \textbf{\MYTITLE} \\[4ex] 47 48 \LARGE 49 \textbf{\MYAUTHOR} \\[8ex] 50 51 \vfill 52 53 A thesis presented for the degree of\\ 54 Master in Cartography \\[3ex] 55 56 \large 57 \VCDescribe 58 \end{center} 59 \end{titlepage} 60 61 \begin{abstract} 62 \label{sec:abstract} 63 Current open-source line generalization solutions have their roots in 64 mathematics and geometry, and are not fit for natural objects like rivers 65 and coastlines. This paper discusses our implementation of {\WM} algorithm 66 under and open-source license, explains things that we would had 67 appreciated in the original paper and compares our results to different 68 generalization algorithms. 69 \end{abstract} 70 71 \newpage 72 73 \tableofcontents 74 \listoffigures 75 76 \newpage 77 78 \chapter{Introduction} 79 \label{sec:introduction} 80 81 When creating small-scale maps, often the detail of the data source is greater 82 than desired for the map. This becomes especially acute for natural features 83 that have many bends, like coastlines, rivers and forest boundaries. 84 85 To create a small-scale map from a large-scale data source, these features need 86 to be generalized: detail should be reduced. However, while doing so, it is 87 important to preserve the "defining" shape of the original feature, otherwise 88 the result will look unrealistic. 89 90 For example, if a river is nearly straight, it should be nearly straight after 91 generalization, otherwise a too straightened river will look like a canal. 92 Conversely, if the river is highly wiggly, the number of bends should be 93 reduced, but not removed. 94 95 Generalization problem for other objects can often be solved by other 96 non-geometric means: 97 98 \begin{itemize} 99 \item Towns and cities can be filtered and generalized by number of 100 inhabitants. 101 \item Roads can be eliminated by the road length, number of lanes, or 102 classification of the road (local, regional, international). 103 \end{itemize} 104 105 Natural line generalization problem can be viewed as having two competing 106 goals: 107 108 \begin{itemize} 109 \item Reduce detail by removing or simplifying "less important" features. 110 \item Retain enough detail, so the original is still recognize-able. 111 \end{itemize} 112 113 Given the discussed complexities, a fine line between under-generalization 114 (leaving object as-is) and over-generalization (making a straight line) must be 115 found. Therein lies the complexity of generalization algorithms: all have 116 different trade-offs. 117 118 \chapter{Literature review} 119 \label{sec:literature-review} 120 121 A number of cartographic line generalization algorithms have been researched. 122 The "classical" ones are {\DP} and {\VW}. 123 124 \section{{\DP} and {\VW}} 125 126 \cite{douglas1973algorithms} and \cite{visvalingam1993line} are "classical" 127 line generalization computer graphics algorithms. They are relatively simple to 128 implement, require few runtime resources. Both of them accept only a single 129 parameter, based on desired scale of the map, which makes them very simple to 130 adjust for different scales. 131 132 Both algorithms are part of PostGIS, a free-software GIS suite: 133 \begin{itemize} 134 \item \cite{douglas1973algorithms} via 135 \href{https://postgis.net/docs/ST_Simplify.html}{PostGIS Simplify}. 136 137 \item \cite{visvalingam1993line} via 138 \href{https://postgis.net/docs/ST_SimplifyVW.html}{PostGIS SimplifyVW}. 139 \end{itemize} 140 141 Since both algorithms produce jagged output lines, it is worthwhile to process 142 those through a widely available \cite{chaikin1974algorithm} smoothing 143 algorithm via \href{https://postgis.net/docs/ST_ChaikinSmoothing.html}{PostGIS 144 ChaikinSmoothing}. 145 146 Even though {\DP} and {\VW} are simple to understand and computationally 147 efficient, they have serious deficiencies for cartographic natural line 148 generalization. 149 150 <TODO: expand on deficiencies> 151 152 \section{Modern approaches} 153 154 Due to their simplicity and ubiquity, {\DP} and {\VW} have been established as 155 go-to algorithms for line generalization. During recent years, alternatives 156 have emerged. These modern replacements fall into roughly two categories: 157 158 \begin{itemize} 159 \item Cartographic knowledge was encoded to an algorithm (bottom-up 160 approach). One among these are \cite{wang1998line}. 161 \item Mathematical shape transformation which yields a more cartographic 162 result. E.g. \cite{jiang2003line}, \cite{dyken2009simultaneous}, 163 \cite{mustafa2006dynamic}, \cite{nollenburg2008morphing}. 164 \end{itemize} 165 166 Authors of most of the aforementioned articles have implemented the 167 generalization algorithm, at least to generate the visuals in the articles. 168 However, I wasn't able to find code for any of those to evaluate with my 169 desired data set, or use as a basis for my own maps. \cite{wang1998line} is 170 available in a commercial product. 171 172 Lack of robust openly available generalization algorithm implementations poses 173 a problem for map creation with free software: there is not a similar 174 high-quality simplification algorithm to create down-scaled maps, so any 175 cartographic work, which uses line generalization as part of its processing, 176 will be of sub-par quality. We believe that availability of high-quality 177 open-source tools is an important foundation for future cartographic 178 experimentation and development, thus it it benefits the cartographic society 179 as a whole. 180 181 \chapter{Methodology} 182 \label{sec:methodology} 183 184 The original \cite{wang1998line} leaves something to be desired for a practical 185 implementation: it is not straightforward to implement the algorithm from the 186 paper alone. 187 188 In this paper we describe {\WM} in a detail that is more useful for algorithm: 189 each section will be expanded, with more elaborate and exact illustrations for 190 every step of the algorithm. 191 192 Algorithms discussed in this paper assume Euclidean geometry. 193 194 \section{Automated tests} 195 \label{sec:automated-tests} 196 197 As part of the algorithm realization, an automated test suite has been 198 developed. Shapes to test each function have been hand-crafted and expected 199 results have been manually calculated. The test suite executes parts of the 200 algorithm against a predefined set of geometries, and asserts that the output 201 matches the resulting hand-calculated geometry. 202 203 The full set of test geometries is visualized in 204 figure~\onpage{fig:test-figures}. The figure includes arrows depicting line 205 direction. 206 207 \begin{figure}[H] 208 \centering 209 \includegraphics[width=\linewidth]{test-figures} 210 \caption{Line geometries for automated test cases} 211 \label{fig:test-figures} 212 \end{figure} 213 214 The full test suite can be executed with a single command, and completes in a 215 few seconds. Having an easily accessible test suite boosts confidence that no 216 unexpected bugs have snug in while modifying the algorithm. 217 218 \section{Vocabulary and terminology} 219 220 This section defines vocabulary and terms as defined in the rest of the paper. 221 222 \begin{description} 223 \item[Vertex] is a point on a plane, can be expressed unambiguously by a 224 pair of $(x,y)$ coordinates. 225 226 \item[Line Segment (or Segment)] joins two vertices by a straight line. A 227 segment can be expressed by two coordinate pairs: $(x_1, y_1)$ and 228 $(x_2, y_2)$. Line Segment and Segment are used interchangeably. 229 230 \item[Line] represents a single linear feature in the real world. For 231 example, a river or a coastline. {\tt LINESTRING} in GIS terms. 232 233 Geometrically, A line is a series of connected line segments, or, 234 equivalently, a series of connected vertices. Each vertex connects to 235 two other vertices, except those vertices at either ends of the line: 236 these two connect to a single other vertex. 237 238 \item[Bend] is a subset of a line that humans perceive as a curve. For the 239 purpose of this paper, the geometric definition is complex and is 240 discussed in section~\onpage{sec:definition-of-a-bend}. 241 \end{description} 242 243 \chapter{Description of the implementation} 244 245 Like alluded in section~\onpage{sec:introduction}, \cite{wang1998line} paper 246 skims over certain details, which are important to implement the algorithm. 247 This section goes through each algorithm stage, illustrating the intermediate 248 steps and explaining the author's desiderata for a more detailed description. 249 250 Illustrations of the following sections are extracted from the automated test 251 cases, which were written during the algorithm implementation (as discussed in 252 section~\onpage{sec:automated-tests}). 253 254 Lines in illustrations are black, and bends are heavily colored after 255 converting them to polygons. Bends are converted to polygons (for illustration 256 purposes) using the following algorithm: 257 258 \begin{itemize} 259 \item Join the first and last vertices of the bend, creating a polygon. 260 \item Color the polygons using distinct colors. 261 \end{itemize} 262 263 \section{Definition of a Bend} 264 \label{sec:definition-of-a-bend} 265 266 \begin{figure}[H] 267 \centering 268 \includegraphics[width=\linewidth]{fig8-definition-of-a-bend} 269 \caption{Originally Figure 8: detected bends are highlighted} 270 \label{fig:fig8-definition-of-a-bend} 271 \end{figure} 272 273 End line segments of all lines should also be part of the bend. That way, all 274 line segments belong to 1 or 2 bends. This characteristic is not obvious when 275 reading the introductory sections, but becomes unavoidable (there could be no 276 other way) when reading the following sections in detail. 277 278 First and last segments of each bend (except for the two end-line segments) is 279 also the first vertex of the next bend. This is apparent when looking at the 280 illustration of the detected bends. 281 282 \section{Gentle Inflection at End of a Bend} 283 284 The example in this section was clear, but insufficient: it does not specify 285 how many vertices should be included when calculating the end-of-bend 286 inflection. We chose the iterative approach -- as long as the angle is "right" 287 and the distance is decreasing, the algorithm should keep going; practically 288 not having an upper bound on the number of iterations. 289 290 \begin{figure}[h] 291 \centering 292 \begin{subfigure}[b]{.45\textwidth} 293 \includegraphics[width=\textwidth]{fig5-gentle-inflection-before} 294 \caption{Before applying the inflection rule} 295 \end{subfigure} 296 \hfill 297 \begin{subfigure}[b]{.45\textwidth} 298 \includegraphics[width=\textwidth]{fig5-gentle-inflection-after} 299 \caption{After applying the inflection rule} 300 \end{subfigure} 301 \caption{Originally Figure 5: gentle inflections at the ends of the bend} 302 \label{fig:fig5-gentle-inflection} 303 \end{figure} 304 305 \section{Self-line Crossing When Cutting a Bend} 306 307 \section{Attributes of a Single Bend} 308 309 \section{Shape of a Bend} 310 311 \section{The Context of a Bend: Isolated and Similar Bends} 312 313 \section{Elimination Operator} 314 315 \section{Combination Operator} 316 317 \section{Exaggeration Operator} 318 319 \chapter{Program Implementation} 320 321 \chapter{Results of Experiments} 322 323 \chapter{Conclusions} 324 \label{sec:conclusions} 325 326 \chapter{Related Work and future suggestions} 327 \label{sec:related_work} 328 329 \printbibliography 330 331 \begin{appendices} 332 333 \chapter{Code listings} 334 335 We strongly believe in the ability to reproduce the results is critical for any 336 scientific work. To make it possible for this paper, all source files and 337 accompanying scripts have been attached to the PDF. To re-generate this 338 document and its accompanying graphics, run this script (assuming name of 339 this document is {\tt mj-msc-full.pdf}): 340 341 \inputminted[fontsize=\small]{bash}{extract-and-generate} 342 343 This was tested on Linux Debian 11 with upstream packages only. 344 345 \end{appendices} 346 \end{document}