Last active
May 15, 2021 22:17
-
-
Save NickCis/2802cd90305c375f71b2f473a6a64063 to your computer and use it in GitHub Desktop.
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
// Descargar: https://github.com/alvarezgarcia/provincias-argentinas-geojson | |
const fetch = require('node-fetch'); | |
const fs = require('fs').promises; | |
async function main() { | |
const geojson = { | |
type: 'FeatureCollection', | |
features: [], | |
}; | |
const files = await fs.readdir('.'); | |
for (const file of files) { | |
if (!file.endsWith('.json') || file.endsWith('output.json') || file.endsWith('package.json')) continue; | |
const data = require(`./${file}`); | |
const province = data && data.features && data.features[0]; | |
if (!province) continue; | |
// https://datosgobar.github.io/georef-ar-api/ | |
const response = await fetch(`https://apis.datos.gob.ar/georef/api/provincias?nombre=${encodeURIComponent(province.properties.name)}`); | |
const json = await response.json(); | |
province.properties = json.provincias[0]; | |
geojson.features.push(province); | |
} | |
await fs.writeFile('./output.json', JSON.stringify(geojson)); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment