Last active
April 17, 2018 08:50
-
-
Save stepankuzmin/207dabd14c60dee8687b59ef7ae62704 to your computer and use it in GitHub Desktop.
Returns FeatureCollection with first features in some dir
This file contains hidden or 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
| const fs = require("fs"); | |
| const path = require("path"); | |
| const argv = process.argv.slice(2); | |
| const dir = argv[0]; | |
| if (!dir) { | |
| console.log("Usage: node get-first-features.js [dir]"); | |
| process.exit(-1); | |
| } | |
| const fileNames = fs.readdirSync(dir).filter(fileName => { | |
| const { ext } = path.parse(fileName); | |
| return ext === ".geojson"; | |
| }); | |
| const features = fileNames.forEach(fileName => { | |
| const { name } = path.parse(fileName); | |
| const originalFileName = path.join(dir, fileName); | |
| const newFileName = path.format({ dir, base: `${name}_1.json` }); | |
| const featureCollection = JSON.parse(fs.readFileSync(originalFileName)); | |
| console.log(fileName, featureCollection.features.length); | |
| const feature = featureCollection.features[0]; | |
| fs.writeFileSync(newFileName, JSON.stringify(feature, null, 2)); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment