Last active
November 8, 2021 15:09
-
-
Save bitner/9435108a710d797b865326a8a82fdd8b to your computer and use it in GitHub Desktop.
dump_smallsats.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
psql <<EOD | |
SET SEARCH_PATH to public, data; | |
DROP VIEW IF EXISTS items_as_ndjson; | |
CREATE OR REPLACE VIEW items_as_ndjson AS | |
SELECT | |
date_trunc('month', datetime)::date as month, | |
datetime, | |
jsonb_build_object( | |
'id', items.id, | |
'datetime', items.datetime, | |
'collection', items.collection, | |
'geometry', st_asgeojson(items.geometry)::jsonb, | |
'properties', items.properties, | |
'assets', items.assets, | |
'links', items.links | |
) AS content | |
FROM items; | |
EOD | |
for month in $(psql -Xqt -c "select distinct(month) from data.items_as_ndjson ORDER BY month asc;") | |
do | |
echo $month | |
psql -Xc "copy (select content from data.items_as_ndjson WHERE datetime >= '$month'::timestamptz and datetime < ('$month'::timestamptz + '1 month'::interval)) to stdout;" | gzip >smallsats_items_${month}.ndjson.gz | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment