Skip to content

SimonCropp/CountryData

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CountryData

Build status NuGet Status NuGet Status

Provides a .net wrapper around the GeoNames Data. Also exposes the data as per country json files.

See Milestones for release notes.

NuGet packages

The NuGets contain a static copy of all data. This data is embedded as resources inside the assembly. No network calls are done by the assembly. To get the latests version of the data do a NuGet update. There are several options to help keep a NuGet update:

Usage

// All country info. This is only the country metadata
// and not all locationData.
var allCountryInfo = CountryLoader.CountryInfo;
var costaRicaInfo = allCountryInfo.Single(_ => _.Iso == "CR");

// Loads all location data for a specific country
var australiaData = CountryLoader.LoadAustraliaLocationData();
var name = australiaData.Name;
var state = australiaData.States[0];
var province = state.Provinces[0];
var community = province.Communities[0];
var place = community.Places[0];
var postCode = place.PostCode;
var placeName = place.Name;
var latitude = place.Location.Latitude;
var longitude = place.Location.Longitude;

snippet source | anchor

Bogus Usage

var faker = new Faker<Target>()
    .RuleFor(
        property: u => u.RandomCountryName,
        setter: (f, u) => f.Country().Name())
    .RuleFor(
        property: u => u.AustralianCapital,
        setter: (f, u) => CountryDataSet.Australia().Capital)
    .RuleFor(
        property: u => u.RandomIrelandState,
        setter: (f, u) => CountryDataSet.Ireland().State().Name)
    .RuleFor(
        property: u => u.RandomIcelandPostCode,
        setter: (f, u) => CountryDataSet.Iceland().PostCode());
var targetInstance = faker.Generate();

snippet source | anchor

Json Files

Country Codes

List of country codes: https://raw.githubusercontent.com/SimonCropp/CountryData/master/Data/countrycodes.txt

https://raw.githubusercontent.com/SimonCropp/CountryData/master/Data/PostCodes/[CountryCode].json.txt

Country Information

https://github.com/SimonCropp/CountryData/blob/master/Data/countryInfo.json.txt

Country Location Data

For example the url for Australia (AU) is:

https://raw.githubusercontent.com/SimonCropp/CountryData/master/Data/PostCodes/AU.json.txt

Structure

The GeoNames data is structured as:

Country > State > Province > Community > Place

However many countries do not have data for every level.

Icon

World designed by Pedro Santos from The Noun Project.

About

Provides a .net wrapper around the GeoNames Data

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Languages