CSharp-Unloc-Loader
This C# library performs these steps:
- Download latest CSV files from UNECE servers with official UN location codes.
- Extract the files into a temporary directory.
- Parses and returns the locations and countries.
- Cleans up the working directory.
Example usage
The below code snippet downloads and parses the latest UN/LOCODE files from UNECE servers and writes all ports on the console.
var loader = new UnlocLoader();
loader.OnWarn += (sender, s) => Console.WriteLine($"Warn: {s}");
loader.OnInfo += (sender, s) => Console.WriteLine($"Info: {s}");
// Download and parse latest UN/LOCODE files from UNECE server.
var result = loader.LoadFromUnece();
var ports = result.Locations
.Where(l => l.Functions.Contains(Function.Port))
.ToList();
foreach (var port in ports)
{
Console.WriteLine(port.ToString());
}
Instead of loading the location files from the UNECE servers, an existing (zipped) location file can be parsed locally like this:
var result = loader.LoadFromFile(@"C:\UnlocFile.zip");
Parsed data
The following items are parsed for each location:
Property name | Description |
---|---|
UNLOC |
Five-letter UN location code |
CountryId |
Two-letter UN country code |
Name |
Accepted name of location |
SpellingName |
Name of location without diacritic signs |
Function |
List of functions of the location (e.g. port) |
ChangeReason |
Reason of change in location details (if any) |
ChangeDetails |
List of details what has changed (if any) |
Position |
Position of location (if available) |
Remarks |
Remarks for location (if available) |
Remarks
- Multiple entries with the same UN/LOCODE exists for different names of the same location.