Created
August 26, 2025 20:09
-
-
Save AndrewSepic/4e99a658f22b34423829e4b7f6246ecc to your computer and use it in GitHub Desktop.
Parse & read GeoJSON features with fs
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
| import fs from 'fs'; | |
| const filePath = './public-schools.geojson'; | |
| const data = JSON.parse(fs.readFileSync(filePath, 'utf8')); | |
| if (data.type === 'FeatureCollection' && Array.isArray(data.features)) { | |
| console.log(`Found ${data.features.length} features`); | |
| data.features.forEach((feature, index) => { | |
| const { properties, geometry } = feature; | |
| // Example: Print NAME and coordinates | |
| console.log(`${index + 1}: ${properties.NAME} -> ${geometry.coordinates}`); | |
| }); | |
| } else { | |
| console.log('File is not a featureCollection with features'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment