Last active
March 7, 2021 00:30
-
-
Save versx/a0915c6bd95a080b6ff60cd539d4feb6 to your computer and use it in GitHub Desktop.
Convert geoJSON format file to separate INI format files by geoJSON property name
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'; | |
const fs = require('fs'); | |
// Customize as required | |
const inFile = process.argv[2]; | |
fs.readFile(inFile, 'utf8', (err, data) => { | |
const geoJSON = JSON.parse(data); | |
geoJSON.features.forEach(feature => { | |
let geoFence = ''; | |
if (feature.geometry.type === 'Polygon') { | |
geoFence += `[${feature.properties.name}]\n`; | |
feature.geometry.coordinates.forEach(coordinateGroup => { | |
coordinateGroup.pop(); | |
coordinateGroup.forEach(point => { | |
geoFence += `${point[1]},${point[0]}\n`; | |
}); | |
}); | |
} | |
fs.writeFile(feature.properties.name + '.txt', geoFence, 'utf8', () => { }); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment