convert to jsonb

This commit is contained in:
Motiejus Jakštys 2021-04-08 15:19:36 +03:00
parent 15eac8ba32
commit 7937aece8b
3 changed files with 20 additions and 3 deletions

View File

@ -1,7 +1,7 @@
\i wm.sql \i wm.sql
drop table if exists wm_debug; drop table if exists wm_debug;
create table wm_debug(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 jsonb);
drop table if exists wm_demo; drop table if exists wm_demo;
create table wm_demo (name text, i bigint, way geometry); create table wm_demo (name text, i bigint, way geometry);

View File

@ -24,7 +24,7 @@ $$ language plpgsql;
-- to preview this somewhat conveniently in QGIS: -- to preview this somewhat conveniently in QGIS:
-- stage || '_' || name || ' gen:' || coalesce(gen, 'Ø') || ' nbend:' || lpad(nbend, 2, '0') -- stage || '_' || name || ' gen:' || coalesce(gen, 'Ø') || ' nbend:' || lpad(nbend, 2, '0')
drop table if exists wm_debug; drop table if exists wm_debug;
create table wm_debug(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 jsonb);
drop table if exists wm_figures; drop table if exists wm_figures;
create table wm_figures (name text, way geometry); create table wm_figures (name text, way geometry);

View File

@ -314,7 +314,7 @@ begin
dbgname, dbgname,
i, i,
bend, bend,
json_build_object( jsonb_build_object(
'area', res.area, 'area', res.area,
'cmp', res.cmp, 'cmp', res.cmp,
'adjsize', res.adjsize, 'adjsize', res.adjsize,
@ -333,11 +333,14 @@ declare
isolation_threshold constant real default 0.2; -- if neighbor's curvatures are within, it's isolated isolation_threshold constant real default 0.2; -- if neighbor's curvatures are within, it's isolated
this real; this real;
res t_bend_attrs; res t_bend_attrs;
prev_i int4;
i int4; i int4;
begin begin
i = 2; i = 2;
while i < array_length(bendattrs, 1)-1 loop while i < array_length(bendattrs, 1)-1 loop
raise notice 'number of bends in %: %', dbgname, array_length(bendattrs, 1);
this = bendattrs[i].curvature * isolation_threshold; this = bendattrs[i].curvature * isolation_threshold;
prev_i = i;
if bendattrs[i-1].curvature < this and bendattrs[i+1].curvature < this then if bendattrs[i-1].curvature < this and bendattrs[i+1].curvature < this then
res = bendattrs[i]; res = bendattrs[i];
res.isolated = true; res.isolated = true;
@ -346,6 +349,19 @@ begin
else else
i = i + 1; i = i + 1;
end if; end if;
if dbgname is not null then
insert into wm_debug (stage, name, nbend, way, props) values(
'fisolated_bends',
dbgname,
prev_i,
res.bend,
jsonb_build_object(
'isolated', res.isolated
)
);
end if;
end loop; end loop;
end end
$$ language plpgsql; $$ language plpgsql;
@ -433,6 +449,7 @@ begin
-- self-crossing mutations are done, calculate bend properties -- self-crossing mutations are done, calculate bend properties
bend_attrs = array((select bend_attrs(bends, dbgname))); bend_attrs = array((select bend_attrs(bends, dbgname)));
perform isolated_bends(bend_attrs, dbgname);
end loop; end loop;
end loop; end loop;