Created
March 18, 2015 17:48
-
-
Save veltman/e2f1b25ab6236738bf2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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