public SingleGeoNamesToponymHandler(ICommandEntities entities , IContainGeoNames geoNames ) { _entities = entities; _geoNames = geoNames; }
public HandleFakeWoeIdByCoordinatesQuery(IContainGeoNames geoNames , IContainGeoPlanet geoPlanet ) { _geoNames = geoNames; _geoPlanet = geoPlanet; }
public HandleSingleGeoNamesToponymQuery(ICommandEntities entities , IContainGeoNames geoNames , IUnitOfWork unitOfWork ) { _entities = entities; _geoNames = geoNames; _unitOfWork = unitOfWork; }
private static IEnumerable <Country> GetGeoNamesCountries(IContainGeoNames geoNames) { if (_geoNamesCountriesCache == null || _geoNamesCountriesUpdated.AddDays(1) < DateTime.UtcNow) { _geoNamesCountriesCache = geoNames.Countries(); _geoNamesCountriesUpdated = DateTime.UtcNow; } return(_geoNamesCountriesCache); }
public HandlePaidWoeIdByCoordinatesQuery(IContainPlaceFinder placeFinder , IContainGeoNames geoNames , IContainGeoPlanet geoPlanet ) { _placeFinder = placeFinder; _geoNames = geoNames; _geoPlanet = geoPlanet; }
public WaterBodiesByGeoServicesEntitySeeder(IProcessQueries queryProcessor , IQueryEntities entities , IContainGeoPlanet geoPlanet , IContainGeoNames geoNames ) { _queryProcessor = queryProcessor; _entities = entities; _geoPlanet = geoPlanet; _geoNames = geoNames; }
public PerformSeedAtlanticOceanWork(IProcessQueries queryProcessor , ISendMail mailSender , ILogExceptions exceptionLogger , IContainGeoPlanet geoPlanet , IContainGeoNames geoNames ) { _queryProcessor = queryProcessor; _mailSender = mailSender; _exceptionLogger = exceptionLogger; _geoPlanet = geoPlanet; _geoNames = geoNames; }
internal static int Handle(WoeIdByCoordinates query, IContainGeoNames geoNamesContainer, IContainGeoPlanet geoPlanetContainer) { if (!query.Coordinates.Latitude.HasValue) { throw new ArgumentException("Query's Coordinates.Latitude is null."); } if (!query.Coordinates.Longitude.HasValue) { throw new ArgumentException("Query's Coordinates.Longitude is null."); } int?woeId = null; // first, invoke geonames geocoder var retryCount = 0; IEnumerable <Toponym> geoNames = null; while (geoNames == null && retryCount < 6) { ++retryCount; geoNames = geoNamesContainer.FindNearbyPlaceName(new NearbyPlaceNameFinder { Latitude = query.Coordinates.Latitude.Value, Longitude = query.Coordinates.Longitude.Value, Language = "en", }); } if (geoNames == null) { throw new ApplicationException("Querying GeoNames service resulted in null result."); } geoNames = geoNames.ToArray(); foreach (var geoName in geoNames) { // try to concord with woeid var concordance = geoPlanetContainer.Concordance(ConcordanceNamespace.GeoNames, geoName.GeoNameId); if (concordance == null || concordance.WoeId <= 0) { continue; } // make sure place exists var geoPlanetPlace = geoPlanetContainer.Place(concordance.WoeId); if (geoPlanetPlace == null) { continue; } woeId = concordance.WoeId; break; } // if there is still no WOE ID, try a textual search if (!woeId.HasValue) { foreach (var geoName in geoNames) { var searchText = new StringBuilder(geoName.Name); if (!string.IsNullOrWhiteSpace(geoName.Admin3Name)) { searchText.Append(" " + geoName.Admin3Name); } if (!string.IsNullOrWhiteSpace(geoName.Admin2Name)) { searchText.Append(" " + geoName.Admin2Name); } if (!string.IsNullOrWhiteSpace(geoName.Admin1Name)) { searchText.Append(" " + geoName.Admin1Name); } searchText.Append(", " + geoName.CountryName); var geoPlanetPlaces = geoPlanetContainer.Places(searchText.ToString().Replace("/", "-")) .Where(x => x.WoeId > 0).ToArray(); NGeo.Yahoo.GeoPlanet.Place geoPlanetPlace = null; if (geoPlanetPlaces.Length == 1) { geoPlanetPlace = geoPlanetPlaces.Single(); } else if (geoPlanetPlaces.Length > 1) { // when multiple results are found, pick the one with // the closest lat & lng match var gn = geoName; Func <NGeo.Yahoo.GeoPlanet.Place, double> coordinateComparer = x => { // is this lat/lng greater or less than the geonames lat/lng? var latDiff = x.Center.Latitude > gn.Latitude ? x.Center.Latitude - gn.Latitude : gn.Latitude - x.Center.Latitude; var lngDiff = x.Center.Longitude > gn.Longitude ? x.Center.Longitude - gn.Longitude : gn.Longitude - x.Center.Longitude; return(latDiff + lngDiff); }; var closest = geoPlanetPlaces.OrderBy(coordinateComparer).ToArray(); var separation = closest.Select(coordinateComparer).First(); if (separation < 1) { geoPlanetPlace = closest.First(); } } if (geoPlanetPlace != null) { woeId = geoPlanetPlace.WoeId; } } } return(woeId.HasValue ? woeId.Value : GeoPlanetPlace.EarthWoeId); }