stud

study spacejunk
Log | Files | Refs | LICENSE

blob 71b24a53 (1693B) - Raw


      1 \i wm.sql
      2 
      3 insert into wm_visuals(name, way) values('salcia-visincia',
      4   st_closestpoint(
      5     (select way from wm_rivers where name='Šalčia'),
      6     (select way from wm_rivers where name='Visinčia')
      7   )
      8 );
      9 
     10 insert into wm_visuals(name, way) values('nemunas-merkys',
     11   st_closestpoint(
     12     (select way from wm_rivers where name='Nemunas'),
     13     (select way from wm_rivers where name='Merkys')
     14   )
     15 );
     16 
     17 
     18 -- wm_envelope clips a geometry by a bounding box around a given object,
     19 -- matching dimensions of A-class paper (1 by sqrt(2).
     20 drop function if exists wm_clip;
     21 create function wm_clip(
     22   geom geometry,
     23   center text,
     24   projection_scale integer,
     25   projection_width float
     26 ) returns geometry as $$
     27 declare
     28   gcenter geometry;
     29   bbox geometry;
     30   halfX float;
     31   halfY float;
     32 begin
     33   halfX = projection_scale * projection_width / 2;
     34   halfY = halfX * sqrt(2);
     35   select way from wm_visuals where name=center into gcenter;
     36   if gcenter is null then
     37     raise 'center % not found', center;
     38   end if;
     39 
     40   bbox = st_envelope(
     41     st_project(gcenter, halfX, radians(90)),
     42     st_project(gcenter, halfY, 0)
     43   );
     44 
     45   return st_intersection(bbox, geom);
     46 end
     47 $$ language plpgsql;
     48 
     49 do $$
     50 declare
     51   npoints bigint;
     52   secs bigint;
     53 begin
     54   select * from ST_SimplifyWM_Estimate((select st_union(way) from wm_rivers)) into npoints, secs;
     55   raise notice 'Total points: %', npoints;
     56   raise notice 'Expected duration: %s (+-%s)', ceil(secs), floor(secs*.5);
     57 end $$ language plpgsql;
     58 
     59 delete from wm_debug where name in (select distinct name from wm_rivers);
     60 delete from wm_demo where name in (select distinct name from wm_rivers);
     61 insert into wm_demo (name, way) select name, ST_SimplifyWM(way, name) from wm_rivers;