public IToponymData FindByName(string name) { DateTime time1 = DateTime.Now; using (var ngeoClient = new GeoNamesClient()) { DateTime time2 = DateTime.Now; var rawData = ngeoClient.Search(new SearchOptions(SearchType.Name, name) {UserName = _userName, MaxRows = 5}); DateTime time3 = DateTime.Now; var result = rawData.Select(t=>new ToponymData(t)).FirstOrDefault(t => t.ToponymType==ToponymTypeEnum.City); DateTime time4 = DateTime.Now; Debug.WriteLine(String.Format("FindByName '{0}' create {1} search {2} createObject {3}", name, (time2 - time1).TotalMilliseconds, (time3 - time2).TotalMilliseconds, (time4 - time3).TotalMilliseconds)); if (result == null) { throw new NotFoundToponymException(); } return result; } }
//Este método obtiene todos los registros de geonames dado un lugar espécifico public List <GeonameNode> GeoNames_SearchByNameEquals(string lugar) { List <GeonameNode> gnodes = new List <GeonameNode>(); using (var geoNames = new GeoNamesClient()) { var resultados = geoNames.Search(new SearchOptions(SearchType.NameEquals, lugar) { UserName = UserName }); foreach (Toponym res in resultados) { gnodes.Add(parseToponymToGeonameNode(res)); } } return(gnodes); }
private static void GeoNamesTest(out double latitude, out double longitude) { using (var ngeoClient = new GeoNamesClient()) { var result = ngeoClient.Search(new SearchOptions(SearchType.Name, "Курган") { UserName = "******", MaxRows = 5 }); foreach (var toponym in result /*.Where(t=>t.FeatureCode=="PPLA")*/) { Console.WriteLine(toponym.Name + " " + toponym.GeoNameId + " " + toponym.FeatureCode + " " + toponym.Population + " " + toponym.FeatureClassCode + " " + toponym.ToponymName); //toponym.Latitude + toponym.Longitude } latitude = result.First().Latitude; longitude = result.First().Longitude; } }
public void GeoNames_SearchByName_ShouldReturnResult_ForAdriaticSea() { using (var geoNames = new GeoNamesClient()) { const string name = "Adriatic Sea"; var results = geoNames.Search(new SearchOptions(SearchType.Name, name) { UserName = UserName }); results.ShouldNotBeNull(); results.Count.ShouldEqual(1); } }