README
geocodes
A tool to get ISO codes and geometries from country names
Installation
In browser
<script src="https://cdn.jsdelivr.net/npm/geocountries" charset="utf-8"></script>
In Observable
geocountries = require("geocountries")
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}
iso3
To get ISO3 codes from a json data set.
codes = geocountries.iso3({
json: fao,
name: "Area",
threshold: 0.7
})
returns a Map
{
"Afghanistan" => Object {name: "Afghanistan", iso3: "AFG", score: 1}
"Albania" => Object {name: "Albania", iso3: "ALB", score: 1}
"Algeria" => Object {name: "Algeria", iso3: "DZA", score: 1}
}
view
To visualize the matching of codes and names.
geocountries.view(codes)
returns a svg chart
add
To add the codes to the initial dataset
data = geocountries.add({ data: mydata, codes: codes, name: "Area" })
addiso3
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.addiso3({
data: mydata,
name: "Area",
treashold: 0.9,
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 }
]
})