Skip to content

Instantly share code, notes, and snippets.

@wboykinm
Created October 25, 2016 20:10
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 wboykinm/b79873f829388495f158df3b2f4bdfbf to your computer and use it in GitHub Desktop.
Save wboykinm/b79873f829388495f158df3b2f4bdfbf to your computer and use it in GitHub Desktop.
Planet Harvester - bulk-download images from the Planet gallery: https://www.planet.com/gallery/
// USAGE node index.js <path to target local storage> <type ("thumb", "geotiff", "full", "web")>
'use strict'
let fs = require('fs')
let request = require('request')
let async = require('async')
let localPath = process.argv[2]
let imageType = process.argv[3]
let planetUrl = 'https://www.planet.com/gallery.json'
let planetList, suffix
if (imageType === 'geotiff') {
suffix = '.tif'
} else {
suffix = '.jpg'
}
request(planetUrl, function(error, response, body) {
if (!error && response.statusCode == 200) {
planetList = JSON.parse(body)
} else {
console.log('failed')
}
async.eachSeries(planetList, function (image, callback) {
if (fs.existsSync(localPath + image.slug + suffix)) {
console.log(image.slug + ' has already been saved')
} else {
let acquisitionDate = image.acquisition_date.substring(0,9)
if (image.images[imageType]) {
console.log('Saving ' + image.images[imageType])
request(image.images[imageType]).pipe(fs.createWriteStream(localPath + image.slug + '_' + acquisitionDate + suffix))
callback();
}
}
}, function (err) {
if (err) { throw err; }
console.log('Got them all');
});
})
{
"name": "planet-harvester",
"version": "0.1.0",
"description": "A module for bulk-downloading images from the Planet gallery: https://www.planet.com/gallery/",
"main": "index.js",
"author": "bill@faraday.io",
"license": "ISC",
"dependencies": {
"async": "^2.1.2",
"https": "^1.0.0",
"request": "^2.75.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment