Permalink
Browse files

A simple utility for converting data from Strætó from ISN93 to WGS84.

  • Loading branch information...
0 parents commit 3761e330cf2eb4049ef84f6acc5357b4c037c325 @gudmundur gudmundur committed Dec 28, 2011
Showing with 178 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +22 −0 LICENSE
  3. +40 −0 README.md
  4. +82 −0 isn.js
  5. +11 −0 package.json
  6. +20 −0 stops.coffee
@@ -0,0 +1,3 @@
+*.swp
+node_modules
+*.csv
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2009-2011 Guðmundur Bjarni Ólafsson <gudmundur.bjarni@gmail.com>
+
+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.
@@ -0,0 +1,40 @@
+# Strætó.is utilities
+
+A set of utilities for working with data coming from [Strætó.is][straeto].
+
+## Installing
+
+To run the utilities, you need to have [Node.js][nodejs] 0.6+, [npm][npmjs] and [CoffeeScript][coffeescript] installed.
+
+ % git clone http://github.com/gudmundur/straeto-utilities
+ % npm install
+
+If you don't have CoffeeScript installed, the setup of this project needs it installed globally
+
+ % npm install coffee-script -g
+
+## Converting stops from ISN93 to WGS84
+
+To convert ISN93 coordinates from Strætó, export the entire data file to csv, run the `stops.coffee` and off you go. The script arguments are
+
+ % coffee stops
+ Usage: stops input_file.csv output_file.csv
+ % coffee stops stops.csv nicely_formatted_stops.csv
+
+## Caveats
+
+Currently I'm working on getting confirmation for that the data I've obtained from Strætó is indeed public.
+
+Additionally I'm working out which license Ævar has on his ISN93 conversion code.
+
+## Contributions
+
+* [Ævar Arnfjörð Bjarmason](https://github.com/avar), the ISN93 to WGS84 convertion code comes from this rockstar.
+* [Björgvin Ragnarsson](https://github.com/nifgraup), various tech and legal aspect pointers.
+
+
+[straeto]: http://www.straeto.is
+[nodejs]: http://nodejs.org
+[npmjs]: http://npmjs.org
+[coffeescript]: http://jashkenas.github.com/coffee-script/
+[isn]: https://gist.github.com/585850
82 isn.js
@@ -0,0 +1,82 @@
+exports.isnet93_to_wgs84 = function(xx, yy) {
+ this.x = xx;
+ this.y = yy;
+
+ this.a = 6378137.0;
+ this.f = 1/298.257222101;
+
+ this.lat1 = 64.25;
+ this.lat2 = 65.75;
+ this.latc = 65.00;
+ this.lonc = 19.00;
+
+ this.eps = 0.00000000001;
+
+
+
+ this.fx = function(p) {
+ return this.a * Math.cos(p/this.rho)/Math.sqrt(1 - Math.pow(this.e*Math.sin(p/this.rho),2));
+ }
+
+ this.f1 = function(p) {
+ return Math.log( (1 - p)/(1 + p) );
+ }
+
+ this.f2 = function(p) {
+ return this.f1(p) - this.e * this.f1(this.e * p);
+ }
+
+ this.f3 = function(p) {
+ return this.pol1*Math.exp( (this.f2(Math.sin(p/this.rho)) - this.f2sin1)*this.sint/2);
+ }
+
+
+
+
+
+ this.rho = 45/Math.atan2(1.0,1.0);;
+ this.e = Math.sqrt(this.f * (2 - this.f));
+
+ this.dum = this.f2(Math.sin(this.lat1/this.rho)) - this.f2(Math.sin(this.lat2/this.rho));;
+ this.sint = 2 * ( Math.log(this.fx(this.lat1)) - Math.log(this.fx(this.lat2)) ) / this.dum;
+
+ this.f2sin1 = this.f2(Math.sin(this.lat1/this.rho));
+ this.pol1 = this.fx(this.lat1)/this.sint;
+ this.polc = this.f3(this.latc) + 500000.0;
+
+ this.peq = this.a * Math.cos(this.latc/this.rho)/(this.sint*Math.exp(this.sint*Math.log((45-this.latc/2)/this.rho)));
+
+ this.pol = Math.sqrt( Math.pow(this.x-500000,2) + Math.pow(this.polc-this.y,2));
+
+ this.lat = 90 - 2 * this.rho * Math.atan( Math.exp( Math.log( this.pol / this.peq ) / this.sint ) );
+ this.lon = 0;
+
+ this.fact = this.rho * Math.cos(this.lat / this.rho) / this.sint / this.pol;
+
+
+
+ this.delta = 1.0;
+ while( Math.abs(this.delta) > this.eps ) {
+ this.delta = ( this.f3(this.lat) - this.pol ) * this.fact;
+ this.lat += this.delta;
+ }
+
+ this.lon = -(this.lonc + this.rho * Math.atan( (500000 - this.x) / (this.polc - this.y) ) / this.sint);
+
+
+
+
+
+
+
+
+
+ this.getLat = function() {
+ return this.lat.toFixed(5);
+ }
+
+ this.getLon = function() {
+ return this.lon.toFixed(5);
+ }
+}
+
@@ -0,0 +1,11 @@
+{
+ "name": "straeto-dataconverter",
+ "description": "A set of utilities for converting official data from Strætó.is",
+ "version": "0.0.1",
+ "author": "Guðmundur Bjarni Ólafsson",
+
+ "dependencies": {
+ "csv": "0.0.10"
+ }
+}
+
@@ -0,0 +1,20 @@
+csv = require 'csv'
+isn = require './isn'
+
+n = 1e-6
+
+[input, output] = process.argv[2..]
+
+unless input and output
+ console.log 'Usage: stops input_file output_file'
+ return
+
+csv().fromPath(input)
+ .toPath(output)
+ .transform((data, index) ->
+ return ['stopId', 'long name', 'short name', 'latitude', 'longitude'] if index is 0
+ [stopId, longName, shortName, easting, northing] = data
+
+ res = new isn.isnet93_to_wgs84(easting * n, northing * n)
+ return [stopId, longName, shortName, res.lat, res.lon]
+ )

0 comments on commit 3761e33

Please sign in to comment.