Skip to content

Instantly share code, notes, and snippets.

@veltman
Created March 18, 2015 17:48
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 veltman/e2f1b25ab6236738bf2d to your computer and use it in GitHub Desktop.
Save veltman/e2f1b25ab6236738bf2d to your computer and use it in GitHub Desktop.
var fs = require("fs");
fs.readFile("aurora-nowcast-map.txt","utf8",function(err,table){
// Remove comment rows and empty rows
var rows = table.split("\n").filter(function(row){
return row.match(/^[0-9\s]+[0-9][0-9\s]+$/);
}).map(function(row){
// Map to space-delimited numbers
return row.trim().split(/\s+/g).map(function(num){
return +num;
});
});
var featureCollection = {
type: "FeatureCollection",
features: []
};
// Calculate lat/lng bins
rows.forEach(function(row,i){
if (!cell) {
return true;
}
var lat0 = -90 + (180 * i / 512),
lat1 = lat0 + 1 / 512;
row.forEach(function(cell,j){
var lng0 = j / 1096 * 360,
lng1 = lng0 + 1 / 1096;
if (lng0 > 180) {
lng0 = lng0 - 360;
}
if (lng1 > 180) {
lng1 = lng1 - 360;
}
featureCollection.features.push({
type: "Feature",
properties: {
probability: cell/100
},
geometry: {
type: "Polygon",
coordinates: [[
[lng0,lat0],
[lng0,lat1],
[lng1,lat1],
[lng1,lat0],
[lng0,lat0]
]]
}
});
});
});
fs.writeFile("probabilities.geo.json",JSON.stringify(featureCollection,null," "));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment