private void VerifyDJIA(DateTime date, string djia) { GDate gdate = new GDate(date, date); var actual_djia = GeoHash.GetDowJonesAsync(gdate).ConfigureAwait(false).GetAwaiter().GetResult(); Assert.AreEqual(djia, actual_djia, $"Data line {validated+1}"); }
// TODO: Implement the more sophisticated method // TODO: Move coordinates class and add accuracy field? private PatternMiningCoordinates FindBestCoordinates(Dictionary <string, int> geohashCounts, int ruleTotalCount) { string bestGeohash = null; double highestFraction = -1; foreach (var entry in geohashCounts) { var geohash = entry.Key; var count = entry.Value; var occFraction = count / (1.0d * ruleTotalCount); if (occFraction > highestFraction) { bestGeohash = geohash; highestFraction = occFraction; } } var result = GeoHash.Decode(bestGeohash); return(new PatternMiningCoordinates() { Latitude = result.Coordinates.Lat, Longitude = result.Coordinates.Lon, Confidence = highestFraction }); }
private void TestOneRow(string[] fields) { var date = DateTime.Parse(fields[0]); var djia = fields[1]; var hashStringWest = fields[2]; var hashStringEast = fields[3]; var hashStringGlobal = fields[4]; var coord68minus30 = fields[5]; var coord68minus29 = fields[6]; var globalCoord = fields[7]; VerifyDJIA(date, djia); var actual_coordWest = GeoHash.GetGeoHash(date, 68, -30); VerifyCoord(coord68minus30, actual_coordWest, "West"); var actual_coordEast = GeoHash.GetGeoHash(date, 68, -29); VerifyCoord(coord68minus29, actual_coordEast, "East"); var actual_coordGlobal = GeoHash.GetGlobalHash(date); VerifyCoord(globalCoord, actual_coordGlobal, "Global"); }
private void Awake() { FMODStudioEventTracker.UnloadAll(); EventRegistry.Clear(); GameModeStarter.Prefab = null; GameSetup.SetInitType(InitTypes.New); GameSetup.SetGameType(GameTypes.Standard); GameSetup.SetDifficulty(DifficultyModes.Normal); TitleSceneBridge.TitleScene = this; TitleSceneBridge.GameSetup = GameSetup.Bridge; TitleSceneBridge.Cheats = Cheats.Bridge; LoadSave.ShouldLoad = false; CoopAckChecker.ACKED = false; CoopSteamServer.Shutdown(); CoopSteamClient.Shutdown(); CoopTreeGrid.Clear(); GeoHash.ClearAll(); TitleScreen.Instance = this; if (LoadAsync.Scenery) { UnityEngine.Object.Destroy(LoadAsync.Scenery); LoadAsync.Scenery = null; } this.InitMpScreenScenery(); }
private void OnExitMenu() { if (this.selected) { return; } this.selected = true; MenuMain.exitingToMenu = true; Time.timeScale = 1f; if (this.audio != null) { this.audio.PrepareForLevelLoad(); } WorkScheduler.ClearInstance(); UniqueIdentifier.AllIdentifiers.Clear(); RecastMeshObj.Clear(); if (BoltNetwork.isRunning) { if (MenuMain.< > f__mg$cache0 == null) { MenuMain.< > f__mg$cache0 = new Action(MenuMain.PostBoltShutdown); } base.StartCoroutine(this.WaitForBoltShutdown(MenuMain.< > f__mg$cache0)); return; } CoopTreeGrid.Clear(); GameSetup.SetInitType(InitTypes.New); GameSetup.SetGameType(GameTypes.Standard); GeoHash.ClearAll(); SceneManager.LoadScene("TitleSceneLoader", LoadSceneMode.Single); }
public async Task <Place> CreatePlace(Place place, string user) { if (!place.Owners.Any()) { place.Owners.Add(new Entities.Application.ListableUser { Id = user }); } if (place.MainPlaylist != null && place.MainPlaylist.Id != null && string.IsNullOrEmpty(place.MainPlaylist.Name)) { var dbUser = await this.userService.GetUser(user); var play = await this.playlistService.GetPlaylistFromSpotify(place.MainPlaylist.Id, dbUser.CurrentToken); if (play != null) { place.MainPlaylist = play; } } place.Geohash = GeoHash.Encode(place.Location.Latitude, place.Location.Longitude); var converted = _mapper.ToDbEntity(place); var dbResult = await _dao.CreatePlace(converted); if (place.MainPlaylist != null) { await this.playlistService.CreatePlaylist(dbResult.Reference.Id, place.MainPlaylist); } return(_mapper.ToApplicationEntity(dbResult)); }
public void EqualTest2() { GeoHash hash = GeoHash.EncodeWithCharacterPrecision(120, 30, 10); GeoHash hash2 = GeoHash.EncodeWithCharacterPrecision(120, 30, 10); Assert.True(hash.Equals(hash2)); }
public static TwoGeoHashBoundingBox FromBase32(string base32) { string bottomLeft = base32.Substring(0, 7); string topRight = base32.Substring(7); return(new TwoGeoHashBoundingBox(GeoHash.FromGeohashString(bottomLeft), GeoHash.FromGeohashString(topRight))); }
/// <summary> /// Bounding Box Coordinates /// Get all coordinates covered by the box in numberOfChars /// </summary> /// <param name="minLat"></param> /// <param name="minLon"></param> /// <param name="maxLat"></param> /// <param name="maxLon"></param> /// <param name="numberOfChars"></param> /// <returns>all coordinates covered by the box in numberOfChars</returns> public Coordinates[] BboxCoordinates(double minLat, double minLon, double maxLat, double maxLon, int numberOfChars = 9) { var coorList = new List <Coordinates>(); string[] hashList = GeoHash.Bboxes(minLat, minLon, maxLat, maxLat, numberOfChars); foreach (string hash in hashList) { // TODO: search all level or search current level only? Coordinates[] coors = GetCoordinates(hash); BoundingBox box = GeoHash.DecodeBbox(hash); if (BoxInBoxRange(box, minLat, minLon, maxLat, maxLon)) { // All covered by box coorList.AddRange(coors); } else { // Not all covered by box foreach (Coordinates c in coors) { if (CoordinateInBoxRange(c, minLat, minLon, maxLat, maxLon)) { coorList.Add(c); } } } } return(coorList.ToArray()); }
/// <summary> /// Bounding Polygon /// Get all the hashString covered by the polygon in numberOfChars /// </summary> /// <param name="polygon">array of coordinates describes the polygon</param> /// <param name="numberOfChars"></param> /// <returns>array of hash string</returns> public static string[] Bpolygon(Coordinates[] polygon, int numberOfChars = 9) { var hashList = new List <string>(); // Get all bounding boxes that are possible be covered by polygon Coordinates max = new Coordinates { Lat = -90, Lon = -180 }; Coordinates min = new Coordinates { Lat = 90, Lon = 180 }; foreach (Coordinates c in polygon) { max.Lat = Math.Max(max.Lat, c.Lat); max.Lon = Math.Max(max.Lon, c.Lon); min.Lat = Math.Min(min.Lat, c.Lat); min.Lon = Math.Min(min.Lon, c.Lon); } string[] bboxHash = GeoHash.Bboxes(min.Lat, min.Lon, max.Lat, max.Lon, numberOfChars); foreach (string hash in bboxHash) { BoundingBox box = GeoHash.DecodeBbox(hash); if (BoxOverlapPolygon(box, polygon)) { hashList.Add(hash); } } return(hashList.ToArray()); }
/// <summary> /// Add coordinates to database(in use) /// </summary> /// <param name="coordinate"></param> public void Add(Coordinates coordinate) { double latitude = coordinate.Lat; double longitude = coordinate.Lon; for (int numberOfChars = 1; numberOfChars <= _MaxNumberOfChar; numberOfChars++) { // Get the key string key = GeoHash.Encode(latitude, longitude, numberOfChars); // The value is coordinate // First entry if (!_Dict.ContainsKey(key)) { List <Coordinates> value = new List <Coordinates> { coordinate }; _Dict.Add(key, value); //Console.WriteLine("Add new key " + key); } // Second entry else if (_Dict.ContainsKey(key) && _Dict[key].Count < _MaxCoordinatesInValue) { _Dict[key].Add(coordinate); //Console.WriteLine("Add existent key " + key + ", " + Dict[key].Count); } // The deepest level else if (numberOfChars == _MaxCoordinatesInValue) { _Dict[key].Add(coordinate); //Console.WriteLine("Add existent key " + key + ", " + Dict[key].Count); } } }
public ClosestCityFinder( string citiesPath, string alternateNamesPath, string admin1Path, string admin2Path, string countriesPath, string clliPath, string unlocodePath) { var alternateNamesDict = GeonamesAlternateNamesParser.ParseToDict(alternateNamesPath); var admin1Dict = GeonamesAdminParser.ParseToDict(admin1Path); var admin2Dict = GeonamesAdminParser.ParseToDict(admin2Path); var countryEntities = GeonamesCountriesParser.ParseToList(countriesPath); var countryCodesDict = GeonamesCountriesParser.ListToISOCodeDict(countryEntities); var geonamesIdsToCLLICodes = CLLICodesParser.ParseToDict(clliPath); var geonamesIdsToUNLOCODECodes = UNLOCODECodesParser.ParseToDict(unlocodePath); this.GeohashesToCities = new Dictionary <string, List <GeonamesCityEntity> >(); foreach (var entity in GeonamesCitiesParser.Parse(citiesPath, alternateNamesDict, admin1Dict, admin2Dict, countryCodesDict, geonamesIdsToCLLICodes, geonamesIdsToUNLOCODECodes)) { var geohash = GeoHash.Encode(entity.Latitude, entity.Longitude, numberOfChars: 3); // 3 = ±78km List <GeonamesCityEntity> citiesInGeohash; if (!this.GeohashesToCities.TryGetValue(geohash, out citiesInGeohash)) { citiesInGeohash = new List <GeonamesCityEntity>(); this.GeohashesToCities[geohash] = citiesInGeohash; } citiesInGeohash.Add(entity); } }
public static TwoGeoHashBoundingBox WithBitPrecision(BoundingBox bbox, int numberOfBits) { GeoHash bottomLeft = GeoHash.WithBitPrecision(bbox.MinLat, bbox.MinLon, numberOfBits); GeoHash topRight = GeoHash.WithBitPrecision(bbox.MaxLat, bbox.MaxLon, numberOfBits); return(new TwoGeoHashBoundingBox(bottomLeft, topRight)); }
public List <GeohashRange> GetRanges(double latitude, double longitude, int rangeBitDepth = 16) // 156.5km { long geohash = GeoHash.EncodeInt(latitude, longitude, bitDepth: rangeBitDepth); long[] neighbours = GeoHash.NeighborsInt(geohash, bitDepth: rangeBitDepth); var ranges = new List <GeohashRange>(neighbours.Length); var rangeLength = geohash.ToString().Length; foreach (var neighbour in neighbours) { var latLong = GeoHash.DecodeInt(neighbour, bitDepth: rangeBitDepth); long geoHash = GeoHash.EncodeInt(latLong.Coordinates.Lat, latLong.Coordinates.Lon); var padAmount = geoHash.ToString().Length; // Now produce the min / max value of this based on the range length // So 21345 becomes 213450000000 to 21345999999 var leftPart = geoHash.ToString().Substring(0, rangeLength); var min = Convert.ToInt64(leftPart.PadRight(padAmount, '0')); var max = Convert.ToInt64(leftPart.PadRight(padAmount, '9')); ranges.Add(new GeohashRange { Min = min, Max = max }); } return(ranges); }
public LocationInfo(GeoPoint location, bool inGeoQuery, IDocumentSnapshot snapshot) { Location = location; InGeoQuery = inGeoQuery; GeoHash = new GeoHash(location); Snapshot = snapshot; }
public static HashSet <GeoObj> SearchGeoHashIndex(SessionBase session, double lat, double lon, double radius) { HashSet <GeoObj> resultSet = new HashSet <GeoObj>(); WGS84Point center = new WGS84Point(lat, lon); GeoHashCircleQuery query = new GeoHashCircleQuery(center, radius); // radius in meters BoundingBox bbox = query.BoundingBox; var btreeSet = session.AllObjects <BTreeSet <GeoObj> >().FirstOrDefault(); foreach (GeoHash hash in query.SearchHashes) { var itr = btreeSet.Iterator(); itr.GoTo(new GeoObj(hash.LongValue)); var current = itr.Current(); while (current != null) { GeoHash geoHash = GeoHash.FromLongValue(current.GeoHashAsLong); if ((geoHash.SignificantBits >= hash.SignificantBits && geoHash.Within(hash)) || (geoHash.SignificantBits < hash.SignificantBits && hash.Within(geoHash))) { if (!(current.Latitude < bbox.MinLat || current.Latitude > bbox.MaxLat || current.Longitude < bbox.MinLon || current.Longitude > bbox.MaxLon)) { resultSet.Add(current); } current = itr.Next(); } else { break; } } } return(resultSet); }
private static async Task <string> AddIntervention( InterventionDto intervention, CloudTable interventionsTable, Address convertedGeoAddress ) { int nextId = await InterventionCounter.GetNextId(interventionsTable); InterventionEntity interventionEntity = new InterventionEntity() { PartitionKey = GeoHash.Encode(convertedGeoAddress.Latitude, convertedGeoAddress.Lognitude, Config.GeoHashPrecision), RowKey = nextId.ToString(), Email = intervention.Email, City = intervention.City, Street = intervention.Street, StreetNumber = intervention.StreetNumber, CreationDate = DateTime.UtcNow, ModificationDate = DateTime.UtcNow, Description = intervention.Description, FullName = intervention.FullName, PhoneNumber = intervention.PhoneNumber, Status = (int)intervention.Status, GeoLat = convertedGeoAddress.Latitude, GeoLng = convertedGeoAddress.Lognitude, }; TableOperation insertNewIntervention = TableOperation.Insert(interventionEntity); await interventionsTable.ExecuteAsync(insertNewIntervention); return(interventionEntity.RowKey); }
internal void childRemoved(DataSnapshot dataSnapshot) { string key = dataSnapshot.Key; LocationInfo info = GeoUtils.getMapSafe(key, locationInfos); if (info != null) { ValueChangedListenerSetup vs = new ValueChangedListenerSetup(geoFire.getDatabaseRefForKey(key), true, (s) => { if (s.DatabaseError == null) { lock (Lock) { GeoLocation location = GeoFire.getLocationValue(dataSnapshot); GeoHash hash = (location != null) ? new GeoHash(location) : null; if (hash == null || !geoHashQueriesContainGeoHash(hash)) { LocationInfo _info = GeoUtils.getMapSafe(key, locationInfos); locationInfos.Remove(key); if (_info != null && _info.inGeoQuery) { foreach (GeoQueryEventListener listener in eventListeners) { geoFire.raiseEvent(() => { listener.onKeyExited(key); }); } } } } } }); } }
public JObject BpolygonSearchProcess(Coordinates select, Coordinates[] polygon, int level) { string hash = GeoHash.Encode(select.Lat, select.Lon, level); // get all other points(out of range) in box Coordinates[] allCoordinates = GetCoordinates(hash); List <Coordinates> coordinatesInRange = new List <Coordinates>(); List <Coordinates> coordinatesOutOfRange = new List <Coordinates>(); foreach (Coordinates c in allCoordinates) { if (PointInPolygon(c, polygon)) { coordinatesInRange.Add(c); } else { coordinatesOutOfRange.Add(c); } } JObject json = JObject.FromObject( new { Boxhash = hash, CoordinatesInRange = coordinatesInRange, CoordinatesOutOfRange = coordinatesOutOfRange } ); return(json); }
public Task <MessageHandlerResults> ProcessMessageAsync(Message msg, string pipelineName, int idx) { //TODO: Handle incorrect messages that doesn't have the required properties var lat = double.Parse(msg.Properties[InputLatProperty]); var lon = double.Parse(msg.Properties[InputLonProperty]); var precision = GeoHashPrecision; var geoHash = GeoHash.EncodeInt(lat, lon, precision); msg.Properties[GeoHashProperty] = geoHash.ToString(); msg.Properties[GeoHashProperty + "Precision"] = precision.ToString(); if (CalculateGeoHashCenterCoordinates) { var x = GeoHash.DecodeInt(geoHash, precision); msg.Properties[GeoHashCenterLatProperty] = x.Coordinates.Lat.ToString(); msg.Properties[GeoHashCenterLonProperty] = x.Coordinates.Lon.ToString(); var originCoordinates = new GeoCoordinate(lat, lon); var geoHashCenter = new GeoCoordinate(x.Coordinates.Lat, x.Coordinates.Lon); msg.Properties[GeoHashCenterDistProperty] = originCoordinates.GetDistanceTo(geoHashCenter).ToString("0"); } return(Task.FromResult(MessageHandlerResults.Success)); }
public JObject BoundingCircleSearchProcess(double selectLatitude, double selectLongitude, double searchLatitude, double searchLongitude, double radius, int level = 9) { string hash = GeoHash.Encode(selectLatitude, selectLongitude, level); // get all other points(out of range) in box Coordinates[] allCoordinates = GetCoordinates(hash); List <Coordinates> coordinatesInRange = new List <Coordinates>(); List <Coordinates> coordinatesOutOfRange = new List <Coordinates>(); foreach (Coordinates c in allCoordinates) { if (Measure(c.Lat, c.Lon, searchLatitude, searchLongitude) <= radius) { coordinatesInRange.Add(c); } else { coordinatesOutOfRange.Add(c); } } JObject json = JObject.FromObject( new { Boxhash = hash, CoordinatesInRange = coordinatesInRange, CoordinatesOutOfRange = coordinatesOutOfRange } ); return(json); }
public void DecodeInt_WhenHashStringIntHasDefaultBitDepth_ReturnsCoordinatesWithinStandardPrecision() { var geoHashDecodeResult = GeoHash.DecodeInt(HashStringInt); Assert.True(Math.Abs(Latitude - geoHashDecodeResult.Coordinates.Lat) < 0.0001, "(37.8324 - " + geoHashDecodeResult.Coordinates.Lat + " was >= 0.0001"); Assert.True(Math.Abs(Longitude - geoHashDecodeResult.Coordinates.Lon) < 0.0001, "(112.5584 - " + geoHashDecodeResult.Coordinates.Lon + " was >= 0.0001"); }
public void BridNestTest() { GeoHash hash = GeoHash.EncodeWithCharacterPrecision(116.402843, 39.999375, 8); string result = hash.ToBase32(); Assert.Equal("wx4g8c9v", result); }
// geohash.org public string GetPathAsGeoHash() { // var locations = locationService.Get(); //var path = locationService.Get().Select(l => GeoHash.Encode(l.Latitude, l.Longitude)); return string.Join(",", locationService.Get().Select(l => GeoHash.Encode(l.Latitude, l.Longitude))); }
public void NeighborsInt_ReturnsNeighborsInAllDirections() { var expectedNeighbors = new long[] { 1702789520, 1702789522, 1702789511, 1702789510, 1702789508, 1702789422, 1702789423, 1702789434 }; var neighbors = GeoHash.NeighborsInt(1702789509, 32); Assert.Equal(expectedNeighbors, neighbors); }
public void Neighbors_ReturnsNeighborsInAllDirections() { var expectedNeighbors = new[] { "dqcjw", "dqcjx", "dqcjr", "dqcjp", "dqcjn", "dqcjj", "dqcjm", "dqcjt" }; var neighbors = GeoHash.Neighbors("dqcjq"); Assert.Equal(expectedNeighbors, neighbors); }
public static string GetGeoHash(string latitude, string longitude) { var latitudeParsed = double.Parse(latitude, CultureInfo.InvariantCulture); var longitudeParsed = double.Parse(longitude, CultureInfo.InvariantCulture); var geoHash = GeoHash.Encode(latitudeParsed, longitudeParsed, Config.GeoHashPrecision); return(geoHash); }
public void DecodeFromCoords() { double lat_actual5 = 25.787, long_actual5 = -4.3291; var calculated8 = GeoHash.Decode("eusftqx9"); Assert.Equal(calculated8.Latitude.ToString().Substring(0, 6), lat_actual5.ToString()); Assert.Equal(calculated8.Longitude.ToString().Substring(0, 7), long_actual5.ToString()); }
public void TestGeoHash() { var ss = new GeoHash().Encode(170.7896, -78.11868, 11); var loc = new GeoHash().Decode(ss); var yy = new GeoHash().Top(ss); }
public void Encode_WhenTheNumberOfCharsIsProvided_ReturnsHashStringWithTheProvidedNumberOfChars() { const int hashStringNumberOfChars = 3; var actualHashString = GeoHash.Encode(32, 117, hashStringNumberOfChars); Assert.Equal(hashStringNumberOfChars, actualHashString.Length); Assert.Equal("wte", actualHashString); }
public TwoGeoHashBoundingBox(GeoHash bottomLeft, GeoHash topRight) { if (bottomLeft.SignificantBits != topRight.SignificantBits) { throw new System.ArgumentException("Does it make sense to iterate between hashes that have different precisions?"); } m_bottomLeft = GeoHash.FromLongValue(bottomLeft.LongValue, bottomLeft.SignificantBits); m_topRight = GeoHash.FromLongValue(topRight.LongValue, topRight.SignificantBits); m_boundingBox = m_bottomLeft.BoundingBox; m_boundingBox.ExpandToInclude(m_topRight.BoundingBox); }
public bool Contains(GeoHash hash) { foreach (GeoHash searchHash in m_searchHashes) { if (hash.Within(searchHash)) { return true; } } return false; }
private void AddSearchHash(GeoHash hash) { if (m_boundingBox == null) { m_boundingBox = new BoundingBox(hash.BoundingBox); } else { m_boundingBox.ExpandToInclude(hash.BoundingBox); } m_searchHashes.Add(hash); }
private void ExpandSearch(GeoHash centerHash, BoundingBox bbox) { AddSearchHash(centerHash); foreach (GeoHash adjacent in centerHash.Adjacent) { BoundingBox adjacentBox = adjacent.BoundingBox; if (adjacentBox.Intersects(bbox) && !m_searchHashes.Contains(adjacent)) { AddSearchHash(adjacent); } } }
public bool Contains(GeoHash hash) { return m_query.Contains(hash); }
private bool HashFits(GeoHash hash, BoundingBox bbox) { return hash.Contains(bbox.UpperLeft) && hash.Contains(bbox.LowerRight); }