public List <Location> findReindeers() { using (var documentClient = new DocumentClient(API_URI, reindeers.token)) return(reindeers.zones.Select(zone => { var feedOptions = new FeedOptions() { PartitionKey = new PartitionKey(zone.countryCode), MaxItemCount = 1 }; var distance = PositionUtil.DistanceInMeters(zone.radius.unit, zone.radius.value); var from = new Point(zone.center.lon, zone.center.lat); // var sql = "SELECT * FROM root r WHERE root.name = '" + zone.reindeer // + "' AND ST_DISTANCE(root.location, {'type': 'Point', 'coordinates':[" // + zone.center.lat + ", " + zone.center.lon + "]}) < " + distance; // System.Console.WriteLine(sql); ReindeerLocation reindeerLocation = documentClient.CreateDocumentQuery <ReindeerLocation>( UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId), feedOptions ).Where(a => a.name == zone.reindeer && a.location.Distance(from) <= distance) .AsEnumerable() .FirstOrDefault(); return new Location() { name = reindeerLocation.name, position = new Center() { lat = reindeerLocation.location.Position.Latitude, lon = reindeerLocation.location.Position.Longitude } }; }).ToList()); }
private double CalculateMovementInMeters(SantaMovement santaMovement) { return(PositionUtil.DistanceInMeters(santaMovement.unit, santaMovement.value)); }