Skip to content

Instantly share code, notes, and snippets.

@versx
Last active March 7, 2021 00:30
Show Gist options
  • Save versx/a0915c6bd95a080b6ff60cd539d4feb6 to your computer and use it in GitHub Desktop.
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
'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