visualizations

main
Motiejus Jakštys 2021-05-19 22:57:47 +03:00 committed by Motiejus Jakštys
parent a2f2d62033
commit 31f0a1961f
4 changed files with 65 additions and 41 deletions

View File

@ -44,7 +44,15 @@ mj-msc-full.pdf: mj-msc.pdf version.tex $(ARCHIVABLES)
mv .tmp-$@ $@
test-figures.pdf: layer2img.py .faux_test
python ./layer2img.py --group1-table=wm_figures --group1-arrows=yes --outfile=$@
python ./layer2img.py --group1-table=wm_figures --outfile=$@
fig-definition-of-a-bend.pdf: layer2img.py Makefile .faux_test
python ./layer2img.py \
--group1-cmap=True \
--group1-table=wm_debug \
--group1-where="name='fig6' AND stage='bbends-polygon' AND gen=1" \
--group2-table=wm_debug --group2-where="name='fig6' AND stage='bbends' AND gen=1" \
--outfile=$@
.faux_test: tests.sql wm.sql .faux_db
./db -f tests.sql

View File

@ -111,20 +111,17 @@ def plt_size(string):
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('--group1-arrows', type=bool)
parser.add_argument('--group1-table')
parser.add_argument('--group1-where')
parser.add_argument('--group1-cmap', type=bool)
group2 = parser.add_mutually_exclusive_group()
group2.add_argument('--group2-infile', type=str)
group2.add_argument('--group2-table', type=str)
parser.add_argument('--group2-arrows', type=bool)
parser.add_argument('--group2-table')
parser.add_argument('--group2-where')
parser.add_argument('--group2-cmap', type=bool)
group3 = parser.add_mutually_exclusive_group()
group3.add_argument('--group3-infile', type=str)
group3.add_argument('--group3-table', type=str)
parser.add_argument('--group3-arrows', type=bool)
parser.add_argument('--group3-table')
parser.add_argument('--group3-where')
parser.add_argument('--group3-cmap', type=bool)
parser.add_argument('-o', '--outfile', metavar='<file>')
parser.add_argument(
@ -133,13 +130,14 @@ def parse_args():
return parser.parse_args()
def read_layer(maybe_table, maybe_file):
if maybe_table:
conn = psycopg2.connect(PSQL_CREDS)
sql = "SELECT way FROM %s" % maybe_table
return geopandas.read_postgis(sql, con=conn, geom_col='way')
elif maybe_file:
return geopandas.read_file(maybe_file)
def read_layer(table, maybe_where=None):
if not table:
return
conn = psycopg2.connect(PSQL_CREDS)
sql = "SELECT way FROM %s" % table
if maybe_where:
sql += " WHERE %s" % maybe_where
return geopandas.read_postgis(sql, con=conn, geom_col='way')
def add_lines(ax, group):
for g in group.to_dict()['way'].values():
@ -150,9 +148,9 @@ def add_lines(ax, group):
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)
group1 = read_layer(args.group1_table, args.group1_where)
group2 = read_layer(args.group2_table, args.group2_where)
group3 = read_layer(args.group3_table, args.group3_where)
rc('text', usetex=True)
fig, ax = plt.subplots()
@ -162,15 +160,17 @@ def main():
ax.set_xlim(left=c[0], right=c[2])
ax.set_ylim(bottom=c[1], top=c[3])
c1 = {'cmap': 'coolwarm'} if args.group1_cmap else {'color': ORANGE}
c2 = {'cmap': 'coolwarm'} if args.group2_cmap else {'color': PURPLE}
c3 = {'cmap': 'coolwarm'} if args.group3_cmap else {'color': GREEN}
if group1 is not None:
group1.plot(ax=ax, color=ORANGE)
args.group1_arrows and add_lines(ax, group1)
group1.plot(ax=ax, **c1)
#args.group1_arrows and add_lines(ax, group1)
if group2 is not None:
group2.plot(ax=ax, color=PURPLE)
args.group2_arrows and add_lines(ax, group1)
group2.plot(ax=ax, **c2)
if group3 is not None:
group3.plot(ax=ax, color=GREEN)
args.group3_arrows and add_lines(ax, group1)
group3.plot(ax=ax, **c3)
ax.axis('off')
ax.margins(0, 0)

View File

@ -214,6 +214,8 @@ unexpected bugs have snug in while modifying the algorithm.
\section{Definition of a Bend}
\section{Gentle Inflection at End of a Bend}
\section{Self-line Crossing When Cutting a Bend}

38
wm.sql
View File

@ -3,7 +3,12 @@ SET plpgsql.extra_errors TO 'all';
-- detect_bends detects bends using the inflection angles. No corrections.
drop function if exists detect_bends;
create function detect_bends(line geometry, dbgname text default null, OUT bends geometry[]) as $$
create function detect_bends(
line geometry,
dbgname text default null,
dbgstagenum integer default null,
OUT bends geometry[]
) as $$
declare
pi constant real default radians(180);
p geometry;
@ -67,6 +72,25 @@ begin
if (select count(1) >= 2 from st_dumppoints(bend)) then
bends = bends || bend;
end if;
if dbgname is not null then
for i in 1..array_length(bends, 1) loop
insert into wm_debug(stage, name, gen, nbend, way) values(
'bbends',
dbgname,
dbgstagenum,
i,
bends[i]
);
insert into wm_debug(stage, name, gen, nbend, way) values(
'bbends-polygon',
dbgname,
dbgstagenum,
i,
st_makepolygon(st_addpoint(bends[i], st_startpoint(bends[i])))
);
end loop;
end if;
end
$$ language plpgsql;
@ -403,17 +427,7 @@ begin
);
end if;
bends = detect_bends(lines[i]);
if dbgname is not null then
insert into wm_debug(stage, name, gen, nbend, way) values(
'bbends',
dbgname,
stagenum,
generate_subscripts(bends, 1),
unnest(bends)
);
end if;
bends = detect_bends(lines[i], dbgname, stagenum);
bends = fix_gentle_inflections(bends);