Zdravím Vás
dostal jsem úkol - musím "vylepšit" funkci, kterou přikládám níže:
cd ~/test/freemap/elevation
scp -p -q -P 21122 92.240.244.41:/home/michal/elevation.sql.bz2 .
psql:
create table public.fm_elevation (
x int, y int,
p00 real, p01 real, p02 real, p03 real,
p10 real, p11 real, p12 real, p13 real,
p20 real, p21 real, p22 real, p23 real,
p30 real, p31 real, p32 real, p33 real);
bzcat elevation.sql.bz2 | grep -v '/*!' |grep -v 'LOCK' | sed 's/`//g' |sql mapnik
-- x = floor($Lat * 1200); => lat = x/1200
create table public.elevation as
select geography(st_makepoint(y/1200.0, x/1200.0)) as p, p11 as ele
from public.fm_elevation;
create index on elevation using gist(p);
analyze elevation;
select count(*) from elevation where st_covers((select st_buffer(geography(waym),1000) from oblasti where typ='sr'), p);
create table t_elevation as
select geography(st_makepoint(y/1200.0, x/1200.0)) as p, p11 as ele
from public.fm_elevation where st_covers((select st_buffer(geography(waym),2000) from oblasti where typ='sr'), geography(st_makepoint(y/1200.0, x/1200.0)));
create index on t_elevation using gist(p);
analyze t_elevation;
create or replace function getz(geography) returns real
LANGUAGE sql IMMUTABLE AS $$
--select ele from elevation where p && st_buffer($1, 150) order by st_distance(p, $1) asc limit 1;
select case when sum(100/(0.01+st_distance(p, $1))) > 0.5 then (sum(ele*100/(0.01+st_distance(p, $1)))/sum(100/(0.01+st_distance(p, $1))))::real else NULL end from t_elevation where p && st_buffer($1, 100);
$$;
create or replace function public.st_asgeojson3d(geography) returns text
LANGUAGE sql IMMUTABLE AS $$
select st_asgeojson(st_makeline(st_makepoint(st_x(geom), st_y(geom), round(getz(geom))))) from (select (st_dumppoints(geometry($1))).geom) as t;
$$;
tahle funkce vrací hodnotu nadm. výšky v požadovaném bodě pomocí spruměrování 8 okolních pixlu, což je v připadě vrcholových bodu nepřesné.
dá se to nějak vylepšit?
děkuji moc