コード例 #1
0
        private S2Loop makeCellLoop(S2CellId begin, S2CellId end)
        {
            // Construct a CCW polygon whose boundary is the union of the cell ids
            // in the range [begin, end). We Add the edges one by one, removing
            // any edges that are already present in the opposite direction.

            IDictionary <S2Point, ISet <S2Point> > edges = new Dictionary <S2Point, ISet <S2Point> >();

            for (var id = begin; !id.Equals(end); id = id.Next)
            {
                var cell = new S2Cell(id);
                for (var k = 0; k < 4; ++k)
                {
                    var a = cell.GetVertex(k);
                    var b = cell.GetVertex((k + 1) & 3);
                    if (!edges.ContainsKey(b))
                    {
                        edges.Add(b, new HashSet <S2Point>());
                    }
                    // if a is in b's set, remove it and remove b's set if it's empty
                    // otherwise, Add b to a's set
                    if (!edges[b].Remove(a))
                    {
                        if (!edges.ContainsKey(a))
                        {
                            edges.Add(a, new HashSet <S2Point>());
                        }
                        edges[a].Add(b);
                    }
                    else if (edges[b].Count == 0)
                    {
                        edges.Remove(b);
                    }
                }
            }

            // The remaining edges form a single loop. We simply follow it starting
            // at an arbitrary vertex and build up a list of vertices.

            var vertices = new List <S2Point>();
            //S2Point p = edges.keySet().iterator().next();
            var p = edges.Keys.First();

            while (edges.Any())
            {
                assertEquals(1, edges[p].Count);
                var next = edges[p].First();
                //S2Point next = edges[p].iterator().next();
                vertices.Add(p);
                edges.Remove(p);
                p = next;
            }

            return(new S2Loop(vertices));
        }
コード例 #2
0
        public void testContains()
        {
            assertTrue(candyCane.Contains(S2LatLng.FromDegrees(5, 71).ToPoint()));
            for (var i = 0; i < 4; ++i)
            {
                assertTrue(northHemi.Contains(new S2Point(0, 0, 1)));
                assertTrue(!northHemi.Contains(new S2Point(0, 0, -1)));
                assertTrue(!southHemi.Contains(new S2Point(0, 0, 1)));
                assertTrue(southHemi.Contains(new S2Point(0, 0, -1)));
                assertTrue(!westHemi.Contains(new S2Point(0, 1, 0)));
                assertTrue(westHemi.Contains(new S2Point(0, -1, 0)));
                assertTrue(eastHemi.Contains(new S2Point(0, 1, 0)));
                assertTrue(!eastHemi.Contains(new S2Point(0, -1, 0)));
                northHemi = rotate(northHemi);
                southHemi = rotate(southHemi);
                eastHemi  = rotate(eastHemi);
                westHemi  = rotate(westHemi);
            }

            // This code checks each cell vertex is contained by exactly one of
            // the adjacent cells.
            for (var level = 0; level < 3; ++level)
            {
                var            loops        = new List <S2Loop>();
                var            loopVertices = new List <S2Point>();
                ISet <S2Point> points       = new HashSet <S2Point>();
                for (var id = S2CellId.Begin(level); !id.Equals(S2CellId.End(level)); id = id.Next)
                {
                    var cell = new S2Cell(id);
                    points.Add(cell.Center);
                    for (var k = 0; k < 4; ++k)
                    {
                        loopVertices.Add(cell.GetVertex(k));
                        points.Add(cell.GetVertex(k));
                    }
                    loops.Add(new S2Loop(loopVertices));
                    loopVertices.Clear();
                }
                foreach (var point in points)
                {
                    var count = 0;
                    for (var j = 0; j < loops.Count; ++j)
                    {
                        if (loops[j].Contains(point))
                        {
                            ++count;
                        }
                    }
                    assertEquals(count, 1);
                }
            }
        }
コード例 #3
0
        public List <S2CellId> GetS2CellIds(ushort level, int maxCells)
        {
            //var geofence = Geofence.FromMultiPolygon(this);
            var bbox          = GetBoundingBox();
            var regionCoverer = new S2RegionCoverer
            {
                MinLevel = level,
                MaxLevel = level,
                MaxCells = maxCells,
            };
            var region = new S2LatLngRect(
                S2LatLng.FromDegrees(bbox.MinimumLatitude, bbox.MinimumLongitude),
                S2LatLng.FromDegrees(bbox.MaximumLatitude, bbox.MaximumLongitude)
                );
            var coverage = new List <S2CellId>();

            regionCoverer.GetCovering(region, coverage);
            var result = new List <S2CellId>();

            foreach (var cellId in coverage)
            {
                var cell = new S2Cell(cellId);
                for (var i = 0; i <= 3; i++)
                {
                    var vertex = cell.GetVertex(i);
                    var coord  = new S2LatLng(new S2Point(vertex.X, vertex.Y, vertex.Z));
                    //if (geofence.Intersects(coord.LatDegrees, coord.LngDegrees))
                    if (GeofenceService.InPolygon(this, coord.LatDegrees, coord.LngDegrees))
                    {
                        result.Add(cellId);
                    }
                }
            }
            return(result);
        }
コード例 #4
0
ファイル: S2GMapDrawer.cs プロジェクト: gandoulf0/RocketBot
        public static void DrawS2Cells(List <ulong> cellsIds, GMapOverlay mapLayer)
        {
            for (var i = 0; i < cellsIds.Count; i++)
            {
                var cellId = new S2CellId((ulong)i);
                var cell   = new S2Cell(cellId);

                var points = new List <PointLatLng>();
                for (var j = 0; j < 4; j++)
                {
                    var point = new S2LatLng(cell.GetVertex(j));
                    points.Add(new PointLatLng(point.LatDegrees, point.LngDegrees));
                }
                var polygon = new GMapPolygon(points, "mypolygon");
                polygon.Fill   = new SolidBrush(Color.FromArgb(50, Color.Red));
                polygon.Stroke = new Pen(Color.Red, 1);
                mapLayer.Polygons.Add(polygon);
            }
        }
コード例 #5
0
        public static void DrawS2Cells(List<ulong> cellsIds, GMapOverlay mapLayer)
        {
            for (int i=0; i<cellsIds.Count; i++)
            {
                S2CellId cellId = new S2CellId(cellsIds[i]);
                S2Cell cell = new S2Cell(cellId);

                List<PointLatLng> points = new List<PointLatLng>();
                for (int j=0; j<4; j++)
                {
                    S2LatLng point = new S2LatLng(cell.GetVertex(j));
                    points.Add(new PointLatLng(point.LatDegrees, point.LngDegrees));
                }
                GMapPolygon polygon = new GMapPolygon(points, "mypolygon");
                polygon.Fill = new SolidBrush(Color.FromArgb(50, Color.Red));
                polygon.Stroke = new Pen(Color.Red, 1);
                mapLayer.Polygons.Add(polygon);
            }
        }
コード例 #6
0
        public dynamic GetWebhookValues(string type)
        {
            var s2cell  = new S2Cell(new S2CellId((ulong)Id));
            var polygon = new List <List <double> >();

            for (var i = 0; i <= 3; i++)
            {
                var vertex = s2cell.GetVertex(i);
                var coord  = new S2LatLng(vertex);
                polygon.Add(new List <double> {
                    coord.LatDegrees,
                    coord.LngDegrees
                });
            }
            return(new
            {
                type = "weather",
                message = new
                {
                    s2_cell_id = Id,
                    latitude = Latitude,
                    longitude = Longitude,
                    polygon = polygon,
                    gameplay_condition = (ushort)GameplayCondition,
                    wind_direction = WindDirection,
                    cloud_level = CloudLevel,
                    rain_level = RainLevel,
                    wind_level = WindLevel,
                    snow_level = SnowLevel,
                    fog_level = FogLevel,
                    special_effect_level = SpecialEffectLevel,
                    severity = Severity,
                    warn_weather = WarnWeather,
                    updated = Updated,
                },
            });
        }
コード例 #7
0
        private S2Loop makeCellLoop(S2CellId begin, S2CellId end)
        {
            // Construct a CCW polygon whose boundary is the union of the cell ids
            // in the range [begin, end). We Add the edges one by one, removing
            // any edges that are already present in the opposite direction.

            IDictionary<S2Point, ISet<S2Point>> edges = new Dictionary<S2Point, ISet<S2Point>>();
            for (var id = begin; !id.Equals(end); id = id.Next)
            {
                var cell = new S2Cell(id);
                for (var k = 0; k < 4; ++k)
                {
                    var a = cell.GetVertex(k);
                    var b = cell.GetVertex((k + 1) & 3);
                    if (!edges.ContainsKey(b))
                    {
                        edges.Add(b, new HashSet<S2Point>());
                    }
                    // if a is in b's set, remove it and remove b's set if it's empty
                    // otherwise, Add b to a's set
                    if (!edges[b].Remove(a))
                    {
                        if (!edges.ContainsKey(a))
                        {
                            edges.Add(a, new HashSet<S2Point>());
                        }
                        edges[a].Add(b);
                    }
                    else if (edges[b].Count == 0)
                    {
                        edges.Remove(b);
                    }
                }
            }

            // The remaining edges form a single loop. We simply follow it starting
            // at an arbitrary vertex and build up a list of vertices.

            var vertices = new List<S2Point>();
            //S2Point p = edges.keySet().iterator().next();
            var p = edges.Keys.First();
            while (edges.Any())
            {
                assertEquals(1, edges[p].Count);
                var next = edges[p].First();
                //S2Point next = edges[p].iterator().next();
                vertices.Add(p);
                edges.Remove(p);
                p = next;
            }

            return new S2Loop(vertices);
        }
