Utilities for map projections.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

  1. import { readFile, writeFile } from 'fs/promises';
  2. // const getBoundingBox = (coordinates: any) => {
  3. // return coordinates.reduce(
  4. // (coordinatesBoundingBox, polygonGroup) => {
  5. // const pg = polygonGroup.reduce(
  6. // (polygonGroupBoundingBox, polygon) => {
  7. // return [
  8. // Math.min()
  9. // ]
  10. // },
  11. // coordinatesBoundingBox
  12. // )
  13. // },
  14. // [[180, -90], [-180, 90]]
  15. // )
  16. // }
  17. const main = async () => {
  18. let json;
  19. try {
  20. const jsonBuffer = await readFile('scripts/generate-bounding-box-data/ne_10m_admin_0_countries.json');
  21. const jsonString = jsonBuffer.toString('utf-8');
  22. json = JSON.parse(jsonString);
  23. } catch {
  24. process.stderr.write('Unable to read Admin 0 Countries GeoJSON. Obtain data from Natural Earth and convert to GeoJSON.');
  25. process.exit(1);
  26. return;
  27. }
  28. const recognizedCountries = json.features.filter(f => f.properties['ISO_A2_EH'] !== '-99');
  29. await writeFile(
  30. 'scripts/generate-bounding-box-data/sample-russia.json',
  31. JSON.stringify(
  32. json.features.find(f => f.properties['NAME'] === 'Russia'),
  33. null,
  34. 2
  35. )
  36. );
  37. const countries = recognizedCountries.map(f => ({
  38. name: f.properties['NAME'],
  39. countryCode: f.properties['ISO_A2_EH'],
  40. }))
  41. .sort((a, b) => a.name.localeCompare(b.name));
  42. countries.forEach(c => {
  43. console.log(c);
  44. })
  45. }
  46. void main();