geocountries
v2.0.0
Published
A tool to get ISO codes and geometries from country names
Downloads
6
Readme
A tool to get ISO codes and geometries from country names
Installation
In browser
<script src="https://cdn.jsdelivr.net/npm/geocountries@2" charset="utf-8"></script>
In Observable
geocountries = require("geocountries@2")
Documentation
Domumentation and running examples available here.
Features
getcode
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}
view
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
add
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
Patches
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 }
]
})
Duplicate
A simple function to get duplicate codes
geocountries.duplicate({ json: data, field: "name" })