-
Notifications
You must be signed in to change notification settings - Fork 1
/
final_zones.sql
51 lines (48 loc) · 1.07 KB
/
final_zones.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- From the import of Mui's final zones table.....
-- The 1 byte id is p0*25. Or p0 ~ zone_number/25
alter table final_zones add column zone_number integer;
update final_zones set zone_number = (p0*25)::integer;
create table final_zones_rast as
with t as (
select rast
from avg_0625.zones_map
limit 1
),
v(t,b,e) as (
values (ARRAY['8BUI','32BF','32BF','32BF','32BF','32BF'],
ARRAY[
ROW(null,'8BUI',0,0),
ROW(null,'32BF',0,0),
ROW(null,'32BF',0,0),
ROW(null,'32BF',0,0),
ROW(null,'32BF',0,0),
ROW(null,'32BF',0,0)]::addbandarg[],
ARRAY[0.0,0,0,0,0,0])
),
r as (
select
st_union(st_asRaster(geom,rast,t,
ARRAY[(p0*25)::integer::float,p0,p1,p2,h1,h2],e)) as rast
from final_zones,t,v
),
tot as (
select st_addBand(rast,b) as rast from t,v
union
select rast from r
)
select st_union(rast) as rast
from tot;
create table final_zones_pixels as
with f as (
select (st_pixelascentroids(rast,1)).*
from final_zones_rast
),
p as (
select st_x(geom) as east,st_y(geom) as north,val
from f
)
select
pid,east,north,val
from p
left join cimis_boundary
using (east,north);