Created
August 18, 2016 14:32
-
-
Save felixebert/e59a5e0ed9acaed3b63797b9f216cc15 to your computer and use it in GitHub Desktop.
Merge and Filter GeoJSON Example
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
var fs = require('fs'); | |
var files = ['Carl-Peters.geojson']; // alle geojson Dateien | |
var allWayFeatures = []; // unsere Ziel-Liste mit allen Ways | |
files.forEach(function (file) { // für jede geojson Datei ... | |
var content = fs.readFileSync(file, {encoding: 'utf-8'}); // lese Dateiinhalt als Zeichenkette | |
var geojson = JSON.parse(content); // Umwandlung in JavaScript-Objekt | |
geojson.features.forEach(function (feature) { // für jedes GeoJSON Feature (way, node, etc.) ... | |
if (feature.id.indexOf('way') >= 0) { // wenn das Feld ID den Begriff "way" enthält ... | |
allWayFeatures.push(feature); // füge das Feature unserer Ziel-Liste mit allen Ways hinzu | |
} | |
}) | |
}); | |
var newGeojson = { // packe unsere Ziel-Liste mit allen Ways in ein GeoJSON-Objekt | |
"type": "FeatureCollection", | |
"features": allWayFeatures | |
}; | |
var newGeojsonString = JSON.stringify(newGeojson, null, 4); // wandle das GeoJSON-Objekt in eine Zeichenkette um, um diese speichern zu können | |
fs.writeFileSync('ways.geojson', newGeojsonString, {encoding: 'utf-8'}); // speichere die Zeichenkette in der Datei ways.geojson |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment