bend attrs

This commit is contained in:
Motiejus Jakštys 2021-04-06 17:48:25 +03:00
parent 0abcd16c99
commit d0972307e2
3 changed files with 42 additions and 16 deletions

View File

@ -1,5 +1,6 @@
SOURCE ?= lithuania-latest.osm.pbf SOURCE ?= lithuania-latest.osm.pbf
WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas' OR name='Žeimena' OR name='Lakaja' #WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas' OR name='Žeimena' OR name='Lakaja'
WHERE ?= name='Žeimena' OR name='Lakaja'
SLIDES = slides-2021-03-29.pdf 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
@ -15,7 +16,7 @@ test-integration: .faux_filter-rivers
.PHONY: clean .PHONY: clean
clean: clean:
-./db stop -./db stop
-rm -r .faux_test .faux_filter-rivers .faux_import-osm .faux.db \ -rm -r .faux_test .faux_filter-rivers .faux_import-osm .faux_db \
version.tex test-figures.pdf _minted-mj-msc \ version.tex test-figures.pdf _minted-mj-msc \
$(shell git ls-files -o mj-msc*) \ $(shell git ls-files -o mj-msc*) \
$(SLIDES) $(SLIDES)
@ -45,22 +46,22 @@ mj-msc-full.pdf: mj-msc.pdf version.tex $(ARCHIVABLES)
test-figures.pdf: layer2img.py .faux_test test-figures.pdf: layer2img.py .faux_test
python ./layer2img.py --group1-table=figures --group1-arrows=yes --outfile=$@ python ./layer2img.py --group1-table=figures --group1-arrows=yes --outfile=$@
.faux_test: tests.sql wm.sql .faux.db .faux_test: tests.sql wm.sql .faux_db
./db -f tests.sql ./db -f tests.sql
touch $@ touch $@
.faux_filter-rivers: .faux_import-osm .faux_filter-rivers: .faux_import-osm Makefile
./db -v where="$(WHERE)" -f aggregate-rivers.sql ./db -v where="$(WHERE)" -f aggregate-rivers.sql
touch $@ touch $@
.faux_import-osm: $(SOURCE) .faux.db .faux_import-osm: $(SOURCE) .faux_db
PGPASSWORD=osm osm2pgsql \ PGPASSWORD=osm osm2pgsql \
-c --multi-geometry \ -c --multi-geometry \
-H 127.0.0.1 -d osm -U osm \ -H 127.0.0.1 -d osm -U osm \
$< $<
touch $@ touch $@
.faux.db: .faux_db:
./db start ./db start
touch $@ touch $@

View File

@ -1,8 +1,8 @@
\i wm.sql \i wm.sql
drop table if exists debug_wm; drop table if exists wm_debug;
create table debug_wm(stage text, name text, gen bigint, nbend bigint, way geometry, props json); create table wm_debug(stage text, name text, gen bigint, nbend bigint, way geometry, props json);
drop table if exists demo_wm; drop table if exists wm_demo;
create table demo_wm (name text, i bigint, way geometry); create table wm_demo (name text, i bigint, way geometry);
insert into demo_wm (name, way) select name, ST_SimplifyWM(way, name) from agg_rivers; insert into wm_demo (name, way) select name, ST_SimplifyWM(way, name) from agg_rivers;

View File

@ -262,6 +262,7 @@ $$ language plpgsql;
drop function if exists bend_attrs; drop function if exists bend_attrs;
drop function if exists isolated_bends;
drop type if exists t_bend_attrs; drop type if exists t_bend_attrs;
create type t_bend_attrs as ( create type t_bend_attrs as (
bend geometry, bend geometry,
@ -269,7 +270,8 @@ create type t_bend_attrs as (
cmp real, cmp real,
adjsize real, adjsize real,
baselinelength real, baselinelength real,
avg_curvature real curvature real,
isolated boolean
); );
create function bend_attrs(bends geometry[], dbgname text default null) returns setof t_bend_attrs as $$ create function bend_attrs(bends geometry[], dbgname text default null) returns setof t_bend_attrs as $$
declare declare
@ -287,7 +289,8 @@ begin
res.cmp = 0; res.cmp = 0;
res.adjsize = 0; res.adjsize = 0;
res.baselinelength = st_distance(st_startpoint(bend), st_endpoint(bend)); res.baselinelength = st_distance(st_startpoint(bend), st_endpoint(bend));
res.avg_curvature = inflection_angle(bend) / st_length(bend); res.curvature = inflection_angle(bend) / st_length(bend);
res.isolated = false;
if st_numpoints(bend) >= 3 then if st_numpoints(bend) >= 3 then
polygon = st_makepolygon(st_addpoint(bend, st_startpoint(bend))); polygon = st_makepolygon(st_addpoint(bend, st_startpoint(bend)));
-- Compactness Index (cmp) is defined as "the ratio of the area of the -- Compactness Index (cmp) is defined as "the ratio of the area of the
@ -316,17 +319,37 @@ begin
'cmp', res.cmp, 'cmp', res.cmp,
'adjsize', res.adjsize, 'adjsize', res.adjsize,
'baselinelength', res.baselinelength, 'baselinelength', res.baselinelength,
'avg_curvature', res.avg_curvature 'curvature', res.curvature
) )
); );
end if; end if;
return next res; return next res;
end loop; end loop;
end; end;
$$ language plpgsql; $$ language plpgsql;
create function isolated_bends(INOUT bendattrs t_bend_attrs[], dbgname text default null) as $$
declare
isolation_threshold constant real default 0.2; -- if neighbor's curvatures are within, it's isolated
this real;
res t_bend_attrs;
i int4;
begin
i = 2;
while i < array_length(bendattrs, 1)-1 loop
this = bendattrs[i].curvature * isolation_threshold;
if bendattrs[i-1].curvature < this and bendattrs[i+1].curvature < this then
res = bendattrs[i];
res.isolated = true;
bendattrs[i] = res;
i = i + 2;
else
i = i + 1;
end if;
end loop;
end
$$ language plpgsql;
-- ST_SimplifyWM simplifies a given geometry using Wang & Müller's -- ST_SimplifyWM simplifies a given geometry using Wang & Müller's
-- "Line Generalization Based on Analysis of Shape Characteristics" algorithm, -- "Line Generalization Based on Analysis of Shape Characteristics" algorithm,
-- 1998. -- 1998.
@ -338,6 +361,7 @@ declare
line geometry; line geometry;
lines geometry[]; lines geometry[];
bends geometry[]; bends geometry[];
bend_attrs t_bend_attrs[];
mutated boolean; mutated boolean;
l_type text; l_type text;
begin begin
@ -408,6 +432,7 @@ begin
-- self-crossing mutations are done, calculate bend properties -- self-crossing mutations are done, calculate bend properties
perform bend_attrs(bends, dbgname); perform bend_attrs(bends, dbgname);
end loop; end loop;
end loop; end loop;