Last active
May 26, 2019 15:46
-
-
Save anderser/1216247dbd676c71a72c to your computer and use it in GitHub Desktop.
Node.js script for å finne nabokommuner fra en topojson-fil med kommunegrenser. Brukt i #kommunebygger
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