Skip to content

Instantly share code, notes, and snippets.

@tuttinator
Created December 7, 2016 20:42
Show Gist options
  • Select an option

  • Save tuttinator/61b2096fc6e2a48488782c990979baff to your computer and use it in GitHub Desktop.

Select an option

Save tuttinator/61b2096fc6e2a48488782c990979baff to your computer and use it in GitHub Desktop.
Retrolens parser

Historic aerial survey data

Experiments with Retrolens.nz data.

First download the shapefile from http://files.interpret.co.nz/Retrolens/Footprints/Retrolens_shp.zip

Warning

You probably don't really want to download everything. One option is to edit the shapefile to select only the features you are interested in (i.e. the town of Wairoa).

Getting started

  • npm install or yarn
  • npm run parse ~/Downloads/Retrolens_shp/image_footprints.shp or npm run parse wairoa.shp (or whatever path to the shapefile you downloaded / edited)

Todo

Implement leafletjs web app using npm start

  • npm start

License

Data sourced from http://retrolens.nz and licensed by LINZ CC-BY 3.0

This source code is MIT licensed.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

{
"name": "historic_aerial_surveys",
"version": "1.0.0",
"description": "Experiments with retrolens.nz",
"main": "index.js",
"scripts": {
"parse": "node parse.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mkdirp": "^0.5.1",
"moment": "^2.17.1",
"shapefile": "^0.5.9"
}
}
const shapefile = require('shapefile');
const retrolensParser = require('./retrolens');
const filename = process.argv[2];
shapefile.open(filename || 'shapes/wairoa.shp')
.then(source => source.read()
.then(function parse(result) {
if (result.done) return;
let geojson = result.value;
let json = retrolensParser.processValues(geojson);
retrolensParser.saveFiles(json, geojson);
return source.read().then(parse);
}))
.catch(error => console.error(error.stack));
const moment = require('moment');
const fs = require('fs');
const mkdirp = require('mkdirp');
const https = require('https');
// Shapefile attributes have been truncated
const attributeMapping = {
"OBJECTID": "OBJECTID",
"sufi": "sufi",
"Survey": "Survey",
"Run": "Run",
"Photo_Numb": "Photo_Number",
"Alternativ": "Alternative_Survey_Name",
"Camera": "Camera",
"Camera_Seq": "Camera_Sequence",
"Nominal_Fo": "Nominal_Focal_",
"Altitude": "Altitude",
"Scale": "Scale",
"Photo_Cent": "Photo_Centre_Lat",
"Photo_Ce00": "Photo_Centre_Long",
"Date": "Date",
"Film": "Film",
"Film_Seque": "Film_Sequence_Number",
"Photo_Type": "Photo_Type",
"Format": "Format",
"Source": "Source",
"Physical_F": "Physical_Film_Condition",
"Image_Anom": "Image_Anomalies",
"Scanned": "Scanned",
"Raw_Filena": "Raw_Filename",
"Released_F": "Released_Filename",
"COPYRIGHT": "COPYRIGHT",
"CONTRACTOR": "CONTRACTOR",
"NAME": "NAME",
"Region": "Region",
"Shape_Leng": "Shape_Length",
"Shape_Area": "Shape_Area"
};
module.exports = {
processValues(geojson){
let result = {}
Object.keys(attributeMapping).forEach((key) => {
result[attributeMapping[key]] = geojson.properties[key];
});
result.Date = moment(result.Date, 'YYYYMMDD').toDate();
result.downloadLink = this.generateDownloadLink(result.Survey, result.Released_Filename);
return result;
},
saveFiles(json, geojson) {
let folder = `output/${moment(json.Date).format('YYYY-MM-DD')}/SN${json.Survey}/`;
mkdirp.sync(folder);
console.log(json);
fs.writeFileSync(`${folder}${json.OBJECTID}.json`, JSON.stringify(json, null, 2));
fs.writeFileSync(`${folder}${json.OBJECTID}.geojson`, JSON.stringify(geojson, null, 2));
let file = fs.createWriteStream(`${folder}${json.OBJECTID}.jpg`);
https.get(json.downloadLink, response => response.pipe(file));
},
generateDownloadLink(surveyId, releasedFilename, imageSize = 'High') {
return `https://files.interpret.co.nz/Retrolens/Imagery/SN${surveyId}/${releasedFilename}/${imageSize}.jpg`
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment