simplify polygon drawing

if it's a polygon, it's always a CMAP.
This commit is contained in:
Motiejus Jakštys 2021-05-19 22:57:48 +03:00 committed by Motiejus Jakštys
parent 913eb30d8b
commit e528ef7dfb
3 changed files with 13 additions and 19 deletions

View File

@ -73,7 +73,6 @@ $(1).pdf: layer2img.py Makefile $(2)
python ./layer2img.py --outfile=$(1).pdf \ python ./layer2img.py --outfile=$(1).pdf \
$$(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)SELECT),--group$$(i)-select="$$($(1)_$$(i)SELECT)") \ $$(if $$($(1)_$$(i)SELECT),--group$$(i)-select="$$($(1)_$$(i)SELECT)") \
$$(if $$($(1)_$$(i)LINESTYLE),--group$$(i)-linestyle="$$($(1)_$$(i)LINESTYLE)") \ $$(if $$($(1)_$$(i)LINESTYLE),--group$$(i)-linestyle="$$($(1)_$$(i)LINESTYLE)") \
) )
@ -84,26 +83,21 @@ $(foreach fig,$(RIVERS), $(eval $(call FIG_template,$(fig),.faux_test-rivers)))
test-figures_1SELECT = wm_figures test-figures_1SELECT = wm_figures
fig8-definition-of-a-bend_1SELECT = wm_debug where name='fig8' AND stage='bbends' AND gen=1 fig8-definition-of-a-bend_1SELECT = wm_debug where name='fig8' AND stage='bbends' AND gen=1
fig8-definition-of-a-bend_2CMAP = 1
fig8-definition-of-a-bend_2SELECT = wm_debug where name='fig8' AND stage='bbends-polygon' AND gen=1 fig8-definition-of-a-bend_2SELECT = wm_debug where name='fig8' AND stage='bbends-polygon' AND gen=1
fig5-gentle-inflection-before_WITHDIV = 2 fig5-gentle-inflection-before_WITHDIV = 2
fig5-gentle-inflection-before_1SELECT = wm_debug where name='fig5' AND stage='bbends' AND gen=1 fig5-gentle-inflection-before_1SELECT = wm_debug where name='fig5' AND stage='bbends' AND gen=1
fig5-gentle-inflection-before_2CMAP = 1
fig5-gentle-inflection-before_2SELECT = wm_debug where name='fig5' AND stage='bbends-polygon' AND gen=1 fig5-gentle-inflection-before_2SELECT = wm_debug where name='fig5' AND stage='bbends-polygon' AND gen=1
fig5-gentle-inflection-after_WITHDIV = 2 fig5-gentle-inflection-after_WITHDIV = 2
fig5-gentle-inflection-after_1SELECT = wm_debug where name='fig5' AND stage='cinflections' AND gen=1 fig5-gentle-inflection-after_1SELECT = wm_debug where name='fig5' AND stage='cinflections' AND gen=1
fig5-gentle-inflection-after_2SELECT = wm_debug where name='fig5' AND stage='cinflections-polygon' AND gen=1 fig5-gentle-inflection-after_2SELECT = wm_debug where name='fig5' AND stage='cinflections-polygon' AND gen=1
fig5-gentle-inflection-after_2CMAP = 1
inflection-1-gentle-inflection-before_WIDTHDIV = 2 inflection-1-gentle-inflection-before_WIDTHDIV = 2
inflection-1-gentle-inflection-before_1SELECT = wm_debug where name='inflection-1' AND stage='bbends' AND gen=1 inflection-1-gentle-inflection-before_1SELECT = wm_debug where name='inflection-1' AND stage='bbends' AND gen=1
inflection-1-gentle-inflection-before_2SELECT = wm_debug where name='inflection-1' AND stage='bbends-polygon' AND gen=1 inflection-1-gentle-inflection-before_2SELECT = wm_debug where name='inflection-1' AND stage='bbends-polygon' AND gen=1
inflection-1-gentle-inflection-before_2CMAP = 1
inflection-1-gentle-inflection-after_WIDTHDIV = 2 inflection-1-gentle-inflection-after_WIDTHDIV = 2
inflection-1-gentle-inflection-after_1SELECT = wm_debug where name='inflection-1' AND stage='cinflections' AND gen=1 inflection-1-gentle-inflection-after_1SELECT = wm_debug where name='inflection-1' AND stage='cinflections' AND gen=1
inflection-1-gentle-inflection-after_2SELECT = wm_debug where name='inflection-1' AND stage='cinflections-polygon' AND gen=1 inflection-1-gentle-inflection-after_2SELECT = wm_debug where name='inflection-1' AND stage='cinflections-polygon' AND gen=1
inflection-1-gentle-inflection-after_2CMAP = 1
fig6-selfcrossing-before_WIDTHDIV = 2 fig6-selfcrossing-before_WIDTHDIV = 2
fig6-selfcrossing-before_1SELECT = wm_debug where name='fig6' AND stage='bbends' AND gen=1 fig6-selfcrossing-before_1SELECT = wm_debug where name='fig6' AND stage='bbends' AND gen=1

