Created
November 20, 2018 22:41
-
-
Save mappingvermont/c84ee4ada3fc084f94d61bb96b9ce154 to your computer and use it in GitHub Desktop.
Bash one-liners of interest
This file contains 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
bash one-liners | |
get list of GLAD geostores in the last 30 days | |
gcloud logging read "(resource.type="container" AND resource.labels.cluster_name="wri-prod" AND resource.labels.namespace_id="default" AND resource.labels.container_name="forest-change" AND textPayload:(geostore))" --freshness 30d | grep glad | grep -v .py | grep -o 'geostore=.*' | cut -f2- -d= | cut -d'&' -f1 | sort | uniq | |
now need to do the same except for download from that dataset - download/3bec70f3-136b-4046-80c6-2a05afd741c6 | |
gcloud logging read "(resource.type="container" AND resource.labels.cluster_name="wri-prod" AND resource.labels.namespace_id="default" AND logName="projects/resource-watch/logs/document" AND jsonPayload.src.func = "toSQLMiddleware" AND ("geostore" AND "lat"))" --freshness 30d | grep geostore | |
# gdal_translate | |
for i in src/*; do gdal_translate $i final/$(basename -- "$i") -co COMPRESS=LZW -projwin -58.6 -9 -58.5 -9.1; done | |
# rename looking through crazy directories | |
for i in source/*/*/*/*/*/*/*; do newname="$(echo $i | cut -d / -f 4).tif"; cp $i glad_$newname; done; | |
# look through a bunch of TSVs for unique polyname/iso/adm1/adm2 | |
for file in source/*; do awk -F"\t" '{ print $2, $7, $8, $9}' $file | sort | uniq > output/$(basename $file); done | |
# iterate over list of CSV of geostore_id,error text. build geostore URL, use jq to parse result then write to file | |
while read p; do fname="$(echo "$p" | cut -d, -f1 )"; curl http://production-api.globalforestwatch.org/geostore/$fname | jq .data.attributes.geojson > $fname.geojson; done < dl.csv | |
# do the above but combine into one geojson | |
while read p; do fname="$(echo "$p" | cut -d, -f1 )"; curl -s http://production-api.globalforestwatch.org/geostore/$fname | jq .data.attributes.geojson.features[0] | json-minify ; done < ../dl.csv | fio collect > all.geojson | |
# do the above + label each polygon with its ID | |
while read p; do fname="$(echo "$p" | cut -d, -f1 )"; curl -s http://production-api.globalforestwatch.org/geostore/$fname | jq --arg fname $fname '.data.attributes.geojson.features[0] + {properties: {geostore_id: $fname}}' | json-minify ; done < ../dl.csv | fio collect > all.geojson | |
# sum feature count for all layers in a geodatabase | |
ogrinfo plantations_merged_single.gdb -so -al | grep Feature | cut -d: -f2 | paste -sd+ - | bc | |
# convert z|x|y map tile table to geojson | |
awk -F',' 'BEGIN{OFS=",";} {print "[" $1,$2,$3 "]"; }' output.csv | grep -v 'x,y,z' | mercantile shapes | fio collect | geojsonio | |
# make a list of all plantations layers but not USA | |
ogrinfo plantations_merged_single.gdb | cut -d: -f2 | cut -d'(' -f1 | grep plant | grep -v usa | grep -v Open | sed -e 's/ //g' > out.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment