import { readFile, writeFile } from 'fs/promises'; // const getBoundingBox = (coordinates: any) => { // return coordinates.reduce( // (coordinatesBoundingBox, polygonGroup) => { // const pg = polygonGroup.reduce( // (polygonGroupBoundingBox, polygon) => { // return [ // Math.min() // ] // }, // coordinatesBoundingBox // ) // }, // [[180, -90], [-180, 90]] // ) // } const main = async () => { let json; try { const jsonBuffer = await readFile('scripts/generate-bounding-box-data/ne_10m_admin_0_countries.json'); const jsonString = jsonBuffer.toString('utf-8'); json = JSON.parse(jsonString); } catch { process.stderr.write('Unable to read Admin 0 Countries GeoJSON. Obtain data from Natural Earth and convert to GeoJSON.'); process.exit(1); return; } const recognizedCountries = json.features.filter(f => f.properties['ISO_A2_EH'] !== '-99'); await writeFile( 'scripts/generate-bounding-box-data/sample-russia.json', JSON.stringify( json.features.find(f => f.properties['NAME'] === 'Russia'), null, 2 ) ); const countries = recognizedCountries.map(f => ({ name: f.properties['NAME'], countryCode: f.properties['ISO_A2_EH'], })) .sort((a, b) => a.name.localeCompare(b.name)); countries.forEach(c => { console.log(c); }) } void main();