View File

@ -25,7 +25,6 @@ def parse_args():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Convert a geometry 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-linestyle') parser.add_argument('--group1-linestyle')
simplify = parser.add_mutually_exclusive_group() simplify = parser.add_mutually_exclusive_group()
@ -34,7 +33,6 @@ def parse_args():
parser.add_argument('--group1-chaikin', type=bool) 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-linestyle') parser.add_argument('--group2-linestyle')
simplify = parser.add_mutually_exclusive_group() simplify = parser.add_mutually_exclusive_group()
simplify.add_argument('--group2-simplifydp', type=int) simplify.add_argument('--group2-simplifydp', type=int)
@ -42,7 +40,6 @@ def parse_args():
parser.add_argument('--group2-chaikin', type=bool) 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-linestyle') parser.add_argument('--group3-linestyle')
simplify = parser.add_mutually_exclusive_group() simplify = parser.add_mutually_exclusive_group()
simplify.add_argument('--group3-simplifydp', type=int) simplify.add_argument('--group3-simplifydp', type=int)
@ -65,11 +62,14 @@ def read_layer(select, width):
return geopandas.read_postgis(sql, con=conn, geom_col='way1') return geopandas.read_postgis(sql, con=conn, geom_col='way1')
def plot_args(color, maybe_cmap, maybe_linestyle): def plot_args(geom, color, maybe_linestyle):
if maybe_cmap: if geom is None:
r = {'cmap': CMAP} return
else:
r = {'color': color} if geom.geom_type[0] == 'Polygon':
return {'cmap': CMAP}
r = {'color': color}
if maybe_linestyle == 'invisible': if maybe_linestyle == 'invisible':
r['color'] = (0, 0, 0, 0) r['color'] = (0, 0, 0, 0)
elif maybe_linestyle: elif maybe_linestyle:
@ -83,9 +83,9 @@ def main():
group1 = read_layer(args.group1_select, width) group1 = read_layer(args.group1_select, width)
group2 = read_layer(args.group2_select, width) group2 = read_layer(args.group2_select, width)
group3 = read_layer(args.group3_select, width) group3 = read_layer(args.group3_select, width)
c1 = plot_args(BLACK, args.group1_cmap, args.group1_linestyle) c1 = plot_args(group1, BLACK, args.group1_linestyle)
c2 = plot_args(ORANGE, args.group2_cmap, args.group2_linestyle) c2 = plot_args(group2, ORANGE, args.group2_linestyle)
c3 = plot_args(GREEN, args.group3_cmap, args.group3_linestyle) c3 = plot_args(group3, GREEN, args.group3_linestyle)
rc('text', usetex=True) rc('text', usetex=True)
fig, ax = plt.subplots() fig, ax = plt.subplots()

View File

@ -38,7 +38,7 @@
\usepackage{layouts} \usepackage{layouts}
\newcommand{\onpage}[1]{\ref{#1} on page~\pageref{#1}} \newcommand{\onpage}[1]{\ref{#1} on page~\pageref{#1}}
\newcommand{\titlecite}[1]{\citetitle{#1} \cite{#1}} \newcommand{\titlecite}[1]{\citetitle{#1}\cite{#1}}
\newcommand{\DP}{Douglas \& Peucker} \newcommand{\DP}{Douglas \& Peucker}
\newcommand{\VW}{Visvalingam--Whyatt} \newcommand{\VW}{Visvalingam--Whyatt}
\newcommand{\WM}{Wang--M{\"u}ller} \newcommand{\WM}{Wang--M{\"u}ller}
@ -75,7 +75,7 @@
\label{sec:abstract} \label{sec:abstract}
Current open-source line generalization solutions have their roots in Current open-source line generalization solutions have their roots in
mathematics and geometry, and are not fit for natural objects like rivers mathematics and geometry, and are not fit for natural objects like rivers
and coastlines. This paper discusses our implementation of {\WM} algorithm and coastlines. This paper discusses our implementation of {\WM}'s algorithm
under and open-source license, explains things that we would had under and open-source license, explains things that we would had
appreciated in the original paper and compares our results to different appreciated in the original paper and compares our results to different
generalization algorithms. generalization algorithms.