コード例 #8
0
        public void testContains()
        {
            assertTrue(candyCane.Contains(S2LatLng.FromDegrees(5, 71).ToPoint()));
            for (var i = 0; i < 4; ++i)
            {
                assertTrue(northHemi.Contains(new S2Point(0, 0, 1)));
                assertTrue(!northHemi.Contains(new S2Point(0, 0, -1)));
                assertTrue(!southHemi.Contains(new S2Point(0, 0, 1)));
                assertTrue(southHemi.Contains(new S2Point(0, 0, -1)));
                assertTrue(!westHemi.Contains(new S2Point(0, 1, 0)));
                assertTrue(westHemi.Contains(new S2Point(0, -1, 0)));
                assertTrue(eastHemi.Contains(new S2Point(0, 1, 0)));
                assertTrue(!eastHemi.Contains(new S2Point(0, -1, 0)));
                northHemi = rotate(northHemi);
                southHemi = rotate(southHemi);
                eastHemi = rotate(eastHemi);
                westHemi = rotate(westHemi);
            }

            // This code checks each cell vertex is contained by exactly one of
            // the adjacent cells.
            for (var level = 0; level < 3; ++level)
            {
                var loops = new List<S2Loop>();
                var loopVertices = new List<S2Point>();
                ISet<S2Point> points = new HashSet<S2Point>();
                for (var id = S2CellId.Begin(level); !id.Equals(S2CellId.End(level)); id = id.Next)
                {
                    var cell = new S2Cell(id);
                    points.Add(cell.Center);
                    for (var k = 0; k < 4; ++k)
                    {
                        loopVertices.Add(cell.GetVertex(k));
                        points.Add(cell.GetVertex(k));
                    }
                    loops.Add(new S2Loop(loopVertices));
                    loopVertices.Clear();
                }
                foreach (var point in points)
                {
                    var count = 0;
                    for (var j = 0; j < loops.Count; ++j)
                    {
                        if (loops[j].Contains(point))
                        {
                            ++count;
                        }
                    }
                    assertEquals(count, 1);
                }
            }
        }
