Skip to content

Commit b9782e5

Browse files
committed
Update script to save list of ISO country codes
1 parent 1cae8cb commit b9782e5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

topojson/bin/process_geodata.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ function getJsonFile(filename) {
3131
}
3232
}
3333

34+
function createCountriesList(geojsonPath, outputPath) {
35+
const geojson = getJsonFile(geojsonPath);
36+
if (!geojson.features) return;
37+
38+
const countryData = geojson.features
39+
.map((feature) => {
40+
const { iso3cd, nam_en } = feature.properties;
41+
return { iso3cd, name: nam_en };
42+
})
43+
.sort((a, b) => a.name.localeCompare(b.name));
44+
45+
fs.writeFileSync(outputPath, JSON.stringify(countryData));
46+
}
47+
3448
function addCentroidsToGeojson(geojsonPath) {
3549
const geojson = getJsonFile(geojsonPath);
3650
if (!geojson.features) return;
@@ -375,6 +389,9 @@ const commandsCountries50m = [
375389
await mapshaper.runCommands(commandsCountries50m);
376390
clampToAntimeridian(outputFilePathCountries50m);
377391

392+
// Build list of countries, ISO codes for documentation
393+
createCountriesList(outputFilePathCountries50m, `${outputDirTopojson}/country_names_iso_codes.json`);
394+
378395
// Get land from all polygon features
379396
const inputFilePathLand50m = outputFilePathCountries50m;
380397
const outputFilePathLand50m = `${outputDirGeojson}/${unFilename}_50m/land.geojson`;

0 commit comments

Comments
 (0)