simplify debugging
This commit is contained in:
parent
ee1c05cd83
commit
fb6e178fb2
@ -11,7 +11,7 @@ begin
|
|||||||
end $$ LANGUAGE plpgsql;
|
end $$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
drop table if exists debug_wm;
|
drop table if exists debug_wm;
|
||||||
create table debug_wm(name text, way geometry, props json);
|
create table debug_wm(stage text, dbgname text, i bigint, j bigint, way geometry, props json);
|
||||||
|
|
||||||
drop table if exists figures;
|
drop table if exists figures;
|
||||||
create table figures (name text, way geometry);
|
create table figures (name text, way geometry);
|
||||||
@ -34,7 +34,7 @@ insert into figures (name, way) values ('multi-island',ST_GeomFromText('MULTILIN
|
|||||||
-- DETECT BENDS
|
-- DETECT BENDS
|
||||||
drop table if exists bends, demo_bends1;
|
drop table if exists bends, demo_bends1;
|
||||||
create table bends (name text, ways geometry[]);
|
create table bends (name text, ways geometry[]);
|
||||||
insert into bends select name, detect_bends(way) from figures;
|
insert into bends select name, detect_bends(way, name) from figures;
|
||||||
create table demo_bends1 (name text, i bigint, way geometry);
|
create table demo_bends1 (name text, i bigint, way geometry);
|
||||||
insert into demo_bends1 select name, generate_subscripts(ways, 1), unnest(ways) from bends;
|
insert into demo_bends1 select name, generate_subscripts(ways, 1), unnest(ways) from bends;
|
||||||
|
|
||||||
@ -57,14 +57,14 @@ do $$
|
|||||||
declare
|
declare
|
||||||
recs t_bend_attrs[];
|
recs t_bend_attrs[];
|
||||||
begin
|
begin
|
||||||
select array(select bend_attrs(ways, true) from inflections) into recs;
|
select array(select bend_attrs(ways, name) from inflections) into recs;
|
||||||
end
|
end
|
||||||
$$ language plpgsql;
|
$$ language plpgsql;
|
||||||
|
|
||||||
-- COMBINED
|
-- COMBINED
|
||||||
drop table if exists demo_wm;
|
drop table if exists demo_wm;
|
||||||
create table demo_wm (name text, i bigint, way geometry);
|
create table demo_wm (name text, i bigint, way geometry);
|
||||||
insert into demo_wm (name, way) select name, ST_SimplifyWM(way, true) from figures;
|
insert into demo_wm (name, way) select name, ST_SimplifyWM(way, name) from figures;
|
||||||
|
|
||||||
do $$
|
do $$
|
||||||
declare
|
declare
|
||||||
|
50
IV/wm.sql
50
IV/wm.sql
@ -3,7 +3,7 @@ SET plpgsql.extra_errors TO 'all';
|
|||||||
|
|
||||||
-- detect_bends detects bends using the inflection angles. No corrections.
|
-- detect_bends detects bends using the inflection angles. No corrections.
|
||||||
drop function if exists detect_bends;
|
drop function if exists detect_bends;
|
||||||
create function detect_bends(line geometry, OUT bends geometry[]) as $$
|
create function detect_bends(line geometry, dbgname text default null, OUT bends geometry[]) as $$
|
||||||
declare
|
declare
|
||||||
pi constant real default radians(180);
|
pi constant real default radians(180);
|
||||||
p geometry;
|
p geometry;
|
||||||
@ -266,7 +266,7 @@ create type t_bend_attrs as (
|
|||||||
adjsize real,
|
adjsize real,
|
||||||
baselinelength real
|
baselinelength real
|
||||||
);
|
);
|
||||||
create function bend_attrs(bends geometry[], dbg boolean default false) returns setof t_bend_attrs as $$
|
create function bend_attrs(bends geometry[], dbgname text default null) returns setof t_bend_attrs as $$
|
||||||
declare
|
declare
|
||||||
i int4;
|
i int4;
|
||||||
fourpi real;
|
fourpi real;
|
||||||
@ -300,9 +300,10 @@ begin
|
|||||||
if res.area > 0 then
|
if res.area > 0 then
|
||||||
select (res.area*(0.75/res.cmp)) into res.adjsize;
|
select (res.area*(0.75/res.cmp)) into res.adjsize;
|
||||||
end if;
|
end if;
|
||||||
if dbg then
|
if dbgname is not null then
|
||||||
insert into debug_wm (name, way, props) values(
|
insert into debug_wm (stage, dbgname, way, props) values(
|
||||||
'bend_attrs_' || i,
|
'ebendattrs',
|
||||||
|
dbgname,
|
||||||
bend,
|
bend,
|
||||||
json_build_object(
|
json_build_object(
|
||||||
'area', res.area,
|
'area', res.area,
|
||||||
@ -321,7 +322,7 @@ $$ language plpgsql;
|
|||||||
-- "Line Generalization Based on Analysis of Shape Characteristics" algorithm,
|
-- "Line Generalization Based on Analysis of Shape Characteristics" algorithm,
|
||||||
-- 1998.
|
-- 1998.
|
||||||
drop function if exists ST_SimplifyWM;
|
drop function if exists ST_SimplifyWM;
|
||||||
create function ST_SimplifyWM(geom geometry, dbg boolean default false) returns geometry as $$
|
create function ST_SimplifyWM(geom geometry, dbgname text default null) returns geometry as $$
|
||||||
declare
|
declare
|
||||||
dbg_stage integer;
|
dbg_stage integer;
|
||||||
i integer;
|
i integer;
|
||||||
@ -344,36 +345,47 @@ begin
|
|||||||
mutated = true;
|
mutated = true;
|
||||||
dbg_stage = 1;
|
dbg_stage = 1;
|
||||||
while mutated loop
|
while mutated loop
|
||||||
if dbg then
|
if dbgname is not null then
|
||||||
insert into debug_wm (name, way) values(
|
insert into debug_wm (stage, dbgname, i, way) values(
|
||||||
dbg_stage || 'afigures_' || i,
|
'afigures',
|
||||||
|
dbgname,
|
||||||
|
i,
|
||||||
lines[i]
|
lines[i]
|
||||||
);
|
);
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
bends = detect_bends(lines[i]);
|
bends = detect_bends(lines[i]);
|
||||||
|
|
||||||
if dbg then
|
if dbgname is not null then
|
||||||
insert into debug_wm(name, way) values(
|
insert into debug_wm(stage, dbgname, i, j, way) values(
|
||||||
dbg_stage || 'bbends_' || i || '_' || generate_subscripts(bends, 1),
|
'bbends',
|
||||||
|
dbgname,
|
||||||
|
i,
|
||||||
|
generate_subscripts(bends, 1),
|
||||||
unnest(bends)
|
unnest(bends)
|
||||||
);
|
);
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
bends = fix_gentle_inflections(bends);
|
bends = fix_gentle_inflections(bends);
|
||||||
|
|
||||||
if dbg then
|
if dbgname is not null then
|
||||||
insert into debug_wm(name, way) values(
|
insert into debug_wm(stage, dbgname, i, j, way) values(
|
||||||
dbg_stage || 'cinflections' || i || '_' || generate_subscripts(bends, 1),
|
'cinflections',
|
||||||
|
dbgname,
|
||||||
|
i,
|
||||||
|
generate_subscripts(bends, 1),
|
||||||
unnest(bends)
|
unnest(bends)
|
||||||
);
|
);
|
||||||
end if;
|
end if;
|
||||||
|
|
||||||
select * from self_crossing(bends) into bends, mutated;
|
select * from self_crossing(bends) into bends, mutated;
|
||||||
|
|
||||||
if dbg then
|
if dbgname is not null then
|
||||||
insert into debug_wm(name, way) values(
|
insert into debug_wm(stage, dbgname, i, j, way) values(
|
||||||
dbg_stage || 'dcrossings' || i || '_' || generate_subscripts(bends, 1),
|
'dcrossings',
|
||||||
|
dbgname,
|
||||||
|
i,
|
||||||
|
generate_subscripts(bends, 1),
|
||||||
unnest(bends)
|
unnest(bends)
|
||||||
);
|
);
|
||||||
end if;
|
end if;
|
||||||
@ -385,7 +397,7 @@ begin
|
|||||||
end if;
|
end if;
|
||||||
|
|
||||||
-- self-crossing mutations are done, calculate bend properties
|
-- self-crossing mutations are done, calculate bend properties
|
||||||
perform bend_attrs(bends, true);
|
perform bend_attrs(bends, dbgname);
|
||||||
end loop;
|
end loop;
|
||||||
|
|
||||||
end loop;
|
end loop;
|
||||||
|
Loading…
Reference in New Issue
Block a user