A tool to get ISO codes and geometries from country names
<script src="https://cdn.jsdelivr.net/npm/geocountries@2" charset="utf-8"></script>
geocountries = require("geocountries@2")
Domumentation and running examples available here.
To get an ISO3 code from a country name.
geocountries.getcode("United States of America")
returns an object
{name: "United States of America", iso3: "USA", score: 1}
To visualize the matching of codes and names.
geocountries.view({
json: mydata, // a geojson
name: "name", // filed with country names
threshold: 0.9, // level of similarity
})
returns a svg chart
If you know your dataset well and you don't need to investigate it, you can skip all the previous steps and add directly the iso3 codes.
geocountries.add({
json: mydata, // a geojson
name: "name", // filed with country names
threshold: 0.9, // level of similarity
})
returns a new json with ISO3 codes and scores
Note tha you can add a patch to add or remove codes.
geocountries.add({
json: mydata, // a geojson
name: "name", // filed with country names
threshold: 0.9, // level of similarity
patch: [
{ name: "French Polynesia", iso3: "PYF" },
{ name: "Niue", iso3: "NIU" },
{ name: "Cook Islands", iso3: "COK" },
{ name: "China, Macao SAR", iso3: "MAC" },
{ name: "Southern Africa", iso3: undefined },
{ name: "South America", iso3: undefined }
]
})
A simple function to get duplicate codes
geocountries.duplicate({ json: data, field: "name" })