File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed
Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change 77declare
88 area_km2_uuid uuid;
99 one_uuid uuid;
10+ global_max_res integer ;
11+ coverage_max_res integer ;
1012begin
1113
1214 select internal_id into area_km2_uuid
@@ -22,11 +24,32 @@ begin
2224 return;
2325 end if;
2426
25- update bivariate_indicators_metadata
26- set max_res = (
27- select max (h3_get_resolution(h3))
27+ with resolution_counts as (
28+ select
29+ h3_get_resolution(h3) as res,
30+ count (9 ) as cnt
2831 from stat_h3_transposed
2932 where indicator_uuid = x_numerator_uuid
33+ group by 1
34+ ),
35+ global as (
36+ select max (res) as r from resolution_counts
37+ ),
38+ coverage as (
39+ select max (res) as r from resolution_counts where cnt <= 1000
40+ )
41+ select global .r , coverage .r
42+ into global_max_res, coverage_max_res
43+ from global, coverage;
44+
45+ update bivariate_indicators_metadata
46+ set
47+ max_res = global_max_res,
48+ coverage_polygon = (
49+ select ST_Transform(ST_Union(h3_cell_to_boundary_geometry(h3)), 4326 )
50+ from stat_h3_transposed
51+ where indicator_uuid = x_numerator_uuid
52+ and h3_get_resolution(h3) = coverage_max_res
3053 )
3154 where internal_id = x_numerator_uuid;
3255
You can’t perform that action at this time.
0 commit comments