コード例 #1
0
        // test for issue 3 https://github.com/bertt/mapbox-vector-tile-cs/issues/3
        // tile: https://b.tiles.mapbox.com/v4/mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7/13/4260/2911.vector.pbf
        public void TestIssue3MapBoxVectorTile()
        {
            // arrange
            const string mapboxissue3File = "mapbox.vector.tile.tests.testdata.issue3_2911.vector.pbf";

            // act
            var pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(mapboxissue3File);
            var layerInfos = VectorTileParser.Parse(pbfStream);

            // asserts
            Assert.IsTrue(layerInfos[7].VectorTileFeatures.Count == 225);
            Assert.IsTrue(layerInfos[0].Version == 2);
            Assert.IsTrue(layerInfos[7].Name == "road");
            Assert.IsTrue(layerInfos[7].Extent == 4096);
            var firstroad = layerInfos[7].VectorTileFeatures[0];

            Assert.IsTrue(firstroad.Geometry.Count == 5);
            Assert.IsTrue(firstroad.Geometry[0].Count == 1);
            Assert.IsTrue(firstroad.Geometry[0][0].X == 816);
            Assert.IsTrue(firstroad.Geometry[0][0].Y == 3446);

            var secondroad = layerInfos[7].VectorTileFeatures[1];

            Assert.IsTrue(secondroad.Geometry.Count == 2);
            Assert.IsTrue(secondroad.Geometry[0].Count == 9);
            Assert.IsTrue(secondroad.Geometry[0][0].X == 3281);
            Assert.IsTrue(secondroad.Geometry[0][0].Y == 424);
        }
コード例 #2
0
        public SecondBenchmark()
        {
            const string mapboxissue3File = @"./testdata/14-8801-5371.vector.pbf";
            var          input            = File.OpenRead(mapboxissue3File);

            layers = VectorTileParser.Parse(input);
        }
コード例 #3
0
        async private Task Download(int level, int col, int row, string tileUrl)
        {
            try
            {
                var bytes = await DownloadTile(level, col, row, tileUrl);

                var layerInfos = VectorTileParser.Parse(new MemoryStream(bytes));

                foreach (var layerInfo in layerInfos)
                {
                    var fc = layerInfo.ToGeoJSON(col, row, level);
                    if (fc.Features != null &&
                        fc.Features.Count > 0 &&
                        _features.ContainsKey(layerInfo.Name))
                    {
                        foreach (var feature in fc.Features)
                        {
                            _features[layerInfo.Name].Add(feature);
                        }
                    }
                }

                StoreToLocalcache(level, col, row, bytes);
            }
            catch (Exception ex)
            {
                _dataset.LastErrorMessage = $"{ ex.Message } at \n{ ex.StackTrace }";
            }
        }
コード例 #4
0
        public override byte[] GetTile(TileInfo tileInfo)
        {
            var bytes      = base.GetTile(tileInfo);
            var index      = tileInfo.Index;
            var layerInfos = VectorTileParser.Parse(new MemoryStream(bytes), index.Col, index.Row, Int32.Parse(index.Level));

            return(VectorTileConverter.ToBitmap(layerInfos, tileInfo));
        }
コード例 #5
0
        public static Feature GeoJSONFromFixture(string name)
        {
            var pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
            var layerInfos = VectorTileParser.Parse(pbfStream);
            var test       = layerInfos[0].VectorTileFeatures[0].ToGeoJSON(0, 0, 0);

            return(test);
        }
コード例 #6
0
        public List <VectorTileLayer> DoParse()
        {
            // arrange
            const string mapboxissue3File = "mapbox.vector.tile.benchmark.testdata.mapbox_tile.vector.pbf";

            // act
            var pbfStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(mapboxissue3File);

            return(VectorTileParser.Parse(pbfStream));
        }
コード例 #7
0
        public override byte[] GetTile(TileInfo tileInfo)
        {
            var bytes           = base.GetTile(tileInfo);
            var index           = tileInfo.Index;
            var layerInfos      = VectorTileParser.Parse(new MemoryStream(bytes), index.Col, index.Row, Int32.Parse(index.Level));
            var tileWidth       = Schema.GetTileWidth(tileInfo.Index.Level);
            var tileHeight      = Schema.GetTileHeight(tileInfo.Index.Level);
            var geoJSONRenderer = new GeoJSONToOpenTKRenderer(tileWidth, tileHeight, ToGeoJSONArray(tileInfo.Extent));

            return(geoJSONRenderer.Render(layerInfos.Select(i => i.FeatureCollection)));
        }
コード例 #8
0
 public void ParseTile()
 {
     try
     {
         var l = VectorTileParser.Parse(_vectorTileStream);
     }
     catch (Exception ex)
     {
         var explanation = ex.ToString();
     }
 }
コード例 #9
0
        public override byte[] GetTile(TileInfo tileInfo)
        {
            var bytes           = base.GetTile(tileInfo);
            var index           = tileInfo.Index;
            var layerInfos      = VectorTileParser.Parse(new MemoryStream(bytes), index.Col, index.Row, int.Parse(index.Level));
            var tileWidth       = Schema.GetTileWidth(tileInfo.Index.Level);
            var tileHeight      = Schema.GetTileHeight(tileInfo.Index.Level);
            var geoJSONRenderer = GetGeoJsonRenderer(tileInfo, tileWidth, tileHeight);

            return(geoJSONRenderer.Render(layerInfos.Select(i => i.FeatureCollection)));
        }
コード例 #10
0
        public void TestMapzenTile()
        {
            // arrange
            const string mapzenfile = "mapbox.vector.tile.tests.testdata.mapzen000.mvt";

            // act
            var pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(mapzenfile);
            var layerInfos = VectorTileParser.Parse(pbfStream);

            // assert
            Assert.IsTrue(layerInfos.Count == 10);
        }
コード例 #11
0
        public void TestLotsOfTags()
        {
            // arrange
            const string mapboxfile = "mapbox.vector.tile.tests.testdata.lots-of-tags.vector.pbf";
            var          pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(mapboxfile);

            // act
            var layerInfos = VectorTileParser.Parse(pbfStream);

            // assert
            Assert.IsTrue(layerInfos[0] != null);
        }
コード例 #12
0
        public void TestBagVectorTile()
        {
            // arrange
            const string bagfile = "mapbox.vector.tile.tests.testdata.bag-17-67317-43082.pbf";

            // act
            var pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(bagfile);
            var layerInfos = VectorTileParser.Parse(pbfStream);

            // assert
            Assert.IsTrue(layerInfos.Count == 1);
            Assert.IsTrue(layerInfos[0].VectorTileFeatures.Count == 83);
            Assert.IsTrue(layerInfos[0].VectorTileFeatures[0].GeometryType == GeomType.Polygon);
        }
コード例 #13
0
        /// <summary>
        /// A Mapbox stream consists only of one tile, so the
        /// </summary>
        /// <param name="tile"></param>
        /// <returns></returns>
        public IEnumerable <VectorTileLayer> GetTile(TileInfo tileInfo)
        {
            System.Diagnostics.Debug.WriteLine($"Tile Row={tileInfo.Index.Row} Col={tileInfo.Index.Col} Zoom={tileInfo.Index.Level}");

            var imageData = connection.Query <images>("SELECT images.tile_id,images.tile_data FROM map,images WHERE map.tile_id=images.tile_id AND map.zoom_level=? AND map.tile_row=? AND map.tile_column=?", new object[] { tileInfo.Index.Level, tileInfo.Index.Row, tileInfo.Index.Col });

            if (imageData == null || imageData.Count == 0)
            {
                return(new List <VectorTileLayer>());
            }

            // TODO: This is the only line we need, if BruTile handles vector tiles correct
            return(VectorTileParser.Parse(tileInfo, new GZipStream(new MemoryStream(imageData.First().tile_data), CompressionMode.Decompress)));
        }
コード例 #14
0
        // test for issue 10 https://github.com/bertt/mapbox-vector-tile-cs/issues/10
        // Attributes tests for short Int values
        public void TestIssue10MapBoxVectorTile()
        {
            // arrange
            const string mapboxissue10File = "mapbox.vector.tile.tests.testdata.cadastral.pbf";

            // act
            var pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(mapboxissue10File);
            var layerInfos = VectorTileParser.Parse(pbfStream);

            // asserts
            var firstattribute = layerInfos[0].VectorTileFeatures[0].Attributes[0];
            var val            = firstattribute.Value;

            Assert.IsTrue((long)val == 867160);
        }
コード例 #15
0
        // test for issue 10 https://github.com/bertt/mapbox-vector-tile-cs/issues/10
        // Attributes tests for short Int values
        public void TestIssue10MapBoxVectorTile()
        {
            // arrange
            const string mapboxissue10File = "Mapsui.VectorTiles.Mapbox.Tests.Resources.cadastral.pbf";

            // act
            var pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(mapboxissue10File);
            var layerInfos = VectorTileParser.Parse(pbfStream);

            // asserts
            var firstattribute = layerInfos[0].VectorTileFeatures[0].Tags.FirstOrDefault <Tag>();
            var val            = firstattribute.Value;

            Assert.IsTrue((int)val.Value == 867160);
        }
コード例 #16
0
ファイル: MvtSubLayer.cs プロジェクト: zchunwu/ArcBruTile
        private static void DownloadTile(object tile)
        {
            var parameters = (object[])tile;
            var tileInfo   = (TileInfo)parameters[0];
            var doneEvent  = (MultipleThreadResetEvent)parameters[1];
            var url        = ((WebTileProvider)_tileSource.Provider).Request.GetUri(tileInfo);
            var request    = new GZipWebClient();
            var bytes      = request.DownloadData(url);

            if (bytes != null)
            {
                var stream = new MemoryStream(bytes);
                Logger.Debug("Start parsing vector tile...");
                var layerInfos = VectorTileParser.Parse(stream);
                tiles[tileInfo] = layerInfos;
            }
            doneEvent.SetOne();
        }
コード例 #17
0
        public void TestVectorTileToGeoJson()
        {
            // arrange
            const string name       = "Mapsui.VectorTiles.Mapbox.Tests.Resources.multi-point.pbf";
            var          pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
            var          layerInfos = VectorTileParser.Parse(pbfStream);
            var          geojson    = layerInfos[0].ToGeoJSON(0, 0, 0);

            // act
            var json = JsonConvert.SerializeObject(geojson);

            // act
            var actualResult   = JObject.Parse(json);
            var expectedResult = JObject.Parse(@"
                {
                  'features': [
                    {
                      'geometry': {
                        'coordinates': [
                          [
                            0.966796875,
                            2.0210651187669839
                          ],
                          [
                            2.98828125,
                            4.0396178267684348
                          ]
                        ],
                        'type': 'MultiPoint'
                      },
                      'id': '1',
                      'properties': {},
                      'type': 'Feature'
                    }
                  ],
                  'type': 'FeatureCollection'
                }            
            ");

            // assert
            Assert.IsTrue(JToken.DeepEquals(actualResult, expectedResult));
        }
コード例 #18
0
        /// <summary>
        /// Gets the image URI.
        /// </summary>
        /// <param name="tileLevel">Tile level.</param>
        /// <param name="tilePositionX">Tile X.</param>
        /// <param name="tilePositionY">Tile Y.</param>
        /// <returns>URI of image.</returns>
        protected override Uri GetTile(int tileLevel, int tilePositionX, int tilePositionY)
        {
            int          zoomLevel  = this.ConvertTileToZoomLevel(tileLevel);
            const string mapboxfile = @"D:\utah.mbtiles";

            // act
            var pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(mapboxfile);
            var layerInfos = VectorTileParser.Parse(pbfStream, tilePositionX, tilePositionY, zoomLevel, false);


            string url    = TileMapnikUrlFormat;
            string prefix = this.GetTilePrefix(tilePositionX, tilePositionY);

            url = ProtocolHelper.SetScheme(url);
            url = url.Replace("{prefix}", prefix);
            url = url.Replace("{zoom}", zoomLevel.ToString(CultureInfo.InvariantCulture));
            url = url.Replace("{x}", tilePositionX.ToString(CultureInfo.InvariantCulture));
            url = url.Replace("{y}", tilePositionY.ToString(CultureInfo.InvariantCulture));

            return(new Uri(url));
        }
コード例 #19
0
        public void TestMapzenTileFromUrl()
        {
            // arrange
            var url = "https://tile.nextzen.org/tilezen/vector/v1/512/all/0/0/0.mvt?api_key=ZVKjQi5pS1-afO-ziytQ8g";

            // Note: Use HttpClient with automatic decompression
            // instead of regular HttpClient otherwise we get exception
            // 'ProtoBuf.ProtoException: Invalid wire-type; this usually means you have over-written a file without truncating or setting the length'
            var gzipWebClient = new HttpClient(new HttpClientHandler()
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            });
            var bytes = gzipWebClient.GetByteArrayAsync(url).Result;

            var stream = new MemoryStream(bytes);

            // act
            var layerInfos = VectorTileParser.Parse(stream);

            // assert
            Assert.IsTrue(layerInfos.Count > 0);
        }
コード例 #20
0
        public void TestPdokTileFromUrl()
        {
            // arrange
            var url = "https://geodata.nationaalgeoregister.nl/beta/topotiles/9/262/169.pbf";

            // Note: Use HttpClient with automatic decompression
            // instead of regular HttpClient otherwise we get exception
            // 'ProtoBuf.ProtoException: Invalid wire-type; this usually means you have over-written a file without truncating or setting the length'
            var gzipWebClient = new HttpClient(new HttpClientHandler()
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            });
            var bytes = gzipWebClient.GetByteArrayAsync(url).Result;

            var stream = new MemoryStream(bytes);

            // act
            var layerInfos = VectorTileParser.Parse(stream);

            // assert
            Assert.IsTrue(layerInfos.Count > 0);
        }
コード例 #21
0
        public void TestBagTileFromUrl()
        {
            // arrange
            var url = "http://research.geodan.nl/service/geoserver/gwc/service/tms/1.0.0/research%3Apand@World_3857@pbf/14/8425/10978.pbf";

            // Note: Use HttpClient with automatic decompression
            // instead of regular HttpClient otherwise we get exception
            // 'ProtoBuf.ProtoException: Invalid wire-type; this usually means you have over-written a file without truncating or setting the length'
            var gzipWebClient = new HttpClient(new HttpClientHandler()
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            });
            var bytes = gzipWebClient.GetByteArrayAsync(url).Result;

            var stream = new MemoryStream(bytes);

            // act
            var layerInfos = VectorTileParser.Parse(stream);

            // assert
            Assert.IsTrue(layerInfos.Count > 0);
        }
コード例 #22
0
        private static void DownloadTile(object tile)
        {
            var parameters = (object[])tile;
            var tileInfo   = (TileInfo)parameters[0];
            var doneEvent  = (MultipleThreadResetEvent)parameters[1];
            var url        = ((WebTileProvider)_tileSource.Provider).Request.GetUri(tileInfo);
            // todo:
            var handler = new HttpClientHandler()
            {
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            };

            var httpClient = new HttpClient(handler);
            var bytes      = httpClient.GetAsync(url).Result.Content.ReadAsByteArrayAsync().Result;

            if (bytes != null)
            {
                var stream = new MemoryStream(bytes);
                Logger.Debug("Start parsing vector tile...");
                var layerInfos = VectorTileParser.Parse(stream);
                tiles[tileInfo] = layerInfos;
            }
            doneEvent.SetOne();
        }
コード例 #23
0
        private bool ProcessTile(TileData t, Map m, int xOffset, int yOffset)
        {
            int x = t.X + xOffset;
            int y = t.Y + yOffset;

            string key = $"{x}_{y}";

            if (MapStore.XY.ContainsKey(key))
            {
                return(false);
            }
            else
            {
                MapStore.XY.Add(key, true);
            }

            // as a sample request Mapzen OSM data in vector tiles format
            //
            var uri    = new Uri($"http://vector.mapzen.com/osm/all/{ t.Z }/{ x}/{ y}.mvt");
            var stream = GetTileFromWeb(uri);

            if (stream == null)
            {
                return(false);
            }

            var layerInfos = VectorTileParser.Parse(stream);

            if (layerInfos.Count == 0)
            {
                return(false);
            }

            // select the POI layer
            var poiLayer = (from layer in layerInfos where layer.Name == "pois" select layer).FirstOrDefault();

            // todo: add other layers and lines/polygons too
            // todo: improve styling
            var fc = poiLayer.ToGeoJSON(x, y, t.Z);

            foreach (var geo in fc.Features)
            {
                // add check for geometry type
                if (geo.Geometry is GeoJSON.Net.Geometry.Point)
                {
                    var    lng1       = ((GeoJSON.Net.Geometry.GeographicPosition)((GeoJSON.Net.Geometry.Point)geo.Geometry).Coordinates).Longitude;
                    var    lat1       = ((GeoJSON.Net.Geometry.GeographicPosition)((GeoJSON.Net.Geometry.Point)geo.Geometry).Coordinates).Latitude;
                    string attributes = String.Empty;
                    foreach (var p in geo.Properties)
                    {
                        attributes += p.Key + ": " + p.Value + Environment.NewLine;
                    }
                    var pin = new Pin()
                    {
                        Position = new Position(lat1, lng1),
                        Label    = $"{lng1},{lat1}",
                    };
                    pin.Clicked += async(sender, e) =>
                    {
                        await App.Current.MainPage.DisplayAlert("Feature Info", attributes, "Ok");
                    };

                    m.Pins.Add(pin);
                }
            }
            return(true);
        }
