From 6f1a45eb1d9468340755f3c34b04fcac3337decb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 19 May 2021 22:57:46 +0300 Subject: [PATCH] beginning of the paper --- Makefile | 28 +++++++-- bib.bib | 152 +++++++++++++++++++++++++++++++++++++++++++++++ layer2img.py | 85 ++++++++++++++++++++++++++ mj-msc.tex | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 423 insertions(+), 6 deletions(-) create mode 100644 bib.bib create mode 100755 layer2img.py create mode 100644 mj-msc.tex diff --git a/Makefile b/Makefile index b200505..1fa567d 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,9 @@ SOURCE ?= lithuania-latest.osm.pbf WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas' -SLIDES = slides-2021-03-29.pdf slides-2021-03-29.html - -SLIDY_PATH= /usr/share/xml/docbook/stylesheet/docbook-xsl/slides/slidy -ifneq ($(wildcard $(SLIDY_PATH)/.*),) -SLIDY_ARGS = -V slidy-url=$(SLIDY_PATH) -endif +SLIDES = slides-2021-03-29.pdf +NON_ARCHIVABLES = notes.txt referatui.txt slides-2021-03-29.txt +ARCHIVABLES = $(filter-out $(NON_ARCHIVABLES),$(shell git ls-files .)) .PHONY: test test: tests.sql .faux.db @@ -30,6 +27,18 @@ clean-tables: .PHONY: slides slides: $(SLIDES) +mj-msc.pdf: mj-msc.tex version.tex bib.bib + latexmk -shell-escape -g -pdf $< + +mj-msc-all.pdf: mj-msc.pdf version.tex $(ARCHIVABLES) + cp $< .tmp-$@ + for f in $^; do \ + if [ "$$f" = "$<" ]; then continue; fi; \ + pdfattach .tmp-$@ $$f .tmp2-$@; \ + mv .tmp2-$@ .tmp-$@; \ + done + mv .tmp-$@ $@ + slides-2021-03-29.pdf: slides-2021-03-29.txt pandoc -t beamer -i $< -o $@ @@ -53,3 +62,10 @@ slides-2021-03-29.html: slides-2021-03-29.txt $(SOURCE): wget http://download.geofabrik.de/europe/$@ + +version.tex: $(shell git rev-parse --show-toplevel)/.git + ( \ + date '+\gdef\GeneratedAt{%F %T %Z}%'; \ + printf '\gdef\VCDescribe{%s}%%\n' $(REF); \ + ) > $@ + diff --git a/bib.bib b/bib.bib new file mode 100644 index 0000000..c61a510 --- /dev/null +++ b/bib.bib @@ -0,0 +1,152 @@ +@article{wang1998line, + title={Line generalization based on analysis of shape characteristics}, + author={Wang, Zeshen and M{\"u}ller, Jean-Claude}, + journal={Cartography and Geographic Information Systems}, + volume={25}, + number={1}, + pages={3--15}, + year={1998}, + publisher={Taylor \& Francis} +} + +@article{Kolanowski_2018, + title={Cartographic Line Generalization Based on Radius of Curvature Analysis}, + volume={7}, + ISSN={2220-9964}, + url={http://dx.doi.org/10.3390/ijgi7120477}, + DOI={10.3390/ijgi7120477}, + number={12}, + journal={ISPRS International Journal of Geo-Information}, + publisher={MDPI AG}, + author={Kolanowski, Bogdan and Augustyniak, Jacek and Latos, Dorota}, + year={2018}, + month={Dec}, + pages={477} +} + +@article{visvalingam1993line, + title={Line generalisation by repeated elimination of points}, + author={Visvalingam, Maheswari and Whyatt, James D}, + journal={The cartographic journal}, + volume={30}, + number={1}, + pages={46--51}, + year={1993}, + publisher={Taylor \& Francis} +} + +@article{muller1991generalization, + title={Generalization of spatial databases}, + author={Muller, Jean-Claude}, + journal={Geographical information systems}, + volume={1}, + pages={457--475}, + year={1991}, + publisher={John Wiley and Sons} +} + +@article{miuller1995generalization, + title={Generalization-state of the art and issues}, + author={Miuller, JC and Weibel, R and Lagrange, J and {\"E}alge, F}, + journal={GIS and Generalisation: Methodology and Practice}, + pages={3--17}, + year={1995} +} + +@inproceedings{mcmaster1992generalization, + title={Generalization in digital cartography}, + author={McMaster, Robert Brainerd and Shea, K Stuart}, + year={1992}, + organization={Association of American Geographers Washington, DC} +} + +@article{douglas1973algorithms, + title={Algorithms for the reduction of the number of points required to represent a digitized line or its caricature}, + author={Douglas, David H and Peucker, Thomas K}, + journal={Cartographica: the international journal for geographic information and geovisualization}, + volume={10}, + number={2}, + pages={112--122}, + year={1973}, + publisher={University of Toronto Press} +} + +% Algorithms for generalization, not reaching satisfactory results +@inproceedings{monmonier1986toward, + title={Toward a practicable model of cartographic generalisation.}, + author={Monmonier, Mark}, + booktitle={Auto Carto London. Proc. conference, 1986. Vol. 2}, + pages={257--266}, + year={1986}, + organization={distributed Royal Institution of Chartered Surveyors} +} +@inproceedings{mcmaster1993spatial, + title={A spatial-object level organization of transformations for cartographic generalization}, + author={McMaster, RB and Barnett, Leone}, + booktitle={AUTOCARTO-CONFERENCE-}, + pages={386--386}, + year={1993}, + organization={Citeseer} +} +@inproceedings{jiang2003line, + title={Line simplification using self-organizing maps}, + author={Jiang, Bin and Nakos, Byron}, + booktitle={Proceedings of the ISPRS Workshop on Spatial Analysis and Decision Making, Hong Kong, China}, + pages={3--5}, + year={2003} +} +@article{dyken2009simultaneous, + title={Simultaneous curve simplification}, + author={Dyken, Christopher and D{\ae}hlen, Morten and Sevaldrud, Thomas}, + journal={Journal of geographical systems}, + volume={11}, + number={3}, + pages={273--289}, + year={2009}, + publisher={Springer} +} +@article{mustafa2006dynamic, + title={Dynamic simplification and visualization of large maps}, + author={Mustafa, Nabil and Krishnan, Shankar and Varadhan, Gokul and Venkatasubramanian, Suresh}, + journal={International Journal of Geographical Information Science}, + volume={20}, + number={3}, + pages={273--302}, + year={2006}, + publisher={Taylor \& Francis} +} +@article{nollenburg2008morphing, + title={Morphing polylines: A step towards continuous generalization}, + author={N{\"o}llenburg, Martin and Merrick, Damian and Wolff, Alexander and Benkert, Marc}, + journal={Computers, Environment and Urban Systems}, + volume={32}, + number={4}, + pages={248--260}, + year={2008}, + publisher={Elsevier} +} +@inproceedings{stanislawski2012automated, + title={Automated metric assessment of line simplification in humid landscapes}, + author={Stanislawski, Lawrence V and Raposo, Paulo and Howard, Michael and Buttenfield, Barbara P}, + booktitle={Proceedings of the AutoCarto}, + year={2012} +} + +% LIKELY UNNEEDED +@book{buttenfield1991map, + title={Map Generalization: Making rules for knowledge representation}, + author={Buttenfield, Barbara Pfeil and McMaster, Robert Brainerd}, + year={1991}, + publisher={Longman Scientific \& Technical London} +} + +@article{chaikin1974algorithm, + title={An algorithm for high-speed curve generation}, + author={Chaikin, George Merrill}, + journal={Computer graphics and image processing}, + volume={3}, + number={4}, + pages={346--349}, + year={1974}, + publisher={Elsevier} +} diff --git a/layer2img.py b/layer2img.py new file mode 100755 index 0000000..95b6a4c --- /dev/null +++ b/layer2img.py @@ -0,0 +1,85 @@ +#!/usr/bin/python3 +import argparse +import geopandas +import psycopg2 +import matplotlib.pyplot as plt + +from matplotlib import rc, patches + +INCH = 25.4 # mm +BOUNDS = ('xmin', 'ymin', 'xmax', 'ymax') +GREEN, ORANGE, PURPLE = '#1b9e77', '#d95f02', '#7570b3' + + +def plt_size(string): + if not string: + return None + try: + w, h = string.split("x") + return float(w) / INCH, float(h) / INCH + except Exception as e: + raise argparse.ArgumentTypeError from e + + +def parse_args(): + parser = argparse.ArgumentParser( + description='Convert geopackage to an image') + group1 = parser.add_mutually_exclusive_group() + group1.add_argument('--group1-infile') + group1.add_argument('--group1-table') + parser.add_argument('-o', '--outfile', metavar='') + parser.add_argument( + '--size', type=plt_size, help='Figure size in mm (WWxHH)') + parser.add_argument( '--clip', type=float, nargs=4, metavar=BOUNDS) + + group2 = parser.add_mutually_exclusive_group() + group2.add_argument('--group2-infile', type=str) + group2.add_argument('--group2-table', type=str) + + group3 = parser.add_mutually_exclusive_group() + group3.add_argument('--group3-infile', type=str) + group3.add_argument('--group3-table', type=str) + return parser.parse_args() + + +def read_layer(maybe_table, maybe_file): + if maybe_table: + conn = psycopg2.connect("host=127.0.0.1 dbname=osm user=osm") + sql = "SELECT geom FROM %s" % maybe_table + return geopandas.read_postgis(sql, con=conn, geom_col='geom') + elif maybe_file: + return geopandas.read_file(maybe_file) + + +def main(): + args = parse_args() + group1 = read_layer(args.group1_table, args.group1_infile) + group2 = read_layer(args.group2_table, args.group2_infile) + group3 = read_layer(args.group3_table, args.group3_infile) + + rc('text', usetex=True) + fig, ax = plt.subplots() + if args.size: + fig.set_size_inches(args.size) + if c := args.clip: + ax.set_xlim(left=c[0], right=c[2]) + ax.set_ylim(bottom=c[1], top=c[3]) + + if group1 is not None: + group1.plot(ax=ax, color=PURPLE) + if group2 is not None: + group2.plot(ax=ax, color=ORANGE) + if group3 is not None: + group3.plot(ax=ax, color=GREEN) + + ax.axis('off') + ax.margins(0, 0) + fig.tight_layout(0) + if args.outfile: + fig.savefig(args.outfile, bbox_inches=0, dpi=600) + else: + plt.show() + + +if __name__ == '__main__': + main() diff --git a/mj-msc.tex b/mj-msc.tex new file mode 100644 index 0000000..56ec792 --- /dev/null +++ b/mj-msc.tex @@ -0,0 +1,164 @@ +\documentclass[a4paper]{article} + +\iffalse +\usepackage[L7x,T1]{fontenc} +\usepackage[lithuanian]{babel} +\else +\usepackage[T1]{fontenc} +\usepackage[english]{babel} +\fi + +\usepackage[utf8]{inputenc} +\usepackage{a4wide} +\usepackage{csquotes} +\usepackage[maxbibnames=99,style=authoryear]{biblatex} +\usepackage[pdfusetitle]{hyperref} +\usepackage{enumitem} +\usepackage[toc,page,title]{appendix} +\addbibresource{bib.bib} +\usepackage{caption} +\usepackage{subcaption} +\usepackage{gensymb} +\usepackage{varwidth} +\usepackage{tabularx} +\usepackage{float} +\usepackage{tikz} +\usepackage{minted} +\usetikzlibrary{er,positioning} +\definecolor{mypurple}{RGB}{117,112,179} +\input{version} + +\newcommand{\DP}{Douglas \& Peucker} +\newcommand{\VW}{Visvalingam--Whyatt} +\newcommand{\WM}{Wang--M{\"u}ller} + +\title{ + Cartographic Generalization of Lines using free software \\ + (example of rivers) \\ \vspace{4mm} +} + +\iffalse +\fi + +\author{Motiejus Jakštys} + +\date{ + \vspace{10mm} + Version: \VCDescribe \\ \vspace{4mm} + Generated At: \GeneratedAt +} + +\begin{document} +\maketitle + +\begin{abstract} +\label{sec:abstract} + +Current open-source line generalization solutions have their roots in + mathematics and geometry, and are not fit for natural objects like rivers + and coastlines. This paper discusses our implementation of \WM algorithm + under and open-source license, explains things that we would had + appreciated in the original paper and compares our results to different + generalization algorithms. +\end{abstract} + +\newpage + +\tableofcontents +\listoffigures + +\newpage + +\section{Introduction} +\label{sec:introduction} + +A number of cartographic line generalization algorithms have been researched, +which claim to better process cartographic objects like lines. These fall into +two rough categories: +\begin{itemize} + \item Cartographic knowledge was encoded to an algorithm (bottom-up + approach). One among these are \cite{wang1998line}. + \item Mathematical shape transformation which yields a more + cartographically suitable down-scaling. E.g. \cite{jiang2003line}, + \cite{dyken2009simultaneous}, \cite{mustafa2006dynamic}, + \cite{nollenburg2008morphing}. +\end{itemize} + +During research for the mentioned articles, prototype code has been written for +most of the algorithms. However, none of them seem to be available for use +except for the two "classical" ones -- {\DP} and {\VW}. + +\cite{wang1998line} is an algorithm specifically created for cartographic +generalization and available for general use, though it is only currently +available in a commercial product. This poses a problem for map creation in +open source software: there is not a similar high-quality simplification +algorithm to create down-scaled maps, so any cartographic work, which uses line +generalization as part of its processing, will be of sub-par quality. +We believe that availability of high-quality open-source tools is an important +foundation for future cartographic experimentation and development, thus it +it benefits the cartographic society as a whole. + +This paper will be reviewing and comparing two widely available algorithms that +are often used for line generalization: +\begin{itemize} + \item \cite{douglas1973algorithms} via + \href{https://postgis.net/docs/ST_Simplify.html}{PostGIS Simplify}. + + \item \cite{visvalingam1993line} via + \href{https://postgis.net/docs/ST_SimplifyVW.html}{PostGIS SimplifyVW}. + +\end{itemize} + +Since both algorithms produce jaggy output lines, it is worthwhile to process +those through a widely available \cite{chaikin1974algorithm} smoothing +algorithm via \href{https://postgis.net/docs/ST_ChaikinSmoothing.html}{PostGIS +ChaikinSmoothing}. + +\section{Visual comparison} + +\subsection{Comparison algorithms and parameters} +\subsection{Combining bends} + +\section{Conclusions} +\label{sec:conclusions} + +\section{Related Work and future suggestions} +\label{sec:related_work} + +\printbibliography + +\begin{appendices} + +\section{Žeimena and Lakaja in context} + +\section{Code listings} + +For the curious users it may be useful to see how the analysis was executed. +Also, given the source listings, it should be relatively straightforward to +re-run the same analysis on a different area. + +The analysis was executed and report was generated on Ubuntu 20.04 with only +system packages. This should be sufficient: {\tt postgis gdal-bin biber +latexmk texlive-bibtex-extra python3-geopandas python3-pygments}. + +\subsection{Makefile} +This file binds all the pieces together: +\begin{itemize} + \item Prepares the PostGIS database. + \item Generates helper figures (sine waves, squares). + \item Runs analysis on input files ({\DP}, {\VW}, Chaikin). + \item Invokes {\tt latexmk} as a final report generation step. +\end{itemize} +\inputminted[fontsize=\small]{make}{Makefile} + +\subsection{layer2img.py} +This file accepts a layer (or two) and generates a PDF image suitable for embedding into the report. +\inputminted[fontsize=\small]{python}{layer2img.py} + +\subsection{db} +Manages a PostGIS database in the Docker container. That way, the database can +be torn down and re-created by automated tools like the {\tt Makefile} itself. +\inputminted[fontsize=\small]{bash}{db} + +\end{appendices} +\end{document}