public void HierarchyParser_ParsesFileCorrectly() { var target = GeoFileReader.ReadHierarchy(@"testdata\test_hierarchy.txt").ToArray(); Assert.AreEqual(4, target.Length); //"Normal" record Assert.AreEqual(6295630, target[0].ParentId); Assert.AreEqual(6255146, target[0].ChildId); Assert.AreEqual("ADM", target[0].Type); //Zero-child Assert.AreEqual(6255149, target[1].ParentId); Assert.AreEqual(0, target[1].ChildId); Assert.AreEqual("ADM", target[1].Type); //No-type Assert.AreEqual(672027, target[2].ParentId); Assert.AreEqual(663875, target[2].ChildId); Assert.AreEqual(string.Empty, target[2].Type); //-1 parent Assert.AreEqual(-1, target[3].ParentId); Assert.AreEqual(3623365, target[3].ChildId); Assert.AreEqual(string.Empty, target[3].Type); }
public void Admin1CodesParser_ParsesFileCorrectly() { var target = GeoFileReader.ReadAdmin1Codes(@"testdata\test_admin1CodesASCII.txt").ToArray(); Assert.AreEqual(4, target.Length); Assert.AreEqual("CF.04", target[0].Code); Assert.AreEqual("Mambéré-Kadéï", target[0].Name); Assert.AreEqual("Mambere-Kadei", target[0].NameASCII); Assert.AreEqual(2386161, target[0].GeoNameId); Assert.AreEqual("This.is.a.VERY.LONG.ID", target[1].Code); Assert.AreEqual("Iğdır", target[1].Name); Assert.AreEqual("Igdir", target[1].NameASCII); Assert.AreEqual(0, target[1].GeoNameId); Assert.AreEqual("TR.80", target[2].Code); Assert.AreEqual("Şırnak", target[2].Name); Assert.AreEqual("Sirnak", target[2].NameASCII); Assert.AreEqual(443189, target[2].GeoNameId); Assert.AreEqual("UA.26", target[3].Code); Assert.AreEqual("Zaporiz’ka Oblast’", target[3].Name); Assert.AreEqual("Zaporiz'ka Oblast'", target[3].NameASCII); Assert.AreEqual(687699, target[3].GeoNameId); }
public void CustomParser_IsUsedCorrectly() { var target = new GeoFileReader().ReadRecords <CustomEntity>(@"testdata\test_custom.txt", new CustomParser(19, 5, new[] { '☃' }, Encoding.UTF7, true)).ToArray(); Assert.AreEqual(2, target.Length); CollectionAssert.AreEqual(target[0].Data, target[1].Data); }
public void FileReader_CanReadBuiltInContinentsCorrectly() { var target = GeoFileReader.ReadBuiltInContinents().ToArray(); Assert.AreEqual(7, target.Length); CollectionAssert.AreEqual(target.OrderBy(c => c.Code).Select(c => c.Code).ToArray(), new[] { "AF", "AN", "AS", "EU", "NA", "OC", "SA" }); }
public void FileReader_CanReadBuiltInFeatureClassesCorrectly() { var target = GeoFileReader.ReadBuiltInFeatureClasses().ToArray(); Assert.AreEqual(9, target.Length); CollectionAssert.AreEqual(target.OrderBy(c => c.Class).Select(c => c.Class).ToArray(), new[] { "A", "H", "L", "P", "R", "S", "T", "U", "V" }); }
public void GeoFileReader_ParsesFileCorrectly2() { var gf = new GeoFileReader(); var target = gf.ReadRecords <CustomEntity>(@"testdata\test_geofilereadercustom2.txt", new CustomParser(4, 0, new[] { '!' }, Encoding.UTF8, false)).ToArray(); Assert.AreEqual(3, target.Length); }
public void GeoFileReader_ParsesFileCorrectly1() { var gf = new GeoFileReader(); var target = gf.ReadRecords(@"testdata\test_geofilereadercustom1.txt", new CustomParser(9, 1, new[] { ',' }, Encoding.UTF8, true)).ToArray(); Assert.AreEqual(2, target.Length); }
public void ReverseGeoCode_RadialSearch_ReturnsMaxCountResults() { // Read a file with data with points in and around London in a 20Km radius var data = GeoFileReader.ReadExtendedGeoNames(@"testdata\test_GB.txt").ToArray(); var rg = new ReverseGeoCode <ExtendedGeoName>(data); var center = rg.CreateFromLatLong(51.5286416, 0); //Exactly at 0 longitude so we test left/right of prime meridian var maxresults = 10; Assert.AreEqual(47, data.Length); //File should contain 47 records total var expected_ids = new[] { 2643741, 2646003, 2643743, 6690870, 2651621, 2655775, 2636503, 2634677, 2656194, 2653266 }; Assert.AreEqual(maxresults, expected_ids.Length); // Search from the/a center in London for all points in a 10Km radius, allowing only maxresults results var searchresults = rg.RadialSearch(center, 100000.0, maxresults).ToArray(); // Number of results should match length of expected_id array Assert.AreEqual(expected_ids.Length, searchresults.Length); // Check if each result is in the expected results array foreach (var r in searchresults) { Assert.IsTrue(expected_ids.Contains(r.Id)); } }
void EnsureLoaded() { if (this.geodata == null) { lock (this.syncLock) { if (this.geodata == null) { using (var stream = this.LoadStream("admin1CodesASCII.txt")) { this.adminCodes = GeoFileReader .ReadAdmin1Codes(stream) .ToList(); } using (var stream = this.LoadStream("cities5000.txt")) { this.geodata = GeoFileReader .ReadExtendedGeoNames(stream) .Where(x => //x.FeatureCode.Equals("PPL", StringComparison.OrdinalIgnoreCase) && //( x.CountryCode.Equals("CA", StringComparison.CurrentCultureIgnoreCase) || x.CountryCode.Equals("US", StringComparison.CurrentCultureIgnoreCase) //) ) .OrderBy(x => x.Latitude) .ThenBy(x => x.Longitude) .ToList(); } } } } }
static void Main(string[] args) { var downloader = GeoFileDownloader.CreateGeoFileDownloader(); string destinationPath = Environment.CurrentDirectory; string countryPath = downloader.DownloadFile("countryInfo.txt", destinationPath).Single(); IEnumerable <CountryInfo> countries = GeoFileReader.ReadCountryInfo(countryPath); var sb = new StringBuilder(); sb.AppendLine("using System.ComponentModel.DataAnnotations;"); sb.AppendLine(); sb.AppendLine("public enum Countries"); sb.AppendLine("{"); foreach (CountryInfo country in countries) { sb.AppendLine(format( name: country.Country, groupName: country.Continent, description: country.ISO_Numeric, shortName: country.ISO_Alpha2, memberName: country.ISO_Alpha3, value: country.GeoNameId )); } sb.AppendLine("}"); File.WriteAllText("..\\..\\..\\Countries.cs", sb.ToString()); }
public void AlternateNamesParserV2_ParsesFileCorrectly() { var target = GeoFileReader.ReadAlternateNamesV2(@"testdata\test_alternateNamesV2.txt").ToArray(); Assert.AreEqual(5, target.Length); Assert.AreEqual(12453592, target[0].Id); Assert.AreEqual(7258581, target[0].GeoNameId); Assert.AreEqual("Rossmoor CDP", target[0].Name); Assert.AreEqual(string.Empty, target[0].ISOLanguage); Assert.IsNull(target[0].Type); Assert.IsFalse(target[0].IsPreferredName); Assert.IsFalse(target[0].IsColloquial); Assert.IsFalse(target[0].IsPreferredName); Assert.IsTrue(target[0].IsHistoric); Assert.AreEqual(string.Empty, target[0].From); Assert.AreEqual("19 February 2008", target[0].To); Assert.AreEqual("1961", target[1].From); Assert.AreEqual(string.Empty, target[1].To); Assert.AreEqual("قولەی کانی ماران", target[2].From); Assert.AreEqual("Qulai Kanimaran", target[2].To); Assert.AreEqual("19150903", target[3].From); Assert.AreEqual(string.Empty, target[3].To); Assert.AreEqual("1589", target[4].From); Assert.AreEqual("1925", target[4].To); }
public void Admin2CodesComposer_ComposesFileCorrectly() { var src = @"testdata\test_admin2Codes.txt"; var dst = @"testdata\test_admin2Codes.out.txt"; GeoFileWriter.WriteAdmin2Codes(dst, GeoFileReader.ReadAdmin2Codes(src)); FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 4, 0, new[] { '\t' }, Encoding.UTF8, false); }
public void Composer_HandlesGZippedFilesCorrectly() { var src = @"testdata\test_extendedgeonames.txt"; var dst = @"testdata\test_extendedgeonames.out.gz"; GeoFileWriter.WriteExtendedGeoNames(dst, GeoFileReader.ReadExtendedGeoNames(src)); Assert.AreEqual(7, GeoFileReader.ReadExtendedGeoNames(dst).Count()); }
public void TimeZoneComposer_ComposesFileCorrectly() { var src = @"testdata\test_timeZones.txt"; var dst = @"testdata\test_timeZones.out.txt"; GeoFileWriter.WriteTimeZones(dst, GeoFileReader.ReadTimeZones(src)); FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 5, 1, new[] { '\t' }, Encoding.UTF8, false); }
public void ISOLanguageCodeComposer_ComposesFileCorrectly() { var src = @"testdata\test_iso-languagecodes.txt"; var dst = @"testdata\test_iso-languagecodes.out.txt"; GeoFileWriter.WriteISOLanguageCodes(dst, GeoFileReader.ReadISOLanguageCodes(src)); FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 4, 1, new[] { '\t' }, Encoding.UTF8, false); }
public void HierarchyComposer_ComposesFileCorrectly() { var src = @"testdata\test_hierarchy.txt"; var dst = @"testdata\test_hierarchy.out.txt"; GeoFileWriter.WriteHierarchy(dst, GeoFileReader.ReadHierarchy(src)); FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 3, 0, new[] { '\t' }, Encoding.UTF8, false); }
public void ExtendedGeoNamesComposer_ComposesFileCorrectly() { var src = @"testdata\test_extendedgeonames.txt"; var dst = @"testdata\test_extendedgeonames.out.txt"; GeoFileWriter.WriteExtendedGeoNames(dst, GeoFileReader.ReadExtendedGeoNames(src)); FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 19, 0, new[] { '\t' }, Encoding.UTF8, false); }
public void FeatureCodeComposer_ComposesFileCorrectly() { var src = @"testdata\test_featureCodes_en.txt"; var dst = @"testdata\test_featureCodes_en.out.txt"; GeoFileWriter.WriteFeatureCodes(dst, GeoFileReader.ReadFeatureCodes(src)); FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 3, 0, new[] { '\t' }, Encoding.UTF8, true); }
public void GeoFileWriter_ComposesFileCorrectly2() { new GeoFileWriter().WriteRecords<CustomEntity>(@"testdata\test_geofilewritercustom2.txt", testvalues, new CustomComposer(Encoding.UTF7, '!')); var gf = new GeoFileReader(); var target = gf.ReadRecords<CustomEntity>(@"testdata\test_geofilewritercustom2.txt", new CustomParser(3, 0, new[] { '!' }, Encoding.UTF7, false)).ToArray(); Assert.AreEqual(3, target.Length); CollectionAssert.AreEqual(testvalues, target, new CustomEntityComparer()); }
public void FeatureClassesParser_ParsesFileCorrectly() { var target = GeoFileReader.ReadFeatureClasses(@"testdata\test_featureClasses_en.txt").ToArray(); Assert.AreEqual(1, target.Length); //First line in file should've been skipped Assert.AreEqual("X", target[0].Class); Assert.AreEqual("Test", target[0].Description); }
public void AlternateNamesComposerV2_ComposesFileCorrectly() { var src = @"testdata\test_alternateNamesV2.txt"; var dst = @"testdata\test_alternateNamesV2.out.txt"; GeoFileWriter.WriteAlternateNamesV2(dst, GeoFileReader.ReadAlternateNamesV2(src)); FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 10, 0, new[] { '\t' }, Encoding.UTF8, false); }
public void GeoFileWriter_ComposesFileCorrectly2() { new GeoFileWriter().WriteRecords <CustomEntity>(@"testdata\test_geofilewritercustom2.txt", testvalues, new CustomComposer(Encoding.UTF7, '!')); var gf = new GeoFileReader(); var target = gf.ReadRecords <CustomEntity>(@"testdata\test_geofilewritercustom2.txt", new CustomParser(3, 0, new[] { '!' }, Encoding.UTF7, false)).ToArray(); Assert.AreEqual(3, target.Length); CollectionAssert.AreEqual(testvalues, target, new CustomEntityComparer()); }
// Compares two data files using a GenericEntity to easily compare actual values without bothering with newline differences, // comments etc. nor trying to "understand" what they mean public static void EnsureFilesAreFunctionallyEqual(string src, string dst, int expectedfields, int skiplines, char[] fieldseparators, Encoding encoding, bool hascomments) { var parser_in = new GenericParser(expectedfields, skiplines, fieldseparators, encoding, hascomments); var parser_out = new GenericParser(expectedfields, 0, fieldseparators, encoding, false); var expected = new GeoFileReader().ReadRecords <GenericEntity>(src, FileType.Plain, parser_in).ToArray(); var actual = new GeoFileReader().ReadRecords <GenericEntity>(dst, FileType.Plain, parser_out).ToArray(); CollectionAssert.AreEqual(expected, actual, new GenericEntityComparer()); }
public void GeoNamesComposerSimple_ComposesFileCorrectly() { // In this test we test the "compact file format" (e.g. GeoName, not ExtendedGeoName) var src = @"testdata\test_geonames_simple.txt"; var dst = @"testdata\test_geonames_simple.out.txt"; GeoFileWriter.WriteGeoNames(dst, GeoFileReader.ReadGeoNames(src, false), false); FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 4, 0, new[] { '\t' }, Encoding.UTF8, false); }
public void ContinentParser_ParsesFileCorrectly() { var target = GeoFileReader.ReadContinents(@"testdata\test_continentCodes.txt").ToArray(); Assert.AreEqual(1, target.Length); //First line in file should've been skipped Assert.AreEqual("EU", target[0].Code); Assert.AreEqual("Europe", target[0].Name); Assert.AreEqual(6255148, target[0].GeoNameId); }
public void GeoNamesComposerExtended_ComposesFileCorrectly() { // In this test we test the "extended file format" (e.g. ExtendedGeoName, not GeoName) // But since GeoName cannot provide all values, all other properties should be null/empty when writing var src = @"testdata\test_geonames_ext.txt"; var dst = @"testdata\test_geonames_ext.out.txt"; GeoFileWriter.WriteGeoNames(dst, GeoFileReader.ReadGeoNames(src, true), true); FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 19, 0, new[] { '\t' }, Encoding.UTF8, false); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(mvcOptions => { mvcOptions.EnableEndpointRouting = false; }); var reader = new GeoFileReader(Configuration["GeobasePath"]); services.AddSingleton(new GeobaseContext(reader)); services.AddScoped <IGeobaseRepository, GeobaseRepository>(); services.AddMvc(); }
public void CountryInfoComposer_ComposesFileCorrectly() { // We use a *slightly* different file (test_countryInfo2 instead of test_countryInfo) because the // CountryInfoParser "fixes" phonenumbers with a missing + (e.g. 31 vs. +31); this way the files // would always differ; test_countryInfo2 has these values fixed var src = @"testdata\test_countryInfo2.txt"; var dst = @"testdata\test_countryInfo2.out.txt"; GeoFileWriter.WriteCountryInfo(dst, GeoFileReader.ReadCountryInfo(src)); FileUtil.EnsureFilesAreFunctionallyEqual(src, dst, 19, 0, new[] { '\t' }, Encoding.UTF8, true); }
public void FileReader_HandlesEmptyFilesCorrectly() { //Could use ANY entity var target1 = new GeoFileReader().ReadRecords <CustomEntity>(@"testdata\emptyfile.txt", new CustomParser(19, 5, new[] { '☃' }, Encoding.UTF7, true)).ToArray(); Assert.AreEqual(0, target1.Length); //Here's a second one var target2 = GeoFileReader.ReadExtendedGeoNames(@"testdata\emptyfile.txt").ToArray(); Assert.AreEqual(0, target2.Length); }
/// <summary> /// Getting GeoData /// </summary> /// <param name="appSettings">to know where to store the temp files</param> /// <param name="geoFileDownload">Abstraction to download Geo Data</param> /// <param name="memoryCache">for keeping status</param> public GeoReverseLookup(AppSettings appSettings, IGeoFileDownload geoFileDownload, IMemoryCache memoryCache = null, IWebLogger logger = null) { // Needed when not having this, application will fail geoFileDownload.Download().ConfigureAwait(false); _appSettings = appSettings; _logger = logger; _admin1CodesAscii = GeoFileReader.ReadAdmin1Codes( Path.Combine(appSettings.TempFolder, "admin1CodesASCII.txt")); // Create our ReverseGeoCode class and supply it with data InitReverseGeoCode(); _cache = memoryCache; }
public void Admin2CodesParser_ParsesFileCorrectly() { var target = GeoFileReader.ReadAdmin2Codes(@"testdata\test_admin2Codes.txt").ToArray(); Assert.AreEqual(2, target.Length); Assert.AreEqual("AF.01.7052666", target[0].Code); Assert.AreEqual("Darwāz-e Bālā", target[0].Name); Assert.AreEqual("Darwaz-e Bala", target[0].NameASCII); Assert.AreEqual(7052666, target[0].GeoNameId); Assert.AreEqual("CA.10.11", target[1].Code); Assert.AreEqual("Gaspésie-Îles-de-la-Madeleine", target[1].Name); Assert.AreEqual("Gaspesie-Iles-de-la-Madeleine", target[1].NameASCII); Assert.AreEqual(0, target[1].GeoNameId); }
public void FileReader_HandlesEmptyFilesCorrectly() { //Could use ANY entity var target1 = new GeoFileReader().ReadRecords<CustomEntity>(@"testdata\emptyfile.txt", new CustomParser(19, 5, new[] { '☃' }, Encoding.UTF7, true)).ToArray(); Assert.AreEqual(0, target1.Length); //Here's a second one var target2 = GeoFileReader.ReadExtendedGeoNames(@"testdata\emptyfile.txt").ToArray(); Assert.AreEqual(0, target2.Length); }
public void CustomParser_IsUsedCorrectly() { var target = new GeoFileReader().ReadRecords<CustomEntity>(@"testdata\test_custom.txt", new CustomParser(19, 5, new[] { '☃' }, Encoding.UTF7, true)).ToArray(); Assert.AreEqual(2, target.Length); CollectionAssert.AreEqual(target[0].Data, target[1].Data); }
public void GeoFileReader_DoesNotThrowOnInvalidExtensionButSpecifiedFileType() { //When filetype is specified and an unknown extension is used it should be read fine var gf = new GeoFileReader(); var target = gf.ReadRecords<CustomEntity>(@"testdata\invalid.ext", FileType.Plain, new CustomParser(5, 0, new[] { '\t' }, Encoding.UTF8, false)).ToArray(); }
public void GeoFileReader_ThrowsOnUnknownSpecifiedFileType() { //When and unknown filetype is specified an exception should be thrown var gf = new GeoFileReader(); var target = gf.ReadRecords<CustomEntity>(@"testdata\invalid.ext", (FileType)999, new CustomParser(5, 0, new[] { '\t' }, Encoding.UTF8, false)).ToArray(); }
public void GeoFileReader_ParsesFileCorrectly2() { var gf = new GeoFileReader(); var target = gf.ReadRecords<CustomEntity>(@"testdata\test_geofilereadercustom2.txt", new CustomParser(4, 0, new[] { '!' }, Encoding.UTF8, false)).ToArray(); Assert.AreEqual(3, target.Length); }
public void GeoFileReader_ThrowsOnFailureWhenAutodetectingFileType() { //When filetype == autodetect and an unknown extension is used an exception should be thrown var gf = new GeoFileReader(); var target = gf.ReadRecords<CustomEntity>(@"testdata\invalid.ext", new CustomParser(5, 0, new[] { '\t' }, Encoding.UTF8, false)).ToArray(); }