more visuals

This commit is contained in:
Motiejus Jakštys 2021-04-24 12:49:37 +03:00
parent 250095cdbd
commit 34ace29bb4
4 changed files with 56 additions and 69 deletions

View File

@ -3,6 +3,9 @@ WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas' OR name='Merkys'
#WHERE ?= name like '%' #WHERE ?= name like '%'
SLIDES = slides-2021-03-29.pdf SLIDES = slides-2021-03-29.pdf
# Max figure size (in meters) is when it's width is TEXTWIDTH_CM on scale 1:25k
SCALEDWIDTH = $(shell awk '/^TEXTWIDTH_CM/{print 25000/100*$$3}' layer2img.py)
############################################################################## ##############################################################################
# These variables have to come before first use due to how macros are expanded # These variables have to come before first use due to how macros are expanded
############################################################################## ##############################################################################
@ -68,7 +71,6 @@ mj-msc.pdf: mj-msc.tex version.inc.tex vars.inc.tex bib.bib \
define FIG_template define FIG_template
$(1).pdf: layer2img.py Makefile $(2) $(1).pdf: layer2img.py Makefile $(2)
python ./layer2img.py --outfile=$(1).pdf \ python ./layer2img.py --outfile=$(1).pdf \
$$(if $$($(1)_WMCLIP),--wmclip=$$($(1)_WMCLIP)) \
$$(if $$($(1)_WIDTHDIV),--widthdiv=$$($(1)_WIDTHDIV)) \ $$(if $$($(1)_WIDTHDIV),--widthdiv=$$($(1)_WIDTHDIV)) \
$$(foreach i,1 2 3, \ $$(foreach i,1 2 3, \
$$(if $$($(1)_$$(i)CMAP),--group$$(i)-cmap="$$($(1)_$$(i)CMAP)") \ $$(if $$($(1)_$$(i)CMAP),--group$$(i)-cmap="$$($(1)_$$(i)CMAP)") \
@ -122,19 +124,16 @@ selfcrossing-1-after_2SELECT = wm_debug where name='selfcrossing-1' AND stage='b
selfcrossing-1-after_2LINESTYLE = invisible selfcrossing-1-after_2LINESTYLE = invisible
salvis-25k_1SELECT = wm_rivers where name='Šalčia' OR name='Visinčia' salvis-25k_1SELECT = wm_rivers where name='Šalčia' OR name='Visinčia'
salvis-25k_WMCLIP = salcia-visincia:25k
salvis-25k_WIDTHDIV = 1 salvis-25k_WIDTHDIV = 1
salvis-50k_WIDTHDIV = 2
salvis-50k_1SELECT = wm_rivers where name='Šalčia' OR name='Visinčia' salvis-50k_1SELECT = wm_rivers where name='Šalčia' OR name='Visinčia'
salvis-50k_WMCLIP = salcia-visincia:50k salvis-50k_WIDTHDIV = 2
salvis-250k_WIDTHDIV = 10
salvis-250k_1SELECT = wm_rivers where name='Šalčia' OR name='Visinčia' salvis-250k_1SELECT = wm_rivers where name='Šalčia' OR name='Visinčia'
salvis-250k_WMCLIP = salcia-visincia:250k salvis-250k_WIDTHDIV = 10
.faux_test-rivers: tests-rivers.sql wm.sql .faux_db .faux_test-rivers: tests-rivers.sql wm.sql .faux_db
./db -f $< ./db -v scaledwidth=$(SCALEDWIDTH) -f $<
touch $@ touch $@
.faux_test: tests.sql wm.sql .faux_db .faux_test: tests.sql wm.sql .faux_db

View File

@ -16,45 +16,39 @@ PSQL_CREDS = "host=127.0.0.1 dbname=osm user=osm password=osm"
# see `NOTICE` in the LaTeX document; this is the width of the main text block. # see `NOTICE` in the LaTeX document; this is the width of the main text block.
TEXTWIDTH_CM = 12.12364 TEXTWIDTH_CM = 12.12364
SCALES = {
"10k": 10000,
"25k": 25000,
"50k": 50000,
"250k": 250000,
}
def inch(cm): def inch(cm):
return cm / 2.54 return cm / 2.54
def wm_clip(string):
if not string:
return None
name, gdr = string.split(":")
if scale := SCALES.get(gdr):
return name, scale
scales = ",".join(SCALES.keys())
raise argparse.ArgumentTypeError("invalid scale. Expected %s" % scales)
def parse_args(): def parse_args():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Convert geopackage to an image') description='Convert a geometry to an image')
parser.add_argument('--group1-select', required=True) parser.add_argument('--group1-select', required=True)
parser.add_argument('--group1-cmap', type=bool) parser.add_argument('--group1-cmap', type=bool)
parser.add_argument('--group1-linestyle') parser.add_argument('--group1-linestyle')
simplify = parser.add_mutually_exclusive_group()
simplify.add_argument('--group1-simplifydp', type=int)
simplify.add_argument('--group1-simplifyvw', type=int)
parser.add_argument('--group1-chaikin', type=bool)
parser.add_argument('--group2-select') parser.add_argument('--group2-select')
parser.add_argument('--group2-cmap', type=bool) parser.add_argument('--group2-cmap', type=bool)
parser.add_argument('--group2-linestyle') parser.add_argument('--group2-linestyle')
simplify = parser.add_mutually_exclusive_group()
simplify.add_argument('--group2-simplifydp', type=int)
simplify.add_argument('--group2-simplifyvw', type=int)
parser.add_argument('--group2-chaikin', type=bool)
parser.add_argument('--group3-select') parser.add_argument('--group3-select')
parser.add_argument('--group3-cmap', type=bool) parser.add_argument('--group3-cmap', type=bool)
parser.add_argument('--group3-linestyle') parser.add_argument('--group3-linestyle')
simplify = parser.add_mutually_exclusive_group()
simplify.add_argument('--group3-simplifydp', type=int)
simplify.add_argument('--group3-simplifyvw', type=int)
parser.add_argument('--group3-chaikin', type=bool)
parser.add_argument('--wmclip',
type=wm_clip,
help="Clip for scale. E.g. salcia-visincia:10k",
)
parser.add_argument('--widthdiv', parser.add_argument('--widthdiv',
default=1, type=float, help='Width divisor') default=1, type=float, help='Width divisor')
@ -62,17 +56,10 @@ def parse_args():
return parser.parse_args() return parser.parse_args()
def read_layer(select, width, maybe_wmclip): def read_layer(select, width):
if not select: if not select:
return return
way = "way" way = "way"
if maybe_wmclip:
name, scale = maybe_wmclip
way = "st_intersection(way, wm_bbox('{name}', {scale}, {width}))".format(
name=name,
scale=scale,
width=width,
)
conn = psycopg2.connect(PSQL_CREDS) conn = psycopg2.connect(PSQL_CREDS)
sql = "SELECT {way} as way1 FROM {select}".format(way=way, select=select) sql = "SELECT {way} as way1 FROM {select}".format(way=way, select=select)
return geopandas.read_postgis(sql, con=conn, geom_col='way1') return geopandas.read_postgis(sql, con=conn, geom_col='way1')
@ -93,9 +80,9 @@ def plot_args(color, maybe_cmap, maybe_linestyle):
def main(): def main():
args = parse_args() args = parse_args()
width = TEXTWIDTH_CM / args.widthdiv width = TEXTWIDTH_CM / args.widthdiv
group1 = read_layer(args.group1_select, width, args.wmclip) group1 = read_layer(args.group1_select, width)
group2 = read_layer(args.group2_select, width, args.wmclip) group2 = read_layer(args.group2_select, width)
group3 = read_layer(args.group3_select, width, args.wmclip) group3 = read_layer(args.group3_select, width)
c1 = plot_args(BLACK, args.group1_cmap, args.group1_linestyle) c1 = plot_args(BLACK, args.group1_cmap, args.group1_linestyle)
c2 = plot_args(ORANGE, args.group2_cmap, args.group2_linestyle) c2 = plot_args(ORANGE, args.group2_cmap, args.group2_linestyle)
c3 = plot_args(GREEN, args.group3_cmap, args.group3_linestyle) c3 = plot_args(GREEN, args.group3_cmap, args.group3_linestyle)

View File

@ -3,7 +3,6 @@
\usepackage[T1]{fontenc} \usepackage[T1]{fontenc}
\usepackage[english]{babel} \usepackage[english]{babel}
\usepackage[utf8]{inputenc} \usepackage[utf8]{inputenc}
%\usepackage{a4wide}
\usepackage [autostyle, english=american]{csquotes} \usepackage [autostyle, english=american]{csquotes}
\MakeOuterQuote{"} \MakeOuterQuote{"}
\usepackage[maxbibnames=99,style=numeric,sorting=none]{biblatex} \usepackage[maxbibnames=99,style=numeric,sorting=none]{biblatex}
@ -19,8 +18,18 @@
\usepackage{tabularx} \usepackage{tabularx}
\usepackage{float} \usepackage{float}
\usepackage{tikz} \usepackage{tikz}
\usepackage{minted}
\usepackage{fancyvrb} \usepackage{fancyvrb}
\iffalse
% requires minted
\usepackage{minted}
\newcommand{\inputcode}[2]{\inputminted[fontsize=\small}{#1}{#2}
\else
% does not require minted
\usepackage{verbatim}
\newcommand{\inputcode}[2]{\verbatiminput{#2}}
\fi
\input{version.inc} \input{version.inc}
\input{vars.inc} \input{vars.inc}
@ -189,6 +198,7 @@ As can be seen in the article example, generalization is worthy.
\end{figure} \end{figure}
\subsubsection{Modern approaches} \subsubsection{Modern approaches}
Due to their simplicity and ubiquity, {\DP} and {\VW} have been established as Due to their simplicity and ubiquity, {\DP} and {\VW} have been established as
@ -617,12 +627,12 @@ We strongly believe in the ability to reproduce the results is critical for any
document and its accompanying graphics, run this script (assuming name of document and its accompanying graphics, run this script (assuming name of
this document is {\tt mj-msc-full.pdf}): this document is {\tt mj-msc-full.pdf}):
\inputminted[fontsize=\small]{bash}{extract-and-generate} \inputcode{bash}{extract-and-generate}
This was tested on Linux Debian 11 with upstream packages only. This was tested on Linux Debian 11 with upstream packages only.
\subsection{Algorithm code listings} \subsection{Algorithm code listings}
\inputminted[fontsize=\small]{postgresql}{wm.sql} \inputcode{postgresql}{wm.sql}
\end{appendices} \end{appendices}
\end{document} \end{document}

View File

@ -1,49 +1,40 @@
\i wm.sql \i wm.sql
insert into wm_visuals(name, way) values('salcia-visincia',
st_closestpoint(
(select way from wm_rivers where name='Šalčia'),
(select way from wm_rivers where name='Visinčia')
)
);
insert into wm_visuals(name, way) values('nemunas-merkys',
st_closestpoint(
(select way from wm_rivers where name='Nemunas'),
(select way from wm_rivers where name='Merkys')
)
);
-- wm_envelope clips a geometry by a bounding box around a given object, -- wm_envelope clips a geometry by a bounding box around a given object,
-- matching dimensions of A-class paper (1 by sqrt(2). -- matching dimensions of A-class paper (1 by sqrt(2).
drop function if exists wm_bbox; drop function if exists wm_bbox;
create function wm_bbox( create function wm_bbox(
center text, center geometry,
projection_scale integer, scaledwidth float
projection_width_cm float
) returns geometry as $$ ) returns geometry as $$
declare declare
gcenter geometry;
halfX float; halfX float;
halfY float; halfY float;
begin begin
halfX = projection_scale * projection_width_cm / 2 / 100; halfX = scaledwidth / 2;
halfY = halfX * sqrt(2); halfY = halfX * sqrt(2);
select way from wm_visuals where name=center into gcenter;
if gcenter is null then
raise 'center % not found', center;
end if;
return st_envelope( return st_envelope(
st_union( st_union(
st_translate(gcenter, halfX, halfY), st_translate(center, halfX, halfY),
st_translate(gcenter, -halfX, -halfY) st_translate(center, -halfX, -halfY)
) )
); );
end end
$$ language plpgsql; $$ language plpgsql;
insert into wm_visuals(name, way) values('salvis', (
select st_intersection(
(select st_union(way) from wm_rivers where name in ('Šalčia', 'Visinčia')),
wm_bbox(
st_closestpoint(
(select way from wm_rivers where name='Šalčia'),
(select way from wm_rivers where name='Visinčia')
),
:scaledwidth
)
)
));
do $$ do $$
declare declare
npoints bigint; npoints bigint;