コード例 #9
0
        async void Load_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".geojson");
            picker.FileTypeFilter.Add(".geoJSON");
            picker.FileTypeFilter.Add(".csv");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    using (StreamReader sr = new StreamReader(file.Path))
                    {
                        string content = sr.ReadToEnd();
                        if (file.FileType == ".csv")
                        {
                            string[] lines = content.Split('\n');
                            for (int i = 0; i < lines.Length; i++)
                            {
                                var item = lines[i];

                                if (String.IsNullOrWhiteSpace(item))
                                {
                                    continue;
                                }

                                string[] info = item.Split(',');
                                double   lat  = 0;
                                double   lon  = 0;

                                if (!Double.TryParse(info[info.Length - 2], out lon) || !Double.TryParse(info[info.Length - 3], out lat))
                                {
                                    if (i == 0)
                                    {
                                        continue;
                                    }
                                    var messageDialog = new MessageDialog("Zeile " + i + " (" + item + ") hat nicht das richtige Format!");
                                    messageDialog.Commands.Add(new UICommand("OK", new UICommandInvokedHandler(this.CommandInvokedHandler)));
                                    messageDialog.DefaultCommandIndex = 0;
                                    messageDialog.Title = "Fehlerhafte Datei";
                                    await messageDialog.ShowAsync();

                                    return;
                                }

                                StringBuilder sb = new StringBuilder("");

                                for (int j = 0; j < info.Length - 3; j++)
                                {
                                    sb.Append(info[j]);
                                }

                                PointOfInterest poi = new PointOfInterest()
                                {
                                    Location = new Geopoint(new BasicGeoposition()
                                    {
                                        Latitude = lat, Longitude = lon
                                    }),
                                    DisplayName           = sb.ToString(),
                                    NormalizedAnchorPoint = AnchorPoints[2],
                                    Flag = PointOfInterest.PORTAL,
                                    Leaf = FindExactCell(new BasicGeoposition()
                                    {
                                        Latitude = lat, Longitude = lon
                                    }, 30).Id.Id
                                };

                                portals.Add(poi);
                                //DataAccess.AddData(poi);
                            }
                        }
                        else
                        {
                            var features = JsonConvert.DeserializeObject <FeatureCollection>(content).Features;

                            foreach (var p in features)
                            {
                                double lon  = ((Point)p.Geometry).Coordinates.Longitude;
                                double lat  = ((Point)p.Geometry).Coordinates.Latitude;
                                int    flag = PointOfInterest.PORTAL;
                                if (p.Properties.ContainsKey("Flag"))
                                {
                                    flag = (int)p.Properties["Flag"];
                                }

                                PointOfInterest poi = new PointOfInterest()
                                {
                                    Location = new Geopoint(new BasicGeoposition()
                                    {
                                        Latitude = lat, Longitude = lon
                                    }),
                                    DisplayName           = (string)p.Properties["name"],
                                    NormalizedAnchorPoint = AnchorPoints[flag],
                                    Flag = flag,
                                    Leaf = FindExactCell(new BasicGeoposition()
                                    {
                                        Latitude = lat, Longitude = lon
                                    }, 30).Id.Id
                                };

                                portals.Add(poi);
                                //DataAccess.AddData(poi);
                            }
                        }
                        AddLayers();
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    Windows.Storage.StorageFolder installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
                    var messageDialog = new MessageDialog("Zugriff auf den Pfad " + file.Path +
                                                          " wurde verweigert.\nBitte gewähren Sie Zugriff unter \n\nEinstellungen -> Privatsphäre -> Dateisystem\n\noder bewegen Sie die Datei an diesen Ort:\n"
                                                          + installedLocation.Path);
                    messageDialog.Commands.Add(new UICommand("OK", new UICommandInvokedHandler(this.CommandInvokedHandler)));
                    messageDialog.DefaultCommandIndex = 0;
                    messageDialog.Title = "Keine Zugriffsrechte";
                    await messageDialog.ShowAsync();

                    return;
                }

                // outermost bounds
                double maxLat = -360;
                double maxLon = -360;
                double minLat = 360;
                double minLon = 360;

                // Find out all Lvl17 cells
                foreach (var p in portals)
                {
                    double lat = p.Location.Position.Latitude;
                    double lon = p.Location.Position.Longitude;

                    if (lon < minLon)
                    {
                        minLon = lon;
                    }
                    if (lon > maxLon)
                    {
                        maxLon = lon;
                    }
                    if (lat < minLat)
                    {
                        minLat = lat;
                    }
                    if (lat > maxLat)
                    {
                        maxLat = lat;
                    }

                    var cell = FindExactCell(p.Location.Position, 17);

                    MapPolygon polygon = new MapPolygon
                    {
                        Path = new Geopath(new List <BasicGeoposition>()
                        {
                            FromS2Point(cell.GetVertex(0)),
                            FromS2Point(cell.GetVertex(1)),
                            FromS2Point(cell.GetVertex(2)),
                            FromS2Point(cell.GetVertex(3))
                        }),

                        ZIndex          = 1,
                        FillColor       = Color.FromArgb(50, 50, 50, 50),
                        StrokeColor     = Colors.Black,
                        StrokeThickness = 2,
                        StrokeDashed    = false
                    };
                    lvl17Cells.Add(polygon);
                    AddCell(polygon);
                }

                // Find out Lvl14 cells
                var area = S2LatLngRect.FromPointPair(
                    S2LatLng.FromDegrees(minLat, minLon),
                    S2LatLng.FromDegrees(maxLat, maxLon)
                    );

                var cells14 = new List <S2CellId>();
                lvl14Coverer.GetCovering(area, cells14);

                for (int i = 0; i < cells14.Count; i++)
                {
                    S2Cell cell = new S2Cell(cells14[i]);

                    MapPolygon polygon = new MapPolygon
                    {
                        Path = new Geopath(new List <BasicGeoposition>()
                        {
                            FromS2Point(cell.GetVertex(0)),
                            FromS2Point(cell.GetVertex(1)),
                            FromS2Point(cell.GetVertex(2)),
                            FromS2Point(cell.GetVertex(3))
                        }),

                        ZIndex          = 1,
                        FillColor       = Color.FromArgb(50, 0, 0, 50),
                        StrokeColor     = Colors.Blue,
                        StrokeThickness = 2,
                        StrokeDashed    = false
                    };
                    lvl14Cells.Add(polygon);
                    AddCell(polygon);
                }

                BasicGeoposition newCenter = new BasicGeoposition();
                newCenter.Latitude  = (minLat + maxLat) / 2;
                newCenter.Longitude = (minLon + maxLon) / 2;
                PokeMap.Center      = new Geopoint(newCenter);
            }
        }