more visuals
This commit is contained in:
parent
f79c5d65d0
commit
5de6c032c0
13
Makefile
13
Makefile
|
@ -3,6 +3,9 @@ WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas' OR name='Merkys'
|
|||
#WHERE ?= name like '%'
|
||||
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
|
||||
##############################################################################
|
||||
|
@ -68,7 +71,6 @@ mj-msc.pdf: mj-msc.tex version.inc.tex vars.inc.tex bib.bib \
|
|||
define FIG_template
|
||||
$(1).pdf: layer2img.py Makefile $(2)
|
||||
python ./layer2img.py --outfile=$(1).pdf \
|
||||
$$(if $$($(1)_WMCLIP),--wmclip=$$($(1)_WMCLIP)) \
|
||||
$$(if $$($(1)_WIDTHDIV),--widthdiv=$$($(1)_WIDTHDIV)) \
|
||||
$$(foreach i,1 2 3, \
|
||||
$$(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
|
||||
|
||||
salvis-25k_1SELECT = wm_rivers where name='Šalčia' OR name='Visinčia'
|
||||
salvis-25k_WMCLIP = salcia-visincia:25k
|
||||
salvis-25k_WIDTHDIV = 1
|
||||
|
||||
salvis-50k_WIDTHDIV = 2
|
||||
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_WMCLIP = salcia-visincia:250k
|
||||
salvis-250k_WIDTHDIV = 10
|
||||
|
||||
.faux_test-rivers: tests-rivers.sql wm.sql .faux_db
|
||||
./db -f $<
|
||||
./db -v scaledwidth=$(SCALEDWIDTH) -f $<
|
||||
touch $@
|
||||
|
||||
.faux_test: tests.sql wm.sql .faux_db
|
||||
|
|
49
layer2img.py
49
layer2img.py
|
@ -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.
|
||||
TEXTWIDTH_CM = 12.12364
|
||||
|
||||
SCALES = {
|
||||
"10k": 10000,
|
||||
"25k": 25000,
|
||||
"50k": 50000,
|
||||
"250k": 250000,
|
||||
}
|
||||
|
||||
def inch(cm):
|
||||
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():
|
||||
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-cmap', type=bool)
|
||||
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-cmap', type=bool)
|
||||
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-cmap', type=bool)
|
||||
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',
|
||||
default=1, type=float, help='Width divisor')
|
||||
|
||||
|
@ -62,17 +56,10 @@ def parse_args():
|
|||
return parser.parse_args()
|
||||
|
||||
|
||||
def read_layer(select, width, maybe_wmclip):
|
||||
def read_layer(select, width):
|
||||
if not select:
|
||||
return
|
||||
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)
|
||||
sql = "SELECT {way} as way1 FROM {select}".format(way=way, select=select)
|
||||
return geopandas.read_postgis(sql, con=conn, geom_col='way1')
|
||||
|
@ -93,9 +80,9 @@ def plot_args(color, maybe_cmap, maybe_linestyle):
|
|||
def main():
|
||||
args = parse_args()
|
||||
width = TEXTWIDTH_CM / args.widthdiv
|
||||
group1 = read_layer(args.group1_select, width, args.wmclip)
|
||||
group2 = read_layer(args.group2_select, width, args.wmclip)
|
||||
group3 = read_layer(args.group3_select, width, args.wmclip)
|
||||
group1 = read_layer(args.group1_select, width)
|
||||
group2 = read_layer(args.group2_select, width)
|
||||
group3 = read_layer(args.group3_select, width)
|
||||
c1 = plot_args(BLACK, args.group1_cmap, args.group1_linestyle)
|
||||
c2 = plot_args(ORANGE, args.group2_cmap, args.group2_linestyle)
|
||||
c3 = plot_args(GREEN, args.group3_cmap, args.group3_linestyle)
|
||||
|
|
18
mj-msc.tex
18
mj-msc.tex
|
@ -3,7 +3,6 @@
|
|||
\usepackage[T1]{fontenc}
|
||||
\usepackage[english]{babel}
|
||||
\usepackage[utf8]{inputenc}
|
||||
%\usepackage{a4wide}
|
||||
\usepackage [autostyle, english=american]{csquotes}
|
||||
\MakeOuterQuote{"}
|
||||
\usepackage[maxbibnames=99,style=numeric,sorting=none]{biblatex}
|
||||
|
@ -19,8 +18,18 @@
|
|||
\usepackage{tabularx}
|
||||
\usepackage{float}
|
||||
\usepackage{tikz}
|
||||
\usepackage{minted}
|
||||
\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{vars.inc}
|
||||
|
||||
|
@ -189,6 +198,7 @@ As can be seen in the article example, generalization is worthy.
|
|||
\end{figure}
|
||||
|
||||
|
||||
|
||||
\subsubsection{Modern approaches}
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
\subsection{Algorithm code listings}
|
||||
\inputminted[fontsize=\small]{postgresql}{wm.sql}
|
||||
\inputcode{postgresql}{wm.sql}
|
||||
|
||||
\end{appendices}
|
||||
\end{document}
|
||||
|
|
|
@ -1,49 +1,40 @@
|
|||
\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,
|
||||
-- matching dimensions of A-class paper (1 by sqrt(2).
|
||||
drop function if exists wm_bbox;
|
||||
create function wm_bbox(
|
||||
center text,
|
||||
projection_scale integer,
|
||||
projection_width_cm float
|
||||
center geometry,
|
||||
scaledwidth float
|
||||
) returns geometry as $$
|
||||
declare
|
||||
gcenter geometry;
|
||||
halfX float;
|
||||
halfY float;
|
||||
begin
|
||||
halfX = projection_scale * projection_width_cm / 2 / 100;
|
||||
halfX = scaledwidth / 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(
|
||||
st_union(
|
||||
st_translate(gcenter, halfX, halfY),
|
||||
st_translate(gcenter, -halfX, -halfY)
|
||||
st_translate(center, halfX, halfY),
|
||||
st_translate(center, -halfX, -halfY)
|
||||
)
|
||||
);
|
||||
end
|
||||
$$ 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 $$
|
||||
declare
|
||||
npoints bigint;
|
||||
|
|
Loading…
Reference in New Issue