Skip to content

Instantly share code, notes, and snippets.

@eiriks
Forked from anderser/kommuner_med_hav.topojson
Last active August 29, 2015 14:16
Show Gist options
  • Save eiriks/c48c507a71fc4b265711 to your computer and use it in GitHub Desktop.
Save eiriks/c48c507a71fc4b265711 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
'use strict'
var topojson = require('topojson');
var fs = require('fs');
var path = require('path');
var filePath = path.join(__dirname, 'kommuner_med_hav.topojson');
fs.readFile(filePath, 'utf8', function (err, data) {
var norge = JSON.parse(data);
var kommuner = topojson.feature(norge, norge.objects.kommuner_med_hav);
var neighbors = topojson.neighbors(norge.objects.kommuner_med_hav.geometries);
var csv = 'nr, navn, naboer\r\n';
kommuner.features.forEach(function(county, i) {
county.neighbors = neighbors[i].map(function(j) { return kommuner.features[j].properties.nr; })
csv += county.properties.nr + ',' + county.properties.name +',' + county.neighbors.join("|") + '\r\n';
});
//skriv ut en csv-liste med kommunenummer, kommunenavn og en pipe (|)-separert liste over kommunenummer til nabokommuner.
console.log(csv);
});
{
"name": "grensedata",
"version": "0.0.0",
"description": "Finn nabokommuner",
"main": "naboer.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"topojson": "^1.6.18"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment