blob bdbeb61b (1654B) - 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_bbox; 21 create function wm_bbox( 22 center text, 23 projection_scale integer, 24 projection_width_cm float 25 ) returns geometry as $$ 26 declare 27 gcenter geometry; 28 halfX float; 29 halfY float; 30 begin 31 halfX = projection_scale * projection_width_cm / 2; 32 halfY = halfX * sqrt(2); 33 select way from wm_visuals where name=center into gcenter; 34 if gcenter is null then 35 raise 'center % not found', center; 36 end if; 37 38 return st_envelope( 39 st_union( 40 st_translate(gcenter, halfX, halfY), 41 st_translate(gcenter, -halfX, -halfY) 42 ) 43 ); 44 end 45 $$ language plpgsql; 46 47 do $$ 48 declare 49 npoints bigint; 50 secs bigint; 51 begin 52 select * from ST_SimplifyWM_Estimate((select st_union(way) from wm_rivers)) into npoints, secs; 53 raise notice 'Total points: %', npoints; 54 raise notice 'Expected duration: %s (+-%s)', ceil(secs), floor(secs*.5); 55 end $$ language plpgsql; 56 57 delete from wm_debug where name in (select distinct name from wm_rivers); 58 delete from wm_demo where name in (select distinct name from wm_rivers); 59 insert into wm_demo (name, way) select name, ST_SimplifyWM(way, name) from wm_rivers;