-
-
Save eiriks/c48c507a71fc4b265711 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
'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); | |
}); |
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
{ | |
"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