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
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
NON_ARCHIVABLES = notes.txt referatui.txt slides-2021-03-29.txt
@ -15,7 +16,7 @@ test-integration: .faux_filter-rivers
.PHONY: clean
clean:
-./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 \
$(shell git ls-files -o mj-msc*) \
$(SLIDES)
@ -45,22 +46,22 @@ mj-msc-full.pdf: mj-msc.pdf version.tex $(ARCHIVABLES)
test-figures.pdf: layer2img.py .faux_test
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
touch $@
.faux_filter-rivers: .faux_import-osm
.faux_filter-rivers: .faux_import-osm Makefile
./db -v where="$(WHERE)" -f aggregate-rivers.sql
touch $@
.faux_import-osm: $(SOURCE) .faux.db
.faux_import-osm: $(SOURCE) .faux_db
PGPASSWORD=osm osm2pgsql \
-c --multi-geometry \
-H 127.0.0.1 -d osm -U osm \
$<
touch $@
.faux.db:
.faux_db:
./db start
touch $@

View File

@ -1,8 +1,8 @@
\i wm.sql
drop table if exists debug_wm;
create table debug_wm(stage text, name text, gen bigint, nbend bigint, way geometry, props json);
drop table if exists wm_debug;
create table wm_debug(stage text, name text, gen bigint, nbend bigint, way geometry, props json);
drop table if exists demo_wm;
create table demo_wm (name text, i bigint, way geometry);
insert into demo_wm (name, way) select name, ST_SimplifyWM(way, name) from agg_rivers;
drop table if exists wm_demo;
create table wm_demo (name text, i bigint, way geometry);
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 isolated_bends;
drop type if exists t_bend_attrs;
create type t_bend_attrs as (
bend geometry,
@ -269,7 +270,8 @@ create type t_bend_attrs as (
cmp real,
adjsize 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 $$
declare
@ -287,7 +289,8 @@ begin
res.cmp = 0;
res.adjsize = 0;
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
polygon = st_makepolygon(st_addpoint(bend, st_startpoint(bend)));
-- Compactness Index (cmp) is defined as "the ratio of the area of the
@ -316,17 +319,37 @@ begin
'cmp', res.cmp,
'adjsize', res.adjsize,
'baselinelength', res.baselinelength,
'avg_curvature', res.avg_curvature
'curvature', res.curvature
)
);
end if;
return next res;
end loop;
end;
$$ 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
-- "Line Generalization Based on Analysis of Shape Characteristics" algorithm,
-- 1998.
@ -338,6 +361,7 @@ declare
line geometry;
lines geometry[];
bends geometry[];
bend_attrs t_bend_attrs[];
mutated boolean;
l_type text;
begin
@ -408,6 +432,7 @@ begin
-- self-crossing mutations are done, calculate bend properties
perform bend_attrs(bends, dbgname);
end loop;
end loop;