Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,17 @@ public String getFunctionsQuery(List<FunctionArgs> args) {
for (int i = 0; i < paramIds.size(); i++) {
var uuid = indicators.get(paramIds.get(i));
if (uuid != null) {
columns.add(String.format("res_%s.indicator_value as %s", i, paramIds.get(i)));
fromRes.add(String.format("left join stat_h3_transposed res_%s on (res_%s.indicator_uuid = '%s' and sh.h3 = res_%s.h3)", i, i, uuid, i));
columns.add(String.format("coalesce(avg(indicator_value) filter (where indicator_uuid = '%s'), 0) as \"%s\"",
uuid, paramIds.get(i)));
} else {
columns.add(String.format("null::float as %s", paramIds.get(i)));
}
}
String joinSQL = StringUtils.EMPTY;
for (int i = 0; i < fromRes.size(); i++) {
joinSQL += " left join stat_h3_transposed " + fromRes.get(i) + " using (h3)";
}
query = String.format(queryFactory.getSql(functionIntersectV2),
StringUtils.join(columns, ", "),
StringUtils.join(fromRes, " "),
StringUtils.join(params, ", "));

System.out.println(query);
} else {
query = String.format(queryFactory.getSql(functionIntersect),
StringUtils.join(paramIds, ", "),
Expand Down
15 changes: 10 additions & 5 deletions src/main/resources/sql.queries/function_intersect_v2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ with validated_input as (
),
boxinput as (select st_envelope(v.geom) as bbox from validated_input as v),
subdivision as (select st_subdivide(v.geom) geom from validated_input v),
hexes as (select distinct sh.h3
hexes_8 as (select distinct sh.h3
from boxinput bi
cross join subdivision sb
join stat_h3_geom sh on (sh.geom && bi.bbox and st_intersects(sh.geom, sb.geom))
join stat_h3_geom sh on (--sh.geom && bi.bbox and
st_intersects(sh.geom, sb.geom))
where sh.resolution = 8),
res as (select %s from hexes sh
%s
)
hexes(h3) as (select h3_compact_cells(array_agg(h3))
from hexes_8
),
res as (select %s
from stat_h3_transposed st
join hexes sg on (sg.h3 = st.h3)
)
select %s
from res st;