コード例 #24
0
        public void Decode(int x, int y, int zoom, TreeView tv)
        {
            Bitmap   bmp = new Bitmap(4096, 4096);
            Graphics g   = Graphics.FromImage(bmp);

            g.Clear(Color.Black);


            WebClient client = new WebClient();

            client.Headers[HttpRequestHeader.AcceptEncoding] = "json";
            string path = "http://{ip}:{port}/data/v3/{zoom}/{x}/{y}.geojson";

            path = "http://{ip}:{port}/data/v3/{zoom}/{x}/{y}.pbf";
            path = path.Replace("{zoom}", zoom.ToString());
            path = path.Replace("{x}", x.ToString());
            path = path.Replace("{y}", y.ToString());
            path = path.Replace("{port}", FilePath.Port);
            path = path.Replace("{ip}", FilePath.IP);

            client.DownloadData(path);
            var responseStream = new GZipStream(client.OpenRead(path), CompressionMode.Decompress);

            List <VectorTileLayer> results = VectorTileParser.Parse(responseStream);

            tv.Invoke((MethodInvoker) delegate
            {
                tv.Nodes.Clear();
                tv.BeginUpdate();

                //Pen gray = new Pen(Color.Gray);
                //Pen water = new Pen(Color.Blue);
                //Pen grass = new Pen(Color.Green);
                //Pen CurrentPen = gray;

                Color WaterColor  = Color.Blue;
                Color ForestColor = Color.DarkGreen;
                Color GrassColor  = Color.LightGreen;

                Brush water       = new SolidBrush(WaterColor);
                Brush industrial  = new SolidBrush(Color.Brown);
                Brush residential = new SolidBrush(Color.Purple);
                Brush commercial  = new SolidBrush(Color.Gray);
                Brush building    = new SolidBrush(Color.DarkGray);
                Brush retail      = new SolidBrush(Color.Orange);
                Brush grass       = new SolidBrush(GrassColor);
                Brush forest      = new SolidBrush(ForestColor);
                Brush railway     = new SolidBrush(Color.LightGray);
                Brush road        = new SolidBrush(Color.White);
                Pen transportpen  = new Pen(Color.White);
                //Brush gray = new SolidBrush(Color.Gray);
                Brush none         = new SolidBrush(Color.Transparent);
                Brush CurrentBrush = none;

                bool Transport = false;

                foreach (VectorTileLayer layer in results)
                {
                    CurrentBrush = none;
                    if (layer.Name == "water")
                    {
                        CurrentBrush = water;
                    }
                    if (layer.Name == "park")
                    {
                        CurrentBrush = forest;
                    }
                    if (layer.Name == "building")
                    {
                        CurrentBrush = building;
                    }
                    if (layer.Name == "transportation")
                    {
                        CurrentBrush = road;
                        Transport    = true;
                    }
                    else
                    {
                        Transport = false;
                    }

                    TreeNode layernode = new TreeNode(layer.Name);
                    uint extent        = layer.Extent;
                    tv.Nodes.Add(layernode);
                    foreach (VectorTileFeature feature in layer.VectorTileFeatures)
                    {
                        if ((layer.Name == "landcover") &&
                            (feature.Attributes[0].Key == "class") &&
                            (feature.Attributes[0].Value.Equals("grass")))
                        {
                            CurrentBrush = grass;
                        }


                        if ((layer.Name == "landuse") &&
                            (feature.Attributes[0].Key == "class"))
                        {
                            if (feature.Attributes[0].Value.Equals("residential"))
                            {
                                CurrentBrush = residential;
                            }

                            if (feature.Attributes[0].Value.Equals("commercial"))
                            {
                                CurrentBrush = commercial;
                            }

                            if (feature.Attributes[0].Value.Equals("retail"))
                            {
                                CurrentBrush = retail;
                            }

                            if (feature.Attributes[0].Value.Equals("industrial"))
                            {
                                CurrentBrush = industrial;
                            }

                            if (feature.Attributes[0].Value.Equals("railway"))
                            {
                                CurrentBrush = railway;
                            }
                        }

                        if ((layer.Name == "park") &&
                            (feature.Attributes[0].Key == "class") &&
                            (feature.Attributes[0].Value.Equals("nature_reserve")))
                        {
                            CurrentBrush = forest;
                        }

                        TreeNode featurenode = new TreeNode(feature.Id);
                        layernode.Nodes.Add(featurenode);

                        featurenode.Nodes.Add(feature.GeometryType.ToString());

                        foreach (List <Coordinate> coordlist in feature.Geometry)
                        {
                            TreeNode coordlistnode = new TreeNode("Coordinates");
                            featurenode.Nodes.Add(coordlistnode);

                            List <Point> points = new List <Point>();

                            foreach (Coordinate c in coordlist)
                            {
                                var v              = c.ToPosition(x, y, zoom, extent);
                                string coord       = string.Format("{0},{1} ({2},{3})", v.Latitude, v.Longitude, c.X, c.Y);
                                TreeNode coordnode = new TreeNode(coord);
                                coordlistnode.Nodes.Add(coordnode);
                                points.Add(new Point((int)c.X, (int)c.Y));
                            }

                            if (points.Count > 1)
                            {
                                if (Transport == true)
                                {
                                    g.DrawLines(transportpen, points.ToArray());
                                }
                                else
                                {
                                    g.FillPolygon(CurrentBrush, points.ToArray());
                                }
                            }

                            //TreeNode coord = new TreeNode(item.)
                        }

                        foreach (KeyValuePair <string, object> att in feature.Attributes)
                        {
                            TreeNode attNode = new TreeNode(att.Key);
                            if (att.Key.Equals("class"))
                            {
                                featurenode.Text += " " + att.Value;
                            }

                            if (att.Key.Equals("name"))
                            {
                                featurenode.Text += ": " + att.Value;
                            }

                            featurenode.Nodes.Add(att.Key + ":" + att.Value);
                            //Console.WriteLine("   -" + att.Key + ":" + att.Value);
                        }
                    }
                    // layernode.ExpandAll();
                }

                tv.EndUpdate();

                g.Dispose();
                string spath = FilePath.GetPath(new vector3(x, y, zoom), "biome") + ".png";

                string sKey = "Key\n";
                sKey       += ColToS("water", WaterColor);
                sKey       += ColToS("grass", GrassColor);
                sKey       += ColToS("forest", ForestColor);
                sKey       += ColToS("industrial", Color.Brown);
                sKey       += ColToS("residential", Color.Purple);
                sKey       += ColToS("commercial", Color.Gray);
                sKey       += ColToS("retail", Color.Orange);
                sKey       += ColToS("railway", Color.LightGray);
                sKey       += ColToS("road", Color.White);
                sKey       += ColToS("building", Color.DarkGray);

                File.WriteAllText("data\\" + zoom + "\\biome\\key.txt", sKey);

                Bitmap lo = new Bitmap(256, 256);
                using (var gr = Graphics.FromImage(lo))
                {
                    gr.DrawImage(bmp, 0, 0, lo.Width, lo.Height);
                }
                lo.Save(spath, ImageFormat.Png);
                bmp.Dispose();
            });
        }
