Skip to content

Commit

Permalink
feat: add vegetation data and function
Browse files Browse the repository at this point in the history
  • Loading branch information
friedjoff committed Aug 27, 2020
1 parent 8c6f3d2 commit 00ef840
Show file tree
Hide file tree
Showing 4 changed files with 20,204 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/data/sql/V7__export_vegetation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
COPY
(WITH herb1 AS
(SELECT foresttype_code,
json_agg(herbtype_code::text::int
ORDER BY herbtype_code) herbtypes
FROM herbtype_foresttype
WHERE frequency = 1
GROUP BY foresttype_code),
herb2 AS
(SELECT foresttype_code,
json_agg(herbtype_code::text::int
ORDER BY herbtype_code) herbtypes
FROM herbtype_foresttype
WHERE frequency = 2
GROUP BY foresttype_code),
bush1 AS
(SELECT foresttype_code,
json_agg(bushtype_code::text::int
ORDER BY bushtype_code) bushtypes
FROM bushtype_foresttype
WHERE frequency = 1
GROUP BY foresttype_code),
bush2 AS
(SELECT foresttype_code,
json_agg(bushtype_code::text::int
ORDER BY bushtype_code) bushtypes
FROM bushtype_foresttype
WHERE frequency = 2
GROUP BY foresttype_code),
moss1 AS
(SELECT foresttype_code,
json_agg(mosstype_code::text::int
ORDER BY mosstype_code) mosstypes
FROM mosstype_foresttype
WHERE frequency = 1
GROUP BY foresttype_code),
moss2 AS
(SELECT foresttype_code,
json_agg(mosstype_code::text::int
ORDER BY mosstype_code) mosstypes
FROM mosstype_foresttype
WHERE frequency = 2
GROUP BY foresttype_code) SELECT json_object_agg(meta.code,json_build_object('herb', json_build_array(coalesce(herb1.herbtypes,'[]'::json),coalesce(herb2.herbtypes,'[]'::json)),'bush', json_build_array(coalesce(bush1.bushtypes,'[]'::json),coalesce(bush2.bushtypes,'[]'::json)),'moss', json_build_array(coalesce(moss1.mosstypes,'[]'::json),coalesce(moss2.mosstypes,'[]'::json)))) AS vegetation
FROM foresttype_meta meta
LEFT JOIN herb1 ON meta.code = herb1.foresttype_code
LEFT JOIN herb2 ON meta.code = herb2.foresttype_code
LEFT JOIN bush1 ON meta.code = bush1.foresttype_code
LEFT JOIN bush2 ON meta.code = bush2.foresttype_code
LEFT JOIN moss1 ON meta.code = moss1.foresttype_code
LEFT JOIN moss2 ON meta.code = moss2.foresttype_code) TO '/data/vegetation.json';
Loading

0 comments on commit 00ef840

Please # to comment.