From b28755bbcdaa8a916c13c196b46e7ba4ef1606dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 19 May 2021 22:57:46 +0300 Subject: [PATCH] integration test demo --- slides-2021-03-29.txt | 4 ++-- tests-integration.sql | 9 ++++++--- wm.sql | 18 +++++++++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/slides-2021-03-29.txt b/slides-2021-03-29.txt index a12d1d3..85d49c6 100644 --- a/slides-2021-03-29.txt +++ b/slides-2021-03-29.txt @@ -78,11 +78,11 @@ linijinių objektų generalizacijai (Lietuvoje -- GDR50 ir GDR250 analogus) # Tolimesnis pritaikymas -Sukurta algoritmo techninė realizacija atviro kodo GIS bus pradžia tolesniam jo +- Sukurta algoritmo techninė realizacija atviro kodo GIS bus pradžia tolesniam jo pritaikymui kitiems gamtiniams objektams: ežerų kranto linija, jūrų, kontinentų, miškų ribos. -Kadangi rezultatas bus techninė realizacija, o ne rašinėlis, tai suteikia +- Kadangi rezultatas bus techninė realizacija, o ne rašinėlis, tai suteikia toliau galimybę vystyti sprendimą. # Demonstracija diff --git a/tests-integration.sql b/tests-integration.sql index 541d4a2..fbd7032 100644 --- a/tests-integration.sql +++ b/tests-integration.sql @@ -1,5 +1,8 @@ \i wm.sql -drop table if exists agg_rivers_wm; -create table agg_rivers_wm (name text, way geometry); -insert into agg_rivers_wm (name, way) select name, ST_SimplifyWM(way, true) from agg_rivers; +drop table if exists debug_wm; +create table debug_wm(name text, 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, true) from agg_rivers; diff --git a/wm.sql b/wm.sql index 1873323..2adf2e9 100644 --- a/wm.sql +++ b/wm.sql @@ -276,7 +276,13 @@ begin fourpi = 4*radians(180); for i in 1..array_length(bends, 1) loop bend = bends[i]; - select st_makepolygon(st_addpoint(bend, st_startpoint(bend))) into polygon; + if st_numpoints(bend) < 3 then + cmp = 0; + area = 0; + polygon = null; + else + select st_makepolygon(st_addpoint(bend, st_startpoint(bend))) into polygon; + end if; -- Compactness Index (cmp) is defined as "the ratio of the area of the -- polygon over the circle whose circumference length is the same as the -- length of the circumference of the polygon". I assume they meant the @@ -285,15 +291,17 @@ begin -- 2. get polygon perimeter = u. Pretend it's our circle's circumference. -- 3. get A (area) of the circle from circumference u := (u^2)/(4*pi) -- 4. divide area by A: cmp = P/((u^2)*4*pi) = 4*pi*P/u^2 - select st_area(polygon) into area; - select fourpi*area/(st_perimeter(polygon)^2) into cmp; - if cmp > 0 then + if polygon is not null then + select st_area(polygon) into area; + select fourpi*area/(st_perimeter(polygon)^2) into cmp; + end if; + if area > 0 then select (area*(0.75/cmp)) into adjsize; end if; if dbg then insert into debug_wm (name, way, props) values( 'bend_attrs_' || i, - polygon, + bend, json_build_object('area', area, 'cmp', cmp, 'adjsize', adjsize) ); end if;