コード例 #25
0
        // tests from https://github.com/mapbox/vector-tile-js/blob/master/test/parse.test.js
        public void TestMapBoxVectorTile()
        {
            // arrange
            const string mapboxfile = "mapbox.vector.tile.tests.testdata.14-8801-5371.vector.pbf";

            // act
            var pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(mapboxfile);
            var layerInfos = VectorTileParser.Parse(pbfStream);

            // check features
            Assert.IsTrue(layerInfos[17].ToGeoJSON(8801, 5371, 14) != null);
            Assert.IsTrue(layerInfos.Count == 20);
            Assert.IsTrue(layerInfos[0].VectorTileFeatures.Count == 107);
            Assert.IsTrue(layerInfos[0].VectorTileFeatures[0].Attributes.Count == 2);

            // check park feature
            var park           = layerInfos[17].VectorTileFeatures[11];
            var firstOrDefault = (from prop in park.Attributes where prop.Key == "name" select prop.Value).FirstOrDefault();

            if (firstOrDefault != null)
            {
                var namePark = firstOrDefault.ToString();
                Assert.IsTrue(namePark == "Mauerpark");
            }
            var pnt = park.Geometry[0];
            var p   = pnt[0];

            Assert.IsTrue(Math.Abs(p.X - 3898) < 0.1);
            Assert.IsTrue(Math.Abs(p.Y - 1731) < 0.1);

            // Check line geometry from roads
            var road = layerInfos[8].VectorTileFeatures[656];
            var ls   = road.Geometry[0];

            Assert.IsTrue(ls.Count == 3);
            var firstPoint = ls[0];

            Assert.IsTrue(Math.Abs(firstPoint.X - 1988) < 0.1);
            Assert.IsTrue(Math.Abs(firstPoint.Y - 306) < 0.1);

            var secondPoint = ls[1];

            Assert.IsTrue(Math.Abs(secondPoint.X - 1808) < 0.1);
            Assert.IsTrue(Math.Abs(secondPoint.Y - 321) < 0.1);

            var thirdPoint = ls[2];

            Assert.IsTrue(Math.Abs(thirdPoint.X - 1506) < 0.1);
            Assert.IsTrue(Math.Abs(thirdPoint.Y - 347) < 0.1);

            // check building geometry
            var buildings = layerInfos[5].VectorTileFeatures[0];
            var poly      = buildings.Geometry[0];

            Assert.IsTrue(poly.Count == 5);

            var p1 = poly[0];

            Assert.IsTrue(Math.Abs(p1.X - 2039) < 0.1);
            Assert.IsTrue(Math.Abs(p1.Y - (-32)) < 0.1);
            var p2 = poly[1];

            Assert.IsTrue(Math.Abs(p2.X - 2035) < 0.1);
            Assert.IsTrue(Math.Abs(p2.Y - (-31)) < 0.1);
            var p3 = poly[2];

            Assert.IsTrue(Math.Abs(p3.X - 2032) < 0.1);
            Assert.IsTrue(Math.Abs(p3.Y - (-31)) < 0.1);
            var p4 = poly[3];

            Assert.IsTrue(Math.Abs(p4.X - 2032) < 0.1);
            Assert.IsTrue(Math.Abs(p4.Y - (-32)) < 0.1);
            var p5 = poly[4];

            Assert.IsTrue(Math.Abs(p5.X - 2039) < 0.1);
            Assert.IsTrue(Math.Abs(p5.Y - (-32)) < 0.1);
        }
コード例 #26
0
 public List <VectorTileLayer> ParseVectorTileFromStream()
 {
     return(VectorTileParser.Parse(input));
 }
