add gpkg samples
This commit is contained in:
parent
b515e40435
commit
d932c7c7fc
4
.gitignore
vendored
4
.gitignore
vendored
@ -18,6 +18,10 @@ __pycache__
|
||||
*.blg
|
||||
*.bcf
|
||||
*.run.xml
|
||||
*.gpkg-wal
|
||||
*.gpkg-shm
|
||||
|
||||
env/
|
||||
*.pyc
|
||||
version.tex
|
||||
db/
|
||||
|
@ -1,2 +1,30 @@
|
||||
mj-referatas.pdf: $(shell git ls-files .)
|
||||
latexmk -g -pdf mj-referatas.tex
|
||||
SHELL = /bin/bash
|
||||
|
||||
GEN = zeimena.pdf st-simplify-100.pdf st-simplify-150.pdf st-simplify-300.pdf st-simplify-500.pdf
|
||||
|
||||
mj-referatas.pdf: mj-referatas.tex version.tex bib.bib zeimena-pretty.pdf $(GEN)
|
||||
latexmk -g -pdf $<
|
||||
|
||||
zeimena.pdf: zeimena.gpkg
|
||||
./layer2img.py --infile=$< --size=74x52 --outfile $@
|
||||
|
||||
st-simplify-%.pdf: db/.faux_st-simplify-%
|
||||
./layer2img.py --table=douglas_$* --size=74x52 --outfile $@
|
||||
|
||||
db/.faux_st-simplify-%: db/.faux_ready st-simplify.sql
|
||||
. ./managedb ; \
|
||||
psql --echo-all -v ON_ERROR_STOP=1 -v tolerance=$* -f st-simplify.sql
|
||||
touch $@
|
||||
|
||||
db/.faux_ready: zeimena.gpkg managedb
|
||||
-./managedb stop; rm -fr db
|
||||
./managedb init
|
||||
ogr2ogr -f PostgreSQL "PG:host=127.0.0.1 user=osm dbname=osm" zeimena.gpkg
|
||||
touch $@
|
||||
|
||||
GIT_DIR = $(shell git rev-parse --show-toplevel)/.git
|
||||
|
||||
version.tex: $(shell git ls-files .) $(GIT_DIR)
|
||||
date "+%F %T %Z" | awk '{print "\\gdef\\GeneratedAt{"$$0"}%"}' > $@
|
||||
[ -n "$$(git status --porcelain)" ] && suffix="-dirty"; \
|
||||
git describe --tags | awk '{print "\\gdef\\VCDescribe{"$$0"'$$suffix'}%"}' >> $@
|
||||
|
@ -52,7 +52,7 @@
|
||||
publisher={University of Toronto Press}
|
||||
}
|
||||
|
||||
// algorithms for generalization, not reaching satisfactory results
|
||||
% Algorithms for generalization, not reaching satisfactory results
|
||||
@inproceedings{monmonier1986toward,
|
||||
title={Toward a practicable model of cartographic generalisation.},
|
||||
author={Monmonier, Mark},
|
||||
@ -113,7 +113,7 @@
|
||||
year={2012}
|
||||
}
|
||||
|
||||
// LIKELY UNNEEDED
|
||||
% LIKELY UNNEEDED
|
||||
@book{buttenfield1991map,
|
||||
title={Map Generalization: Making rules for knowledge representation},
|
||||
author={Buttenfield, Barbara Pfeil and McMaster, Robert Brainerd},
|
||||
|
@ -3,12 +3,15 @@
|
||||
|
||||
import argparse
|
||||
import geopandas
|
||||
import psycopg2
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
INCH = 25.4 # mm
|
||||
INCH = 25.4 # mm
|
||||
|
||||
|
||||
def plt_size(string):
|
||||
if not string:
|
||||
# using default matplotlib dimensions
|
||||
return None
|
||||
try:
|
||||
w, h = string.split("x")
|
||||
@ -16,25 +19,36 @@ def plt_size(string):
|
||||
except Exception as e:
|
||||
raise argparse.ArgumentTypeError from e
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description='Convert layer to an image')
|
||||
parser.add_argument('infile', type=str)
|
||||
parser.add_argument('layer', type=str)
|
||||
parser.add_argument('-o', '--output', metavar='<file>', type=str)
|
||||
parser.add_argument('--size', type=plt_size, help='Figure size in mm (WWxHH)')
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Convert geopackage to an image')
|
||||
group = parser.add_mutually_exclusive_group(required=True)
|
||||
group.add_argument('--infile', type=str)
|
||||
group.add_argument('--table', type=str)
|
||||
parser.add_argument('-o', '--outfile', metavar='<file>', type=str)
|
||||
parser.add_argument(
|
||||
'--size', type=plt_size, help='Figure size in mm (WWxHH)')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
f = geopandas.read_file(args.infile)
|
||||
if args.table:
|
||||
conn = psycopg2.connect("host=127.0.0.1 dbname=osm user=osm")
|
||||
sql = "SELECT geom FROM %s" % args.table
|
||||
f = geopandas.read_postgis(sql, con=conn, geom_col='geom')
|
||||
else:
|
||||
f = geopandas.read_file(args.infile)
|
||||
f.plot(figsize=args.size)
|
||||
plt.axis('off')
|
||||
plt.margins(0, 0)
|
||||
plt.tight_layout(0)
|
||||
if args.output:
|
||||
plt.savefig(args.output, bbox_inches=0, dpi=300)
|
||||
if args.outfile:
|
||||
plt.savefig(args.outfile, bbox_inches=0, dpi=300)
|
||||
else:
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
46
II/Referatas/managedb
Executable file
46
II/Referatas/managedb
Executable file
@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
main() {
|
||||
PATH=$PATH:/usr/lib/postgresql/12/bin
|
||||
case ${1:-} in
|
||||
init)
|
||||
mkdir -p db && initdb db
|
||||
mkdir -p db/wal
|
||||
sed -i "s/.*unix_socket_dir.*/unix_socket_directories = '.\/wal'/" \
|
||||
db/postgresql.conf
|
||||
pg_ctl -D db -l db/logfile start
|
||||
|
||||
export PGHOST=127.0.0.1
|
||||
psql postgres -c 'CREATE ROLE osm WITH SUPERUSER LOGIN'
|
||||
psql postgres -c 'CREATE DATABASE osm'
|
||||
psql osm osm -c 'CREATE EXTENSION postgis'
|
||||
;;
|
||||
start)
|
||||
pg_ctl -D db -l db/logfile start
|
||||
;;
|
||||
stop)
|
||||
pg_ctl -D db -l db/logfile stop
|
||||
;;
|
||||
*)
|
||||
>&2 echo "Unknown command: '$*'"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
|
||||
if [[ $# != 0 ]]; then
|
||||
>&2 echo "Sourcing does not accept arguments: $*"
|
||||
else
|
||||
export PGHOST=127.0.0.1
|
||||
export PGUSER=osm
|
||||
export PGDATABASE=osm
|
||||
>&2 echo "OK: exported PGUSER, PGHOST and PGDATABASE"
|
||||
fi
|
||||
else
|
||||
set -euo pipefail
|
||||
export PGHOST=
|
||||
export PGUSER=
|
||||
export PGDATABASE=
|
||||
main "$@"
|
||||
fi
|
@ -14,6 +14,7 @@
|
||||
\usepackage{varwidth}
|
||||
\usepackage{tikz}
|
||||
\usetikzlibrary{er,positioning}
|
||||
\input{version}
|
||||
|
||||
\title{
|
||||
Cartografic Generalization of Lines \\
|
||||
@ -21,15 +22,40 @@
|
||||
}
|
||||
|
||||
\iffalse
|
||||
small scale: 1:XXXXXX
|
||||
large scale: 1:XXX
|
||||
|
||||
take douglas-pecker and check for different scales.
|
||||
|
||||
a4: 210x297mm
|
||||
a6: 105x148xmm
|
||||
a7: 74x105mm
|
||||
a8: 52x74mm
|
||||
|
||||
connect rivers first to a single polylines:
|
||||
- some algs can preserve connectivity, some not.
|
||||
|
||||
ideal hypothesis: mueller algorithm + topology may fully realize cartographic generalization tasks.
|
||||
|
||||
what scales and what distances?
|
||||
|
||||
https://postgis.net/docs/ST_SimplifyVW.html
|
||||
https://postgis.net/docs/ST_Simplify.html
|
||||
https://postgis.net/docs/ST_SimplifyPreserveTopology.html
|
||||
|
||||
how is tolerance bound to scale?
|
||||
- just use same parameter.
|
||||
|
||||
|
||||
\fi
|
||||
|
||||
\author{Motiejus Jakštys}
|
||||
|
||||
\date{\today}
|
||||
\date{
|
||||
\vspace{10mm}
|
||||
Version: \VCDescribe \\ \vspace{4mm}
|
||||
Generated At: \GeneratedAt
|
||||
}
|
||||
|
||||
\begin{document}
|
||||
\maketitle
|
||||
@ -73,7 +99,7 @@ of straight and curved river shape, and author's familiarity with the location.
|
||||
|
||||
\begin{figure}
|
||||
\centering
|
||||
\includegraphics[width=148mm]{zeimena}
|
||||
\includegraphics[width=148mm]{zeimena-pretty}
|
||||
\caption{Žeimena near Jaunadaris}
|
||||
\label{fig:zeimena}
|
||||
\end{figure}
|
||||
@ -81,19 +107,60 @@ of straight and curved river shape, and author's familiarity with the location.
|
||||
\section{Mathematical and geometrical algorithms}
|
||||
|
||||
To understand why geometrical algorithms are not entirely suitable for
|
||||
downscaling, let's pick some visual examples.
|
||||
downscaling, let's pick some visual examples. Start with
|
||||
\cite{douglas1973algorithms}, one of the most well-known line simplification
|
||||
algorithms, which is often used for generalization. Žeimena example is
|
||||
generalized with different tolerances in figure~\ref{fig:douglas-peucker} on
|
||||
page~\pageref{fig:douglas-peucker}.
|
||||
|
||||
\subsection{Douglas \& Peucker}
|
||||
As one can observe in figure~\ref{fig:douglas-100}, the Douglas \& Peucker with
|
||||
100m tolerance preserves most of the shape, and 500m
|
||||
(figure~\ref{fig:douglas-500}) becomes a straight line.
|
||||
|
||||
\cite{douglas1973algorithms} is one of the most well-known line simplification
|
||||
algorithms, which is often used for generalization. It will simplify the line shape.
|
||||
|
||||
Trying the same dataset with different tolerances for Douglas \& Peucker.
|
||||
\begin{figure}
|
||||
\centering
|
||||
\begin{subfigure}[b]{0.18\textwidth}
|
||||
\includegraphics[width=\textwidth]{zeimena}
|
||||
\caption{original}
|
||||
\label{fig:zeimena-original}
|
||||
\end{subfigure}
|
||||
~
|
||||
\begin{subfigure}[b]{0.18\textwidth}
|
||||
\includegraphics[width=\textwidth]{st-simplify-100}
|
||||
\caption{100m}
|
||||
\label{fig:douglas-100}
|
||||
\end{subfigure}
|
||||
~
|
||||
\begin{subfigure}[b]{0.18\textwidth}
|
||||
\includegraphics[width=\textwidth]{st-simplify-150}
|
||||
\caption{150m}
|
||||
\label{fig:douglas-150}
|
||||
\end{subfigure}
|
||||
~
|
||||
\begin{subfigure}[b]{0.18\textwidth}
|
||||
\includegraphics[width=\textwidth]{st-simplify-300}
|
||||
\caption{300m}
|
||||
\label{fig:douglas-300}
|
||||
\end{subfigure}
|
||||
~
|
||||
\begin{subfigure}[b]{0.18\textwidth}
|
||||
\includegraphics[width=\textwidth]{st-simplify-500}
|
||||
\caption{500m}
|
||||
\label{fig:douglas-500}
|
||||
\end{subfigure}
|
||||
\caption{Douglas \& Peucker line simplifications with different tolerances}
|
||||
\label{fig:douglas-peucker}
|
||||
\end{figure}
|
||||
|
||||
\section{Algorithms based on cartographical knowledge}
|
||||
|
||||
\cite{jiang2003line}, \cite{dyken2009simultaneous},
|
||||
\cite{mustafa2006dynamic}, \cite{nollenburg2008morphing}
|
||||
For further investigation:
|
||||
\begin{itemize}
|
||||
\item \cite{jiang2003line}
|
||||
\item \cite{dyken2009simultaneous}
|
||||
\item \cite{mustafa2006dynamic}
|
||||
\item \cite{nollenburg2008morphing}
|
||||
\end{itemize}
|
||||
|
||||
\section{My Idea}
|
||||
\label{sec:my_idea}
|
||||
|
14
II/Referatas/st-simplify.sql
Normal file
14
II/Referatas/st-simplify.sql
Normal file
@ -0,0 +1,14 @@
|
||||
DROP TABLE IF EXISTS douglas_:tolerance;
|
||||
|
||||
CREATE TABLE douglas_:tolerance (
|
||||
fid serial NOT NULL,
|
||||
geom geometry(MULTILINESTRING, 3346)
|
||||
);
|
||||
|
||||
INSERT INTO douglas_:tolerance (geom) (
|
||||
SELECT
|
||||
ST_Simplify (ST_LineMerge (ST_Union (geom)),
|
||||
:tolerance) AS geoms
|
||||
FROM
|
||||
zeimena);
|
||||
|
BIN
II/Referatas/zeimena-pretty.pdf
Normal file
BIN
II/Referatas/zeimena-pretty.pdf
Normal file
Binary file not shown.
BIN
II/Referatas/zeimena.gpkg
Normal file
BIN
II/Referatas/zeimena.gpkg
Normal file
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user