working with clipping/display of rivers
This commit is contained in:
parent
802967cfea
commit
811a714096
19
IV/Makefile
19
IV/Makefile
@ -10,7 +10,8 @@ SLIDES = slides-2021-03-29.pdf
|
|||||||
NON_ARCHIVABLES = notes.txt referatui.txt slides-2021-03-29.txt
|
NON_ARCHIVABLES = notes.txt referatui.txt slides-2021-03-29.txt
|
||||||
ARCHIVABLES = $(filter-out $(NON_ARCHIVABLES),$(shell git ls-files .))
|
ARCHIVABLES = $(filter-out $(NON_ARCHIVABLES),$(shell git ls-files .))
|
||||||
|
|
||||||
FIGURES = test-figures \
|
FIGURES = \
|
||||||
|
test-figures \
|
||||||
fig8-definition-of-a-bend \
|
fig8-definition-of-a-bend \
|
||||||
fig5-gentle-inflection-before \
|
fig5-gentle-inflection-before \
|
||||||
fig5-gentle-inflection-after \
|
fig5-gentle-inflection-after \
|
||||||
@ -21,6 +22,10 @@ FIGURES = test-figures \
|
|||||||
selfcrossing-1-before \
|
selfcrossing-1-before \
|
||||||
selfcrossing-1-after
|
selfcrossing-1-after
|
||||||
|
|
||||||
|
RIVERS = \
|
||||||
|
salvis-gdr10 \
|
||||||
|
salvis-gdr50
|
||||||
|
|
||||||
# paper sizes in mm
|
# paper sizes in mm
|
||||||
A4p = 210x297
|
A4p = 210x297
|
||||||
A4l = 297x210
|
A4l = 297x210
|
||||||
@ -75,8 +80,9 @@ mj-msc.pdf: mj-msc.tex version.inc.tex vars.inc.tex bib.bib $(addsuffix .pdf,$(F
|
|||||||
############################
|
############################
|
||||||
|
|
||||||
define FIG_template
|
define FIG_template
|
||||||
$(1).pdf: layer2img.py Makefile .faux_test
|
$(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)") \
|
||||||
@ -84,7 +90,8 @@ $(1).pdf: layer2img.py Makefile .faux_test
|
|||||||
$$(if $$($(1)_$$(i)LINESTYLE),--group$$(i)-linestyle="$$($(1)_$$(i)LINESTYLE)") \
|
$$(if $$($(1)_$$(i)LINESTYLE),--group$$(i)-linestyle="$$($(1)_$$(i)LINESTYLE)") \
|
||||||
)
|
)
|
||||||
endef
|
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
|
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_2SELECT = wm_debug where name='selfcrossing-1' AND stage='bbends' AND gen=1
|
||||||
selfcrossing-1-after_2LINESTYLE = invisible
|
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
|
.faux_test-rivers: tests-rivers.sql wm.sql .faux_db
|
||||||
./db -f $<
|
./db -f $<
|
||||||
|
@ -11,6 +11,7 @@ CMAP = 'tab20c'
|
|||||||
|
|
||||||
BOUNDS = ('xmin', 'ymin', 'xmax', 'ymax')
|
BOUNDS = ('xmin', 'ymin', 'xmax', 'ymax')
|
||||||
INCH_MM = 25.4
|
INCH_MM = 25.4
|
||||||
|
INCH_CM = INCH_MM / 10
|
||||||
BLACK, GREEN, ORANGE, PURPLE = '#000000', '#1b9e77', '#d95f02', '#7570b3'
|
BLACK, GREEN, ORANGE, PURPLE = '#000000', '#1b9e77', '#d95f02', '#7570b3'
|
||||||
PSQL_CREDS = "host=127.0.0.1 dbname=osm user=osm password=osm"
|
PSQL_CREDS = "host=127.0.0.1 dbname=osm user=osm password=osm"
|
||||||
|
|
||||||
@ -28,9 +29,9 @@ SCALES = {
|
|||||||
def wm_clip(string):
|
def wm_clip(string):
|
||||||
if not string:
|
if not string:
|
||||||
return None
|
return None
|
||||||
gdr, name = string.split(":")
|
name, gdr = string.split(":")
|
||||||
if scale := SCALES.get(gdr):
|
if scale := SCALES.get(gdr):
|
||||||
return gdr, scale
|
return name, scale
|
||||||
scales = ",".join(SCALES.keys())
|
scales = ",".join(SCALES.keys())
|
||||||
raise argparse.ArgumentTypeError("invalid scale. Expected %s" % scales)
|
raise argparse.ArgumentTypeError("invalid scale. Expected %s" % scales)
|
||||||
|
|
||||||
@ -51,7 +52,9 @@ def parse_args():
|
|||||||
parser.add_argument('--group3-linestyle')
|
parser.add_argument('--group3-linestyle')
|
||||||
|
|
||||||
parser.add_argument('--wmclip',
|
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',
|
parser.add_argument('--widthdiv',
|
||||||
default=1, type=float, help='Width divisor')
|
default=1, type=float, help='Width divisor')
|
||||||
|
|
||||||
@ -59,19 +62,20 @@ def parse_args():
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def read_layer(select, width, maybe_wmclip):
|
def read_layer(select, width_in, maybe_wmclip):
|
||||||
if not select:
|
if not select:
|
||||||
return
|
return
|
||||||
way = "way"
|
way = "way"
|
||||||
if maybe_wmclip:
|
if maybe_wmclip:
|
||||||
name, scale = 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,
|
name=name,
|
||||||
scale=scale,
|
scale=scale,
|
||||||
width=width,
|
width=width_in * INCH_CM,
|
||||||
)
|
)
|
||||||
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)
|
||||||
|
print("sql: %s" % sql)
|
||||||
return geopandas.read_postgis(sql, con=conn, geom_col='way1')
|
return geopandas.read_postgis(sql, con=conn, geom_col='way1')
|
||||||
|
|
||||||
|
|
||||||
@ -99,7 +103,7 @@ def main():
|
|||||||
|
|
||||||
rc('text', usetex=True)
|
rc('text', usetex=True)
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
fig.set_figwidth(width)
|
#fig.set_figwidth(width)
|
||||||
|
|
||||||
group1 is not None and group1.plot(ax=ax, **c1)
|
group1 is not None and group1.plot(ax=ax, **c1)
|
||||||
group2 is not None and group2.plot(ax=ax, **c2)
|
group2 is not None and group2.plot(ax=ax, **c2)
|
||||||
|
@ -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,
|
-- 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_clip;
|
drop function if exists wm_bbox;
|
||||||
create function wm_clip(
|
create function wm_bbox(
|
||||||
geom geometry,
|
|
||||||
center text,
|
center text,
|
||||||
projection_scale integer,
|
projection_scale integer,
|
||||||
projection_width float
|
projection_width_cm float
|
||||||
) returns geometry as $$
|
) returns geometry as $$
|
||||||
declare
|
declare
|
||||||
gcenter geometry;
|
gcenter geometry;
|
||||||
bbox geometry;
|
|
||||||
halfX float;
|
halfX float;
|
||||||
halfY float;
|
halfY float;
|
||||||
begin
|
begin
|
||||||
halfX = projection_scale * projection_width / 2;
|
halfX = projection_scale * projection_width_cm / 2;
|
||||||
halfY = halfX * sqrt(2);
|
halfY = halfX * sqrt(2);
|
||||||
select way from wm_visuals where name=center into gcenter;
|
select way from wm_visuals where name=center into gcenter;
|
||||||
if gcenter is null then
|
if gcenter is null then
|
||||||
raise 'center % not found', center;
|
raise 'center % not found', center;
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
bbox = st_envelope(
|
return st_envelope(
|
||||||
st_project(gcenter, halfX, radians(90)),
|
st_union(
|
||||||
st_project(gcenter, halfY, 0)
|
st_translate(gcenter, halfX, halfY),
|
||||||
|
st_translate(gcenter, -halfX, -halfY)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return st_intersection(bbox, geom);
|
|
||||||
end
|
end
|
||||||
$$ language plpgsql;
|
$$ language plpgsql;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user