Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node.js script for å finne nabokommuner fra en topojson-fil med kommunegrenser. Brukt i #kommunebygger
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
You can’t perform that action at this time.