working with clipping/display of rivers

main
Motiejus Jakštys 2021-05-19 22:57:48 +03:00 committed by Motiejus Jakštys
parent aad2d02134
commit fc4db2b3bc
3 changed files with 45 additions and 30 deletions

View File

@ -10,16 +10,21 @@ SLIDES = slides-2021-03-29.pdf
NON_ARCHIVABLES = notes.txt referatui.txt slides-2021-03-29.txt
ARCHIVABLES = $(filter-out $(NON_ARCHIVABLES),$(shell git ls-files .))
FIGURES = test-figures \
fig8-definition-of-a-bend \
fig5-gentle-inflection-before \
fig5-gentle-inflection-after \
inflection-1-gentle-inflection-before \
inflection-1-gentle-inflection-after \
fig6-selfcrossing-before \
fig6-selfcrossing-after \
selfcrossing-1-before \
selfcrossing-1-after
FIGURES = \
test-figures \
fig8-definition-of-a-bend \
fig5-gentle-inflection-before \
fig5-gentle-inflection-after \
inflection-1-gentle-inflection-before \
inflection-1-gentle-inflection-after \
fig6-selfcrossing-before \
fig6-selfcrossing-after \
selfcrossing-1-before \
selfcrossing-1-after
RIVERS = \
salvis-gdr10 \
salvis-gdr50
# paper sizes in mm
A4p = 210x297
@ -75,8 +80,9 @@ mj-msc.pdf: mj-msc.tex version.inc.tex vars.inc.tex bib.bib $(addsuffix .pdf,$(F
############################
define FIG_template
$(1).pdf: layer2img.py Makefile .faux_test
$(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)") \
@ -84,7 +90,8 @@ $(1).pdf: layer2img.py Makefile .faux_test
$$(if $$($(1)_$$(i)LINESTYLE),--group$$(i)-linestyle="$$($(1)_$$(i)LINESTYLE)") \
)
endef
$(foreach fig,$(FIGURES),$(eval $(call FIG_template,$(fig))))
$(foreach fig,$(FIGURES),$(eval $(call FIG_template,$(fig).faux_test)))
$(foreach fig,$(RIVERS), $(eval $(call FIG_template,$(fig),.faux_test-rivers)))
test-figures_1SELECT = wm_figures
@ -128,6 +135,12 @@ selfcrossing-1-after_1SELECT = wm_debug where name='selfcrossing-1' AND stage='d
selfcrossing-1-after_2SELECT = wm_debug where name='selfcrossing-1' AND stage='bbends' AND gen=1
selfcrossing-1-after_2LINESTYLE = invisible
salvis-gdr10_1SELECT = wm_rivers where name='Šalčia' OR name='Visinčia'
salvis-gdr10_WMCLIP = salcia-visincia:GDR10
salvis-gdr50_1SELECT = wm_rivers where name='Šalčia' OR name='Visinčia'
salvis-gdr50_WMCLIP = salcia-visincia:GDR50
.faux_test-rivers: tests-rivers.sql wm.sql .faux_db
./db -f $<

View File

@ -11,6 +11,7 @@ CMAP = 'tab20c'
BOUNDS = ('xmin', 'ymin', 'xmax', 'ymax')
INCH_MM = 25.4
INCH_CM = INCH_MM / 10
BLACK, GREEN, ORANGE, PURPLE = '#000000', '#1b9e77', '#d95f02', '#7570b3'
PSQL_CREDS = "host=127.0.0.1 dbname=osm user=osm password=osm"
@ -28,9 +29,9 @@ SCALES = {
def wm_clip(string):
if not string:
return None
gdr, name = string.split(":")
name, gdr = string.split(":")
if scale := SCALES.get(gdr):
return gdr, scale
return name, scale
scales = ",".join(SCALES.keys())
raise argparse.ArgumentTypeError("invalid scale. Expected %s" % scales)
@ -51,7 +52,9 @@ def parse_args():
parser.add_argument('--group3-linestyle')
parser.add_argument('--wmclip',
type=wm_clip, help="Clip. E.g. GDR10:nemunas-merkys")
type=wm_clip,
help="Clip for scale. E.g. salcia-visincia:GDR10",
)
parser.add_argument('--widthdiv',
default=1, type=float, help='Width divisor')
@ -59,19 +62,20 @@ def parse_args():
return parser.parse_args()
def read_layer(select, width, maybe_wmclip):
def read_layer(select, width_in, maybe_wmclip):
if not select:
return
way = "way"
if maybe_wmclip:
name, scale = maybe_wmclip
way = "wm_clip(way, {name}, {scale}, {width})".format(
way = "st_intersection(way, wm_bbox('{name}', {scale}, {width}))".format(
name=name,
scale=scale,
width=width,
width=width_in * INCH_CM,
)
conn = psycopg2.connect(PSQL_CREDS)
sql = "SELECT {way} as way1 FROM {select}".format(way=way, select=select)
print("sql: %s" % sql)
return geopandas.read_postgis(sql, con=conn, geom_col='way1')
@ -99,7 +103,7 @@ def main():
rc('text', usetex=True)
fig, ax = plt.subplots()
fig.set_figwidth(width)
#fig.set_figwidth(width)
group1 is not None and group1.plot(ax=ax, **c1)
group2 is not None and group2.plot(ax=ax, **c2)

View File

@ -17,32 +17,30 @@ insert into wm_visuals(name, way) values('nemunas-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_clip;
create function wm_clip(
geom geometry,
drop function if exists wm_bbox;
create function wm_bbox(
center text,
projection_scale integer,
projection_width float
projection_width_cm float
) returns geometry as $$
declare
gcenter geometry;
bbox geometry;
halfX float;
halfY float;
begin
halfX = projection_scale * projection_width / 2;
halfX = projection_scale * projection_width_cm / 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;
bbox = st_envelope(
st_project(gcenter, halfX, radians(90)),
st_project(gcenter, halfY, 0)
return st_envelope(
st_union(
st_translate(gcenter, halfX, halfY),
st_translate(gcenter, -halfX, -halfY)
)
);
return st_intersection(bbox, geom);
end
$$ language plpgsql;