Skip to content

Instantly share code, notes, and snippets.

@maning
Last active December 9, 2020 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maning/18001c4190dc1ba9d3edaba607e1e903 to your computer and use it in GitHub Desktop.
Save maning/18001c4190dc1ba9d3edaba607e1e903 to your computer and use it in GitHub Desktop.
#!/bin/bash -x
# For each file, get bounds of each imagery, download imagery tiles and
# create masks/labels.
url=ph-temp/url-bld.txt #linedelimited textfile of OAM imagery, for example, http://oin-hotosm.s3.amazonaws.com/590efc68d4280a001030900c/0/ae843ead-f764-4b58-badf-d6f66eff3f3b.tif
images=ph-temp/positives-images #path to save images
masks=ph-temp/positives-masks #path to save masks
maskpoly=ph-temp/arc-buildings.geojson #polygon to rasterize
while read line || [[ -n "$line" ]]; do
#echo get bounds $line, ${line##*/}.geojson ...
rio bounds $line > ${line##*/}.geojson
echo clipping to negative polys ...
ogr2ogr -f GeoJSON -clipsrc ${line##*/}.geojson ${line##*/}_clip.geojson $maskpoly
echo get list of tiles ...
./rs cover --zoom 21 ${line##*/}_clip.geojson ${line##*/}.tiles
x=$(echo "$line" | cut -c 36- | cut -d'.' -f 1)
echo Getting tiles $x ...
./rs download "https://tiles.openaerialmap.org/"$x"/{z}/{x}/{y}.png" \
${line##*/}.tiles $images
echo Getting masks $x ...
#./rs rasterize --dataset config/dataset-building.toml --zoom 21 --size 256 \
ph-temp/arc-buildings.geojson ${line##*/}.tiles $masks
done < "$url"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment