Skip to content

Instantly share code, notes, and snippets.

@andrewharvey
Created September 24, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewharvey/a040b489bdfde8722bba to your computer and use it in GitHub Desktop.
Save andrewharvey/a040b489bdfde8722bba to your computer and use it in GitHub Desktop.
Scrips to mass download and extract animal tracks uploaded to zoatrack.org
# Scrips to mass download and extract animal tracks uploaded to zoatrack.org
#
# Originally by Andrew Harvey <andrew.harvey4@gmail.com>
# This file is licenced CC0 http://creativecommons.org/publicdomain/zero/1.0/
#
# At the time of writing, all data provided from zoatrack is released under the
# Creative Commons Attribution-NonCommercial-NoDerivs License.
# http://zoatrack.org/
get:
mkdir -p detections trajectory
curl "http://zoatrack.org/detections?projectId=[1-152]&format=shp" -o "detections/#1.zip"
curl "http://zoatrack.org/trajectory?projectId=[1-152]&format=shp" -o "trajectory/#1.zip"
curl "http://zoatrack.org/detections?projectId=[1-152]&format=kml" -o "detections/#1.kml"
curl "http://zoatrack.org/trajectory?projectId=[1-152]&format=kml" -o "trajectory/#1.kml"
find detections/ trajectory/ -type f -size 0 -exec rm -f '{}' \;
extract:
rm -rf shp
mkdir -p shp/detections shp/trajectory
for f in detections/*.zip; do b=`basename "$$f" .zip`; mkdir -p "shp/detections/$$b" ; unzip -j -d "shp/detections/$$b" "$$f" ; done
for f in trajectory/*.zip; do b=`basename "$$f" .zip`; mkdir -p "shp/trajectory/$$b" ; unzip -j -d "shp/trajectory/$$b" "$$f" ; done
joinLoad:
psql -c "DROP TABLE IF EXISTS detections;"
psql -c "DROP TABLE IF EXISTS trajectory;"
for f in shp/detections/*/*.shp; do projectid=`dirname "$$f" | cut -d'/' -f3`; ogr2ogr -f PostgreSQL -sql "select *, '$${projectid}' AS projectid from detections" -append PG: "$$f" ; done
for f in shp/trajectory/*/*.shp; do projectid=`dirname "$$f" | cut -d'/' -f3`; ogr2ogr -f PostgreSQL -sql "select *, '$${projectid}' AS projectid from trajectory" -append PG: "$$f" ; done
toGeoJSON:
mkdir -p geojson
rm -f geojson/*.geojson
ogr2ogr -f GeoJSON -select 'animalname,fromdate,todate,projectid' geojson/detections.geojson PG: detections
ogr2ogr -f GeoJSON -select 'animalname,fromdate,todate,projectid' geojson/trajectory.geojson PG: trajectory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment