From 27869c317642a36a3c3da725edd24afb01141c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 13 May 2021 18:33:01 +0300 Subject: [PATCH] add some figures, use different exaggeration algorithm --- IV/Makefile | 16 ++++++++---- IV/mj-msc.tex | 15 ++++++++--- IV/test.sql | 2 ++ IV/visuals.sql | 3 +-- IV/wm.sql | 69 +++++++++++++++++++++++++++----------------------- 5 files changed, 62 insertions(+), 43 deletions(-) diff --git a/IV/Makefile b/IV/Makefile index 69c7009..9d46544 100644 --- a/IV/Makefile +++ b/IV/Makefile @@ -40,7 +40,8 @@ RIVERS = \ salvis-visvalingam-64-chaikin-50k \ salvis-overlaid-douglas-64-chaikin-50k \ salvis-overlaid-visvalingam-64-chaikin-50k \ - salvis-wm-24-50k + salvis-wm-75-50k \ + salvis-wm-375-250k ################################# # The thesis, publishable version @@ -192,10 +193,15 @@ salvis-overlaid-visvalingam-64-chaikin-50k_1COLOR = orange salvis-overlaid-visvalingam-64-chaikin-50k_WIDTHDIV = 2 salvis-overlaid-visvalingam-64-chaikin-50k_QUADRANT = 1 -salvis-wm-24-50k_1SELECT = wm_visuals where name='salvis' -salvis-wm-24-50k_2SELECT = wm_visuals where name='salvis-wm-24' -salvis-wm-24-50k_2COLOR = orange -#salvis-wm-24-50k_WIDTHDIV = 4 +salvis-wm-75-50k_1SELECT = wm_visuals where name='salvis' +salvis-wm-75-50k_2SELECT = wm_visuals where name='salvis-wm-75' +salvis-wm-75-50k_1COLOR = orange +salvis-wm-75-50k_WIDTHDIV = 2 + +salvis-wm-375-250k_1SELECT = wm_visuals where name='salvis' +salvis-wm-375-250k_2SELECT = wm_visuals where name='salvis-wm-375' +salvis-wm-375-250k_1COLOR = orange +salvis-wm-375-250k_WIDTHDIV = 2 .faux_db: db init.sql rivers.sql bash db start diff --git a/IV/mj-msc.tex b/IV/mj-msc.tex index 3e67606..341e429 100644 --- a/IV/mj-msc.tex +++ b/IV/mj-msc.tex @@ -1292,18 +1292,25 @@ NOTE: this should provide a higher-level overview of the written code: \subsection{Generalization results of Analyzed Rivers} -Figure~\ref{fig:salvis-wm-24-50k} visualizes the generalization result for +Figure~\ref{fig:salvis-wm-75-50k} visualizes the generalization result for Šalčia and Visinčia. The generalized feature is orange. As can be seen, some isolated bends are exaggerated, and some small bends are removed. -% TODO: replace 24 to 75. \begin{figure}[ht] \centering - \includegraphics[width=.5\textwidth]{salvis-wm-24-50k} + \includegraphics[width=.5\textwidth]{salvis-wm-75-50k} \caption{{\WM}-generalized river (1:{\numprint{50000}}).} - \label{fig:salvis-wm-24-50k} + \label{fig:salvis-wm-75-50k} \end{figure} +\begin{figure}[ht] + \centering + \includegraphics[width=.5\textwidth]{salvis-wm-375-250k} + \caption{{\WM}-generalized river (1:{\numprint{250000}}).} + \label{fig:salvis-wm-375-250k} +\end{figure} + + \subsection{Generalization result comparison with national spatial data sets} % TODO: GDR50LT and GDR250LT diff --git a/IV/test.sql b/IV/test.sql index a792317..1c3dbcd 100644 --- a/IV/test.sql +++ b/IV/test.sql @@ -49,6 +49,8 @@ insert into wm_figures (name, way) values ('fig6-combi', ST_Union( insert into wm_figures (name, way) values ('selfcrossing-1-rev',ST_Reverse( ST_Translate((select way from wm_figures where name='selfcrossing-1'), 0, 60))); +update wm_figures set way=st_setsrid(way, 3857); + delete from wm_debug where name in (select distinct name from wm_figures); delete from wm_demo where name in (select distinct name from wm_figures); insert into wm_demo (name, way) select name, ST_SimplifyWM(way, .1, null, name) from wm_figures where name not in ('fig8', 'isolated-1'); diff --git a/IV/visuals.sql b/IV/visuals.sql index 797f50d..7e81d68 100644 --- a/IV/visuals.sql +++ b/IV/visuals.sql @@ -123,8 +123,7 @@ begin ('salvis-visvalingam-' || i, geom2), ('salvis-visvalingam-' || i || '-chaikin', st_chaikinsmoothing(geom2, 5)); end loop; - -- TODO: 75 - foreach i in array array[16, 24] loop + foreach i in array array[75, 375] loop geom3 = st_simplifywm((select way from wm_visuals where name='salvis'), i, 50, 'salvis-' || i); insert into wm_visuals(name, way) values ('salvis-wm-' || i, geom3); diff --git a/IV/wm.sql b/IV/wm.sql index 0c962c6..96fc197 100644 --- a/IV/wm.sql +++ b/IV/wm.sql @@ -414,9 +414,9 @@ begin return st_split(st_snap(input, blade, 0.00000001), blade); end $$ language plpgsql; --- wm_exaggerate_bend exaggerates a given bend. Must be a simple linestring. -drop function if exists wm_exaggerate_bend; -create function wm_exaggerate_bend( + +drop function if exists wm_exaggerate_bend2; +create function wm_exaggerate_bend2( INOUT bend geometry, size float, desired_size float @@ -424,9 +424,13 @@ create function wm_exaggerate_bend( declare scale constant float default 1.2; -- exaggeration enthusiasm midpoint geometry; -- midpoint of the baseline - splitbend geometry; -- bend split across its half - bendm geometry; -- bend with coefficients to prolong the lines points geometry[]; + startazimuth float; + azimuth float; + diffazimuth float; + point geometry; + sss float; + protect int = 10; begin if size = 0 then raise 'invalid input: zero-area bend'; @@ -435,35 +439,36 @@ begin st_pointn(bend, 1), st_pointn(bend, -1) ), .5); + startazimuth = st_azimuth(midpoint, st_pointn(bend, 1)); - while size < desired_size loop - splitbend = wm_st_split(bend, st_lineinterpolatepoint(bend, .5)); - -- Convert bend to LINESTRINGM, where M is the fraction by how - -- much the point will be prolonged: - -- 1. draw a line between midpoint and the point on the bend. - -- 2. multiply the line length by M. Midpoint stays intact. - -- 3. the new set of lines form a new bend. - -- Uses linear interpolation; can be updated to gaussian or similar; - -- then interpolate manually instead of relying on st_addmeasure. - bendm = st_collect( - st_addmeasure(st_geometryn(splitbend, 1), 1, scale), - st_addmeasure(st_geometryn(splitbend, 2), scale, 1) - ); - - points = array(( - select st_scale( - st_makepoint(st_x(geom), st_y(geom)), - st_makepoint(st_m(geom), st_m(geom)), - midpoint - ) - from st_dumppoints(bendm) - order by path[1], path[2] - )); - - bend = st_setsrid(st_makeline(points), st_srid(bend)); + while (size < desired_size) and (protect > 0) loop + protect = protect - 1; + for i in 2..st_npoints(bend)-1 loop + point = st_pointn(bend, i); + azimuth = st_azimuth(midpoint, point); + diffazimuth = degrees(azimuth - startazimuth); + if diffazimuth > 180 then + diffazimuth = diffazimuth - 360; + elseif diffazimuth < -180 then + diffazimuth = diffazimuth + 360; + end if; + diffazimuth = abs(diffazimuth); + if diffazimuth > 90 then + diffazimuth = 180 - diffazimuth; + end if; + sss = ((scale-1) * (diffazimuth / 90)^0.5); + point = st_transform( + st_project( + st_transform(point, 4326)::geography, + st_distance(midpoint, point) * sss, azimuth)::geometry, + 3857 + ); + bend = st_setpoint(bend, i-1, point); + end loop; size = wm_adjsize(bend); end loop; -end $$ language plpgsql; +end +$$ language plpgsql; -- wm_adjsize calculates adjusted size for a polygon. Can return 0. drop function if exists wm_adjsize; @@ -512,7 +517,7 @@ begin <> for i in 1..array_length(attrs, 1) loop if attrs[i].isolated and attrs[i].adjsize < desired_size then - bend = wm_exaggerate_bend(bends[i], attrs[i].adjsize, desired_size); + bend = wm_exaggerate_bend2(bends[i], attrs[i].adjsize, desired_size); -- does bend intersect with the previous or next -- intersect_patience bends? If they do, abort exaggeration for this one.