コード例 #27
0
        public void TestMapBoxVectorTileNew()
        {
            // arrange
            const string mapboxfile = "mapbox.vector.tile.tests.testdata.14-8801-5371.vector.pbf";

            // act
            var pbfStream  = Assembly.GetExecutingAssembly().GetManifestResourceStream(mapboxfile);
            var layerInfos = VectorTileParser.Parse(pbfStream);

            // check features
            Assert.IsTrue(layerInfos.Count == 20);
            Assert.IsTrue(layerInfos[0].VectorTileFeatures.Count == 107);
            Assert.IsTrue(layerInfos[0].VectorTileFeatures[0].Attributes.Count == 2);

            // check park feature
            var park           = layerInfos[17].VectorTileFeatures[11];
            var firstOrDefault = (from prop in park.Attributes where prop.Key == "name" select prop.Value).FirstOrDefault();

            if (firstOrDefault != null)
            {
                var namePark = firstOrDefault.ToString();
                Assert.IsTrue(namePark == "Mauerpark");
            }

            // check point geometry type from park
            Assert.IsTrue(park.Id == "3000003150561");
            Assert.IsTrue(park.GeometryType == GeomType.Point);
            Assert.IsTrue(park.Geometry.Count == 1);
            Assert.IsTrue(park.Geometry[0].Count == 1);
            var p = park.Geometry[0][0];

            Assert.IsTrue(Math.Abs(p.X - 3898) < 0.1);
            Assert.IsTrue(Math.Abs(p.Y - 1731) < 0.1);

            // Check line geometry from roads
            var road = layerInfos[8].VectorTileFeatures[656];

            Assert.IsTrue(road.Id == "241452814");
            Assert.IsTrue(road.GeometryType == GeomType.LineString);
            var ls = road.Geometry;

            Assert.IsTrue(ls.Count == 1);
            Assert.IsTrue(ls[0].Count == 3);
            var firstPoint = ls[0][0];

            Assert.IsTrue(Math.Abs(firstPoint.X - 1988) < 0.1);
            Assert.IsTrue(Math.Abs(firstPoint.Y - 306) < 0.1);

            var secondPoint = ls[0][1];

            Assert.IsTrue(Math.Abs(secondPoint.X - 1808) < 0.1);
            Assert.IsTrue(Math.Abs(secondPoint.Y - 321) < 0.1);

            var thirdPoint = ls[0][2];

            Assert.IsTrue(Math.Abs(thirdPoint.X - 1506) < 0.1);
            Assert.IsTrue(Math.Abs(thirdPoint.Y - 347) < 0.1);

            // Check polygon geometry for buildings
            var building = layerInfos[5].VectorTileFeatures[0];

            Assert.IsTrue(building.Id == "1000267229912");
            Assert.IsTrue(building.GeometryType == GeomType.Polygon);
            var b = building.Geometry;

            Assert.IsTrue(b.Count == 1);
            Assert.IsTrue(b[0].Count == 5);
            firstPoint = b[0][0];
            Assert.IsTrue(Math.Abs(firstPoint.X - 2039) < 0.1);
            Assert.IsTrue(Math.Abs(firstPoint.Y + 32) < 0.1);
            secondPoint = b[0][1];
            Assert.IsTrue(Math.Abs(secondPoint.X - 2035) < 0.1);
            Assert.IsTrue(Math.Abs(secondPoint.Y + 31) < 0.1);
            thirdPoint = b[0][2];
            Assert.IsTrue(Math.Abs(thirdPoint.X - 2032) < 0.1);
            Assert.IsTrue(Math.Abs(thirdPoint.Y + 31) < 0.1);
            var fourthPoint = b[0][3];

            Assert.IsTrue(Math.Abs(fourthPoint.X - 2032) < 0.1);
            Assert.IsTrue(Math.Abs(fourthPoint.Y + 32) < 0.1);
            var fifthPoint = b[0][4];

            Assert.IsTrue(Math.Abs(fifthPoint.X - 2039) < 0.1);
            Assert.IsTrue(Math.Abs(fifthPoint.Y + 32) < 0.1);
        }