Пример #1
0
        public async Task <IActionResult> Show(
            [FromRoute] string id
            )
        {
            var cta = await Mongo.GetCallToAction(id);

            if (cta == null)
            {
                Logger.LogInformation("Call to action {0} not found", id);
                return(NotFound());
            }

            var filter = (await Mongo.GetCallToActionFilters(id)).FirstOrDefault();

            if (filter == null)
            {
                Logger.LogError("Call to action {0} has no filter", filter);
                return(NotFound());
            }

            // HACK: shows huge Geohash
            var geohashBounds = Geohasher.GetBoundingBox(filter.CoveringGeohash[0].Substring(0, 1));

            return(View("Show", new CallToActionViewModel {
                Id = cta.Id.ToString(),
                From = filter.TimeBegin,
                To = filter.TimeEnd,
                Description = cta.Description,
                BoundingBox = geohashBounds,
                PolygonCoordinates = filter.Geometry.ToRingArray()
            }));
        }
Пример #2
0
        public void Should_Get_BoundingBox()
        {
            var hasher = new Geohasher();

            var envelope = hasher.GetBoundingBox("u");

            Assert.Equal(90, envelope.MaxX);
            Assert.Equal(45, envelope.MaxY);
            Assert.Equal(45, envelope.MinX);
            Assert.Equal(0, envelope.MinY);
        }
        public async Task FullDump()
        {
            var lastAccess = await Mongo.GetLastDailyStats();

            Response.Headers[HeaderNames.LastModified] = lastAccess.Date.ToUniversalTime().ToString("R");
            Response.Headers[HeaderNames.ContentType]  = "text/csv";
            Response.StatusCode = (int)HttpStatusCode.OK;

            await Response.WriteAsync("Date,TotalMinutesTracked,CentroidGeohash,CentroidLat,CentroidLong,GeohashBoxJSON,LocationCount,VehicleCount,EventCount,SampleCount,DiscardedSampleCount,BoundingBoxDiagonal,MinAtHome,MinAtWork,MinAtSchool,MinAtLocations,MinElsewhere" + Environment.NewLine);

            var cursor = await Mongo.FetchAllDailyStats();

            while (await cursor.MoveNextAsync())
            {
                foreach (var stat in cursor.Current)
                {
                    var centroid = stat.CentroidHash ?? Geohasher.Encode(stat.Centroid.Coordinates.Latitude, stat.Centroid.Coordinates.Longitude, 5);
                    var bbox     = Geohasher.GetBoundingBox(centroid);
                    var polygon  = new Polygon(new LineString[] {
                        new LineString(new IPosition[] {
                            new Position(bbox[0], bbox[2]),
                            new Position(bbox[0], bbox[3]),
                            new Position(bbox[1], bbox[3]),
                            new Position(bbox[1], bbox[2]),
                            new Position(bbox[0], bbox[2])
                        })
                    });

                    await Response.WriteAsync(string.Join(",",
                                                          stat.Date.ToString("yyyy-MM-dd"),
                                                          stat.TotalMinutesTracked,
                                                          centroid,
                                                          stat.Centroid.Coordinates.Latitude.ToString("F5"),
                                                          stat.Centroid.Coordinates.Longitude.ToString("F5"),
                                                          "\"" + JsonConvert.SerializeObject(polygon).Replace("\"", "\"\"") + "\"",
                                                          stat.LocationCount,
                                                          stat.VehicleCount,
                                                          stat.EventCount,
                                                          stat.SampleCount,
                                                          stat.DiscardedSampleCount,
                                                          stat.BoundingBoxDiagonal.ToString("F2"),
                                                          stat.LocationTracking.MinutesAtHome,
                                                          stat.LocationTracking.MinutesAtWork,
                                                          stat.LocationTracking.MinutesAtSchool,
                                                          stat.LocationTracking.MinutesAtOtherKnownLocations,
                                                          stat.LocationTracking.MinutesElsewhere
                                                          ) + Environment.NewLine);
                }
            }
        }
Пример #4
0
        public Polygon BoundingBox(string geohash)
        {
            var bb = hasher.GetBoundingBox(geohash);

            var coordinates = new List <Coordinate>();

            coordinates.Add(new Coordinate(bb[3], bb[0]));
            coordinates.Add(new Coordinate(bb[3], bb[1]));
            coordinates.Add(new Coordinate(bb[2], bb[1]));
            coordinates.Add(new Coordinate(bb[2], bb[0]));
            coordinates.Add(new Coordinate(bb[3], bb[0]));

            var linearRing = new LinearRing(coordinates.ToArray());
            var polygon    = new Polygon(linearRing);

            return(polygon);
        }