add some figures, use different exaggeration algorithm

main
Motiejus Jakštys 2021-05-19 22:57:51 +03:00 committed by Motiejus Jakštys
parent 2f144197c1
commit 3a7ac37ae9
5 changed files with 62 additions and 43 deletions

View File

@ -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

View File

@ -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

View File

@ -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');

View File

@ -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);

69
wm.sql
View File

@ -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
<<bendloop>>
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.