示例#1
0
        public void LazyDecoding(string fileName)
        {
            string fullFileName = Path.Combine(fixturesPath, fileName);

            Assert.True(File.Exists(fullFileName), "Vector tile exists");
            byte[]     data = File.ReadAllBytes(fullFileName);
            VectorTile vt   = new VectorTile(data);

            foreach (var layerName in vt.LayerNames())
            {
                VectorTileLayer layer = vt.GetLayer(layerName);
                for (int i = 0; i < layer.FeatureCount(); i++)
                {
                    VectorTileFeature feat = layer.GetFeature(i);
                    var properties         = feat.GetProperties();
                    foreach (var prop in properties)
                    {
                        Assert.AreEqual(prop.Value, feat.GetValue(prop.Key), "Property values match");
                    }
                    foreach (var geomPart in feat.Geometry <int>())
                    {
                        foreach (var coord in geomPart)
                        {
                            //TODO add Assert
                        }
                    }
                }
            }
            string geojson = vt.ToGeoJson(0, 0, 0);

            Assert.GreaterOrEqual(geojson.Length, 30, "geojson >= 30 chars");
        }
示例#2
0
        public CustomFeatureUnity(VectorTileFeature feature, CustomTile tile, float layerExtent, bool buildingsWithUniqueIds = false)
        {
            Data       = feature;
            Properties = Data.GetProperties();
            Points.Clear();
            Tile = tile;

            //this is a temp hack until we figure out how streets ids works
            _geom = buildingsWithUniqueIds ? feature.Geometry <float>() : feature.Geometry <float>(0);

            _rectSizex = tile.Rect.Size.x;
            _rectSizey = tile.Rect.Size.y;

            _geomCount = _geom.Count;
            for (var i = 0; i < _geomCount; i++)
            {
                _pointCount = _geom[i].Count;
                _newPoints  = new List <Vector3>(_pointCount);
                for (var j = 0; j < _pointCount; j++)
                {
                    var point = _geom[i][j];
                    _newPoints.Add(new Vector3((float)(point.X / layerExtent * _rectSizex - (_rectSizex / 2)) * tile.TileScale, 0, (float)((layerExtent - point.Y) / layerExtent * _rectSizey - (_rectSizey / 2)) * tile.TileScale));
                }
                Points.Add(_newPoints);
            }
        }
        public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile, float layerExtent, bool buildingsWithUniqueIds = false)
        {
            Data       = feature;
            Properties = Data.GetProperties();
            Points.Clear();

            //this is a temp hack until we figure out how streets ids works
            if (buildingsWithUniqueIds == true)      //ids from building dataset is big ulongs
            {
                _geom = feature.Geometry <float>();  //and we're not clipping by passing no parameters
            }
            else                                     //streets ids, will require clipping
            {
                _geom = feature.Geometry <float>(0); //passing zero means clip at tile edge
            }

            _rectSizex = tile.Rect.Size.x;
            _rectSizey = tile.Rect.Size.y;

            _geomCount = _geom.Count;
            for (int i = 0; i < _geomCount; i++)
            {
                _pointCount = _geom[i].Count;
                _newPoints  = new List <Vector3>(_pointCount);
                for (int j = 0; j < _pointCount; j++)
                {
                    var point = _geom[i][j];
                    _newPoints.Add(new Vector3((float)(point.X / layerExtent * _rectSizex - (_rectSizex / 2)) * tile.TileScale, 0, (float)((layerExtent - point.Y) / layerExtent * _rectSizey - (_rectSizey / 2)) * tile.TileScale));
                }
                Points.Add(_newPoints);
            }
        }
示例#4
0
        public override GOFeature ParseFeatureData(VectorTileFeature feature, GOLayer layer)
        {
            IDictionary properties = feature.GetProperties();
            GOFeature   goFeature;

            if (layer.layerType == GOLayer.GOLayerType.Roads)
            {
                goFeature = new GORoadFeature();
            }
            else
            {
                goFeature = new GOFeature();
            }

            goFeature.kind = GOEnumUtils.MapboxToKind(layer.name);

            goFeature.y = layer.defaultLayerY();
            if (properties.Contains("_symbol"))
            {
                goFeature.y = Convert.ToInt64(properties ["_symbol"]) / 10.0f * Global.tilesizeRank;
            }

            goFeature.height = layer.defaultRendering.polygonHeight;

            return(goFeature);
        }
示例#5
0
        private void ParseLabelLayerToList(List <GOParsedLayer> list, VectorTile vt, GOLabelsLayer layer)
        {
            string[] lyrs = tile.GetLabelsStrings().Split(',');
//			string kindKey = tile.GetPoisKindKey();

            foreach (string l in lyrs)
            {
                VectorTileLayer lyr = vt.GetLayer(l);
                if (lyr != null)
                {
                    int featureCount = lyr.FeatureCount();

                    if (featureCount == 0)
                    {
                        continue;
                    }

                    GOParsedLayer pl = new GOParsedLayer();
                    pl.name        = lyr.Name;
                    pl.labelsLayer = layer;
                    pl.goFeatures  = new List <GOFeature> ();

                    for (int i = 0; i < featureCount; i++)
                    {
                        VectorTileFeature vtf        = lyr.GetFeature(i);
                        IDictionary       properties = vtf.GetProperties();

                        List <List <LatLng> > geomWgs = vtf.GeometryAsWgs84((ulong)goTile.zoomLevel, (ulong)goTile.tileCoordinates.x, (ulong)goTile.tileCoordinates.y, 0);

                        if (geomWgs.Count == 0 || geomWgs[0].Count <= 1)
                        {
                            continue;
                        }

                        GOFeature gf = new GOFeature();
                        gf.properties    = properties;
                        gf.goFeatureType = vtf.GOFeatureType(geomWgs);
                        gf.labelsLayer   = layer;
                        gf.featureIndex  = (Int64)i + vt.LayerNames().IndexOf(lyr.Name);
                        gf.goTile        = goTile;
                        gf = tile.EditLabelData(gf);
                        gf.goFeatureType = GOFeatureType.Label;

                        gf.ConvertAttributes();
                        if (geomWgs.Count > 0)
                        {
                            gf.geometry = geomWgs[0];
                            gf.ConvertGeometries();
                            gf.preloadedLabelData = GOSegment.FindTheLongestStreightSegment(gf.convertedGeometry, 0);
                            AddFatureToList(gf, pl.goFeatures);
                        }
                    }
                    list.Add(pl);
                }
            }
        }
示例#6
0
        public void TestVectTile()
        {
            var        pbf = File.ReadAllBytes(@"E:\Downloads\63.pbf");
            VectorTile vt  = new VectorTile(pbf, false);

            foreach (var layerName in vt.LayerNames())
            {
                VectorTileLayer layer = vt.GetLayer(layerName);
                for (int j = 0; j < layer.FeatureCount(); j++)
                {
                    VectorTileFeature feat = layer.GetFeature(j);
                    var ff    = feat.Geometry <long>();
                    var props = feat.GetProperties();
                }
            }
        }
        public override GOFeature ParseFeatureData(VectorTileFeature feature, GOLayer layer)
        {
            IDictionary properties = feature.GetProperties();
            GOFeature   goFeature;

            if (layer.layerType == GOLayer.GOLayerType.Roads)
            {
                goFeature = new GORoadFeature();
                ((GORoadFeature)goFeature).isBridge = properties.Contains("brunnel") && (string)properties ["brunnel"] == "bridge";
                ((GORoadFeature)goFeature).isTunnel = properties.Contains("brunnel") && (string)properties ["brunnel"] == "tunnel";
                ((GORoadFeature)goFeature).isLink   = properties.Contains("brunnel") && (string)properties ["brunnel"] == "link";
            }
            else
            {
                goFeature = new GOFeature();
            }

            goFeature.kind = GOEnumUtils.MapboxToKind((string)properties["class"]);

            goFeature.y = goFeature.index / 1000 + layer.defaultLayerY();

            if (goFeature.kind == GOFeatureKind.lake)             //terrible fix for vector maps without a sort value.
            {
                goFeature.y = layer.defaultLayerY(GOLayer.GOLayerType.Landuse);
            }

            goFeature.height = layer.defaultRendering.polygonHeight;

            if (layer.useRealHeight && properties.Contains("render_height"))
            {
                double h = Convert.ToDouble(properties["render_height"]);
                goFeature.height = (float)h;
            }

            if (layer.useRealHeight && properties.Contains("render_min_height"))
            {
                double hm = Convert.ToDouble(properties["render_min_height"]);
                goFeature.y = (float)hm;
                if (goFeature.height >= hm)
                {
                    goFeature.y      = (float)hm;
                    goFeature.height = (float)goFeature.height - (float)hm;
                }
            }

            return(goFeature);
        }
        public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile, float layerExtent)
        {
            Data       = feature;
            Properties = Data.GetProperties();
            Points     = new List <List <Vector3> >();

            for (int i = 0; i < feature.Geometry.Count; i++)
            {
                var nl = new List <Vector3>(feature.Geometry[i].Count);
                for (int j = 0; j < feature.Geometry[i].Count; j++)
                {
                    var point = feature.Geometry[i][j];
                    nl.Add(new Vector3((float)(point.X / layerExtent * tile.Rect.Size.x - (tile.Rect.Size.x / 2)), 0, (float)((layerExtent - point.Y) / layerExtent * tile.Rect.Size.y - (tile.Rect.Size.y / 2))));
                }
                Points.Add(nl);
            }
        }
示例#9
0
        public void FeatureSinglePoint()
        {
            byte[]     data = File.ReadAllBytes(Path.Combine(fixturesPath, "Feature-single-point.mvt"));
            VectorTile vt   = new VectorTile(data);

            Assert.AreEqual(1, vt.LayerNames().Count, "one layer");
            VectorTileLayer lyr = vt.GetLayer(vt.LayerNames()[0]);

            Assert.AreEqual("layer_name", lyr.Name, "Layer name");
            Assert.AreEqual(1, lyr.FeatureCount(), "Feature count");
            VectorTileFeature feat = lyr.GetFeature(0);

            Assert.AreEqual(GeomType.POINT, feat.GeometryType, "Geometry type");
            Assert.AreEqual(123, feat.Id, "id");
            Dictionary <string, object> properties = feat.GetProperties();

            Assert.AreEqual("world", properties["hello"]);
            Assert.AreEqual("world", feat.GetValue("hello"));
        }
示例#10
0
        private static void DrawLineString(VectorTileFeature feature, Pallete pallete, Graphics graphics, double divisionRatio)
        {
            Dictionary <string, object> props = feature.GetProperties();

            foreach (List <Vector2 <int> > geometry in feature.Geometry <int>())
            {
                Point[] points = geometry.Select(vector2 => new Point((int)Math.Ceiling(vector2.X / divisionRatio), (int)Math.Ceiling(vector2.Y / divisionRatio))).ToArray();
                using (Pen pen = new Pen(pallete.MainDrawPen.Color, 2))
                {
                    graphics.DrawLines(pen, points);
                }

                // Draw name of street
                //if (props.ContainsKey("name"))
                //{
                //	var text = (string)props["name"];
                //	foreach (Vector2<int> point in geometry)
                //	{
                //		graphics.DrawString(text, font, pallete.GetPropFillBrush("name"), point.X, point.Y);
                //	}
                //}
            }
        }
示例#11
0
        public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile, float layerExtent)
        {
            Data       = feature;
            Properties = Data.GetProperties();
            Points.Clear();

            _rectSizex = tile.Rect.Size.x;
            _rectSizey = tile.Rect.Size.y;

            _geom      = feature.Geometry <float>(0);
            _geomCount = _geom.Count;
            for (int i = 0; i < _geomCount; i++)
            {
                _pointCount = _geom[i].Count;
                _newPoints  = new List <Vector3>(_pointCount);
                for (int j = 0; j < _pointCount; j++)
                {
                    var point = _geom[i][j];
                    _newPoints.Add(new Vector3((float)(point.X / layerExtent * _rectSizex - (_rectSizex / 2)) * tile.TileScale, 0, (float)((layerExtent - point.Y) / layerExtent * _rectSizey - (_rectSizey / 2)) * tile.TileScale));
                }
                Points.Add(_newPoints);
            }
        }
示例#12
0
        public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile, float layerExtent)
        {
            Data       = feature;
            Properties = Data.GetProperties();
            Points     = new List <List <Vector3> >();

            double unityTileSizeX = tile.Rect.Size.x;
            double unityTileSizeY = tile.Rect.Size.y;

            List <List <Point2d <float> > > geom = feature.Geometry <float>();
            var geomCount = geom.Count;

            for (int i = 0; i < geomCount; i++)
            {
                var pointCount = geom[i].Count;
                var nl         = new List <Vector3>(pointCount);
                for (int j = 0; j < pointCount; j++)
                {
                    var point = geom[i][j];
                    nl.Add(new Vector3((float)(point.X / layerExtent * unityTileSizeX - (unityTileSizeX / 2)) * tile.TileScale, 0, (float)((layerExtent - point.Y) / layerExtent * unityTileSizeY - (unityTileSizeY / 2)) * tile.TileScale));
                }
                Points.Add(nl);
            }
        }
示例#13
0
        public VectorFeatureUnity(VectorTileFeature feature, List <List <Point2d <float> > > geom, UnityTile tile, float layerExtent, bool buildingsWithUniqueIds = false)
        {
            Data       = feature;
            Properties = Data.GetProperties();
            Points.Clear();
            Tile  = tile;
            _geom = geom;

            _rectSizex = tile.Rect.Size.x;
            _rectSizey = tile.Rect.Size.y;

            _geomCount = _geom.Count;
            for (int i = 0; i < _geomCount; i++)
            {
                _pointCount = _geom[i].Count;
                _newPoints  = new List <Vector3>(_pointCount);
                for (int j = 0; j < _pointCount; j++)
                {
                    var point = _geom[i][j];
                    _newPoints.Add(new Vector3((float)(point.X / layerExtent * _rectSizex - (_rectSizex / 2)) * tile.TileScale, 0, (float)((layerExtent - point.Y) / layerExtent * _rectSizey - (_rectSizey / 2)) * tile.TileScale));
                }
                Points.Add(_newPoints);
            }
        }
示例#14
0
        public IEnumerator BuildLayer(VectorTileLayer layerData, GOLayer layer, bool delayedLoad)
        {
            GameObject parent = null;

            if (transform.FindChild(layer.name) == null)
            {
                parent                  = new GameObject();
                parent.name             = layer.name;
                parent.transform.parent = this.transform;
                parent.SetActive(!layer.startInactive);
            }
            else
            {
                parent = transform.FindChild(layer.name).gameObject;
            }


            if (layerData.FeatureCount() == 0)
            {
                yield break;
            }


            List <GOFeature> stack = new List <GOFeature> ();

            for (int i = 0; i < layerData.FeatureCount(); i++)
            {
                //get the feature
                VectorTileFeature feature   = layerData.GetFeature(i);
                GOFeature         goFeature = ParseFeatureData(feature, layer);

                if (layer.useOnly.Length > 0 && !layer.useOnly.Contains(goFeature.kind))
                {
                    continue;
                }
                if (layer.avoid.Length > 0 && layer.avoid.Contains(goFeature.kind))
                {
                    continue;
                }

                if (layer.layerType == GOLayer.GOLayerType.Roads)
                {
                    GORoadFeature grf = (GORoadFeature)goFeature;
                    if ((grf.isBridge && !layer.useBridges) || (grf.isTunnel && !layer.useTunnels) || (grf.isLink && !layer.useBridges))
                    {
                        continue;
                    }
                }

                //multipart
                List <List <LatLng> > geomWgs84 = feature.GeometryAsWgs84((ulong)map.zoomLevel, (ulong)tileCoordinates.x, (ulong)tileCoordinates.y, 0);

                string type = feature.GetFeatureType(geomWgs84);
                if (type == null || feature.GeometryType == GeomType.POINT)
                {
                    continue;
                }
                if (feature.GeometryType == GeomType.POLYGON && layer.layerType == GOLayer.GOLayerType.Roads)
                {
                    continue;
                }

                if (type == "MultiLineString" || (type == "Polygon" && !layer.isPolygon))
                {
                    foreach (IList geometry in geomWgs84)
                    {
                        GOFeature gf = ParseFeatureData(feature, layer);
                        gf.geometry   = geometry;
                        gf.type       = type;
                        gf.layer      = layer;
                        gf.parent     = parent;
                        gf.properties = feature.GetProperties();
                        gf.ConvertGeometries();
                        gf.ConvertAttributes();
                        gf.index         = (Int64)i;
                        gf.goFeatureType = GOFeature.GOFeatureType.MultiLine;
                        stack.Add(gf);
                    }
                }
                else if (type == "LineString")
                {
                    GOFeature gf = ParseFeatureData(feature, layer);
                    gf.geometry   = geomWgs84 [0];
                    gf.type       = type;
                    gf.layer      = layer;
                    gf.parent     = parent;
                    gf.properties = feature.GetProperties();
                    gf.ConvertGeometries();
                    gf.ConvertAttributes();
                    gf.index         = (Int64)i;
                    gf.goFeatureType = GOFeature.GOFeatureType.Line;
                    if (geomWgs84.Count == 0)
                    {
                        continue;
                    }

                    stack.Add(gf);
                }

                else if (type == "Polygon")
                {
                    GOFeature gf = ParseFeatureData(feature, layer);
                    gf.geometry   = geomWgs84 [0];
                    gf.type       = type;
                    gf.layer      = layer;
                    gf.parent     = parent;
                    gf.properties = feature.GetProperties();
                    gf.ConvertGeometries();
                    gf.ConvertAttributes();
                    gf.index         = (Int64)i;
                    gf.goFeatureType = GOFeature.GOFeatureType.Polygon;

                    stack.Add(gf);
                }

                else if (type == "MultiPolygon")
                {
                    GameObject multi = new GameObject("MultiPolygon");
                    multi.transform.parent = parent.transform;

                    IList subject = null;
                    IList clips   = new List <List <LatLng> >();

                    for (int j = 0; j < geomWgs84.Count; j++)                     //Clip ascending

                    {
                        IList p = geomWgs84 [j];
                        if (GOFeature.IsGeoPolygonClockwise(p))
                        {
                            subject = p;
                        }
                        else
                        {
                            //Add clip
                            clips.Add(p);
                        }
                        //Last one
                        if (j == geomWgs84.Count - 1 || (j < geomWgs84.Count - 1 && GOFeature.IsGeoPolygonClockwise(geomWgs84 [j + 1]) && subject != null))
                        {
                            GOFeature gf = ParseFeatureData(feature, layer);
                            gf.geometry   = subject;
                            gf.clips      = clips;
                            gf.type       = type;
                            gf.layer      = layer;
                            gf.parent     = parent;
                            gf.properties = feature.GetProperties();
                            gf.ConvertGeometries();
                            gf.ConvertAttributes();
                            gf.index         = (Int64)i;
                            gf.goFeatureType = GOFeature.GOFeatureType.MultiPolygon;

                            stack.Add(gf);

                            subject = null;
                            clips   = new List <List <LatLng> >();
                        }
                    }
                }
            }

            IList iStack = (IList)stack;

            if (layer.layerType == GOLayer.GOLayerType.Roads)
            {
                iStack = GORoadFeature.MergeRoads(iStack);
            }

            int n = 25;

            for (int i = 0; i < iStack.Count; i += n)
            {
                for (int k = 0; k < n; k++)
                {
                    if (i + k >= iStack.Count)
                    {
                        yield return(null);

                        break;
                    }

                    GOFeature   r       = (GOFeature)iStack [i + k];
                    IEnumerator routine = r.BuildFeature(this, delayedLoad);
                    if (routine != null)
                    {
                        if (Application.isPlaying)
                        {
                            StartCoroutine(routine);
                        }
                        else
                        {
                            GORoutine.start(routine, this);
                        }
                    }
                }
                yield return(new WaitForSeconds(0.5f));
            }

            Resources.UnloadUnusedAssets();

            yield return(null);
        }
示例#15
0
        public override void Run(VectorTileFeature feature, MeshData md)
        {
            if (md.Vertices.Count == 0)
            {
                return;
            }

            var prop = feature.GetProperties();

            if (prop.ContainsKey("height"))
            {
                Height = Convert.ToSingle(feature.GetValue("height"));
            }

            var buildingLowest  = float.MaxValue;
            var buildingHighest = float.MinValue;

            foreach (var vector in md.Vertices)
            {
                if (vector.y < buildingLowest)
                {
                    buildingLowest = vector.y;
                }
                if (vector.y > buildingHighest)
                {
                    buildingHighest = vector.y;
                }
            }
            var buildingHighestOnTerrain = buildingHighest + Height;

            if (FlatTop)
            {
                for (int i = 0; i < md.Vertices.Count; i++)
                {
                    md.Vertices[i] = new Vector3(md.Vertices[i].x, buildingHighestOnTerrain, md.Vertices[i].z);
                }
            }
            else
            {
                var pushUp = new Vector3(0, Height, 0);
                for (int i = 0; i < md.Vertices.Count; i++)
                {
                    md.Vertices[i] += pushUp;
                }
            }

            var     vertsStartCount = 0;
            var     count           = md.Vertices.Count;
            float   d = 0f;
            Vector3 v1;
            Vector3 v2;
            int     ind = 0;

            var wallTri = new List <int>();
            var wallUv  = new List <Vector2>();

            for (int i = 1; i < count; i++)
            {
                v1  = md.Vertices[vertsStartCount + i - 1];
                v2  = md.Vertices[vertsStartCount + i];
                ind = md.Vertices.Count;
                md.Vertices.Add(v1);
                md.Vertices.Add(v2);
                md.Vertices.Add(new Vector3(v1.x, buildingLowest, v1.z));
                md.Vertices.Add(new Vector3(v2.x, buildingLowest, v2.z));

                d = (v2 - v1).magnitude;

                wallUv.Add(new Vector2(0, 0));
                wallUv.Add(new Vector2(d, 0));
                wallUv.Add(new Vector2(0, Height));
                wallUv.Add(new Vector2(d, Height));

                wallTri.Add(ind);
                wallTri.Add(ind + 2);
                wallTri.Add(ind + 1);

                wallTri.Add(ind + 1);
                wallTri.Add(ind + 2);
                wallTri.Add(ind + 3);
            }

            if (CloseEnd)
            {
                v1  = md.Vertices[vertsStartCount];
                v2  = md.Vertices[vertsStartCount + count - 1];
                ind = md.Vertices.Count;
                md.Vertices.Add(v1);
                md.Vertices.Add(v2);
                md.Vertices.Add(new Vector3(v1.x, buildingLowest, v1.z));
                md.Vertices.Add(new Vector3(v2.x, buildingLowest, v2.z));

                d = (v2 - v1).magnitude;

                wallUv.Add(new Vector2(0, 0));
                wallUv.Add(new Vector2(d, 0));
                wallUv.Add(new Vector2(0, Height));
                wallUv.Add(new Vector2(d, Height));

                wallTri.Add(ind);
                wallTri.Add(ind + 1);
                wallTri.Add(ind + 2);

                wallTri.Add(ind + 1);
                wallTri.Add(ind + 3);
                wallTri.Add(ind + 2);
            }

            md.Triangles.Add(wallTri);

            md.UV[0].AddRange(wallUv);
        }
示例#16
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            SynchronizationContext sync = SynchronizationContext.Current;

            lvInfo.Items.Clear();

            int        countReq  = 0;
            int        countResp = 0;
            FileSource fs        = new FileSource();

            //https://api.mapbox.com/v4/mapbox.mapbox-streets-v7/14/3410/6200.vector.pbf
            //https://api.mapbox.com/v4/mapbox.mapbox-streets-v7/14/3410/6200.vector.pbf
            //https://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v7/18/74984/100276.vector.pbf

            object locker = new object();

            DateTime dtStart = DateTime.Now;

            System.Diagnostics.Debug.WriteLine(string.Format(" ============> WinForm, thread id:{0} <==============", System.Threading.Thread.CurrentThread.ManagedThreadId));
            for (int i = (int)outerLoopStart.Value; i < (int)outerLoopStop.Value; i++)
            {
                for (int x = (int)tileXstart.Value; x < tileXstop.Value; x++)
                {
                    countReq++;
                    lblReqCnt.Text = countReq.ToString();

                    HTTPRequest request = (HTTPRequest)fs.Request(
                        string.Format("https://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v7/18/{0}/100276.vector.pbf", x)
                        , (Response r) => {
                        System.Diagnostics.Debug.WriteLine(string.Format("winform response, thread id:{0}", System.Threading.Thread.CurrentThread.ManagedThreadId));
                        //lock (locker) {
                        countResp++;
                        if (countResp == 1)
                        {
                            foreach (var hdr in r.Headers)
                            {
                                addItem(string.Format("{0}: {1}", hdr.Key, hdr.Value));
                            }
                        }
                        if (0 == countResp % 500)
                        {
                            Application.DoEvents();
                        }
                        try {
                            if (lblRespCnt.InvokeRequired)
                            {
                                System.Diagnostics.Debug.WriteLine(string.Format("winform lblRespCnt.InvokeRequired, thread id:{0}", System.Threading.Thread.CurrentThread.ManagedThreadId));
                                //lblRespCnt.Invoke(new Action(() => { lblRespCnt.Text = countResp.ToString(); }));
                                //Invoke((MethodInvoker)delegate { lblRespCnt.Text = countResp.ToString(); });
                                //sync.Send(delegate { lblRespCnt.Text = countResp.ToString(); }, null);
                                //sync.Send(delegate { lblRespCnt.Text = countResp.ToString(); }, null);
                                sync.Post(delegate { lblRespCnt.Text = countResp.ToString(); }, null);
                            }
                            else
                            {
                                System.Diagnostics.Debug.WriteLine(string.Format("winform !lblRespCnt.InvokeRequired, thread id:{0}", System.Threading.Thread.CurrentThread.ManagedThreadId));
                                lblRespCnt.Text = countResp.ToString();
                            }
                        }
                        catch (Exception ex) {
                            addItem(ex.ToString());
                        }
                        //}
                        if (r.RateLimitHit)
                        {
                            addItem(string.Format("{3} statuscode:{4} rate limit hit:{5} --- LimitInterval:{0} LimitLimit:{1} LimitReset:{2}", r.XRateLimitInterval, r.XRateLimitLimit, r.XRateLimitReset, x, r.StatusCode, r.RateLimitHit));
                        }
                        if (r.StatusCode != 200)
                        {
                            if (null != r.Data && r.Data.Length > 0)
                            {
                                addItem(Encoding.UTF8.GetString(r.Data));
                            }
                            else
                            {
                                addItem(string.Format("StatusCode: {0} - NO body", r.StatusCode));
                            }
                        }
                        if (r.HasError)
                        {
                            addItem("");
                            foreach (var ex in r.Exceptions)
                            {
                                addItem(ex.ToString());
                            }
                            addItem("");
                            return;
                        }

                        if (IDC_chkDecodeVTs.Checked)
                        {
                            try {
                                VectorTile.VectorTile vt = new VectorTile.VectorTile(r.Data);
                                foreach (var lyrName in vt.LayerNames())
                                {
                                    VectorTileLayer lyr = vt.GetLayer(lyrName);
                                    for (int j = 0; j < lyr.FeatureCount(); j++)
                                    {
                                        VectorTileFeature feat = lyr.GetFeature(j);
                                        feat.GetProperties();
                                        feat.Geometry <int>();
                                    }
                                }
                            }
                            catch (Exception ex) {
                                addItem(ex.ToString());
                            }
                        }
                    }
                        );
                }
            }



            addItem("waiting ...");
            Application.DoEvents();
            //while (!request.IsCompleted) {  }
            fs.WaitForAllRequests();
            DateTime dtFinished = DateTime.Now;

            addItem(string.Format("finished! requests:{0} responses:{1}", countReq, countResp));
            addItem(string.Format(
                        "{0} -> {1}, elapsed {2}s"
                        , dtStart.ToString("HH:mm:ss")
                        , dtFinished.ToString("HH:mm:ss")
                        , dtFinished.Subtract(dtStart).TotalSeconds
                        ));
        }
示例#17
0
        private void ParsePOILayerToList(List <GOParsedLayer> list, VectorTile vt, GOPOILayer layer)
        {
            string[] lyrs    = tile.GetPoisStrings().Split(',');
            string   kindKey = tile.GetPoisKindKey();

            foreach (string l in lyrs)
            {
                VectorTileLayer lyr = vt.GetLayer(l);
                if (lyr != null)
                {
                    int featureCount = lyr.FeatureCount();

                    if (featureCount == 0)
                    {
                        continue;
                    }

                    GOParsedLayer pl = new GOParsedLayer();
                    pl.name       = lyr.Name;
                    pl.poiLayer   = layer;
                    pl.goFeatures = new List <GOFeature> ();

                    for (int i = 0; i < featureCount; i++)
                    {
                        VectorTileFeature vtf        = lyr.GetFeature(i);
                        IDictionary       properties = vtf.GetProperties();

                        GOPOIKind      kind      = GOEnumUtils.PoiKindToEnum((string)properties[kindKey]);
                        GOPOIRendering rendering = layer.GetRenderingForPoiKind(kind);

                        if (kind == GOPOIKind.UNDEFINED || rendering == null)
                        {
                            continue;
                        }

                        List <List <LatLng> > geomWgs = vtf.GeometryAsWgs84((ulong)goTile.zoomLevel, (ulong)goTile.tileCoordinates.x, (ulong)goTile.tileCoordinates.y, 0);
                        GOFeature             gf      = new GOFeature();
                        gf.poiKind       = kind;
                        gf.goTile        = goTile;
                        gf.properties    = properties;
                        gf.attributes    = GOFeature.PropertiesToAttributes(gf.properties);
                        gf.goFeatureType = vtf.GOFeatureType(geomWgs);

                        if (gf.goFeatureType == GOFeatureType.Undefined)
                        {
                            continue;
                        }

                        gf.poiLayer     = layer;
                        gf.poiRendering = rendering;
                        gf.featureIndex = (Int64)i + vt.LayerNames().IndexOf(lyr.Name);
                        gf = tile.EditFeatureData(gf);
                        gf.ConvertAttributes();

                        if (geomWgs.Count > 0 && gf.goFeatureType == GOFeatureType.Point)
                        {
                            gf.geometry = geomWgs [0];
                            gf.ConvertPOIGeometries();
                            AddFatureToList(gf, pl.goFeatures);
                        }
                    }

                    list.Add(pl);
                }
            }
        }
示例#18
0
        private void ParseGOLayerToList(List <GOParsedLayer> list, VectorTile vt, GOLayer layer)
        {
            string[] lyrs = tile.GetLayersStrings(layer).Split(',');

            foreach (string l in lyrs)
            {
                VectorTileLayer lyr = vt.GetLayer(l);
                if (lyr != null)
                {
                    int featureCount = lyr.FeatureCount();

                    if (featureCount == 0)
                    {
                        continue;
                    }

                    GOParsedLayer pl = new GOParsedLayer();
                    pl.name       = lyr.Name;
                    pl.goLayer    = layer;
                    pl.goFeatures = new List <GOFeature> ();

                    int indexOfLayer = vt.LayerNames().IndexOf(lyr.Name);

                    for (int i = 0; i < featureCount; i++)
                    {
                        VectorTileFeature vtf = lyr.GetFeature(i);

                        List <List <LatLng> > geomWgs = vtf.GeometryAsWgs84((ulong)goTile.zoomLevel, (ulong)goTile.tileCoordinates.x, (ulong)goTile.tileCoordinates.y, 0);

                        GOFeature gf;
                        if (layer.layerType == GOLayer.GOLayerType.Roads)
                        {
                            gf = new GORoadFeature();
                        }
                        else
                        {
                            gf = new GOFeature();
                        }

                        gf.properties    = vtf.GetProperties();
                        gf.attributes    = GOFeature.PropertiesToAttributes(gf.properties);
                        gf.goFeatureType = vtf.GOFeatureType(geomWgs);
                        gf.layer         = layer;
                        gf.featureIndex  = (Int64)i;
                        gf.layerIndex    = indexOfLayer;
                        gf.featureCount  = featureCount;
                        gf        = tile.EditFeatureData(gf);
                        gf.goTile = goTile;
//							gf.setRenderingOptions ();
                        gf.ConvertAttributes();

                        if (geomWgs.Count > 0)
                        {
                            switch (gf.goFeatureType)
                            {
                            case GOFeatureType.Line:
                                gf.geometry = geomWgs [0];
                                gf.ConvertGeometries();
                                AddFatureToList(gf, pl.goFeatures);
                                break;

                            case GOFeatureType.Polygon:
                                gf.geometry = geomWgs[0];
                                gf.ConvertGeometries();
                                AddFatureToList(gf, pl.goFeatures);
                                break;

                            case GOFeatureType.MultiLine:
                                foreach (IList geometry in geomWgs)
                                {
                                    float     indexMulti = (((float)geomWgs.IndexOf((List <LatLng>)geometry) + 1) * (i + 1) / geomWgs.Count);
                                    GOFeature gfm;
                                    if (layer.layerType == GOLayer.GOLayerType.Roads)
                                    {
                                        gfm = new GORoadFeature((GORoadFeature)gf);
                                    }
                                    else
                                    {
                                        gfm = new GOFeature(gf);
                                    }

//									gfm.index = indexMulti;
                                    gfm.geometry = geometry;
                                    gfm.ConvertGeometries();
                                    AddFatureToList(gfm, pl.goFeatures);
                                }
                                break;

                            case GOFeatureType.MultiPolygon:
                                foreach (IList geometry in geomWgs)
                                {
                                    List <Vector3>         convertedSubject = null;
                                    List <List <Vector3> > convertedClips   = new List <List <Vector3> >();

                                    for (int j = 0; j < geomWgs.Count; j++)                                     //Clip ascending

                                    {
                                        IList          p          = geomWgs [j];
                                        List <Vector3> convertedP = GOFeature.CoordsToVerts(p, layer.layerType == GOLayer.GOLayerType.Buildings);
                                        if (GOFeature.IsClockwise(convertedP))
                                        {
                                            convertedSubject = convertedP;
                                        }
                                        else
                                        {
                                            //Add clip
                                            convertedClips.Add(convertedP);
                                        }
                                        //Last one
                                        if (j == geomWgs.Count - 1 || (j < geomWgs.Count - 1 && GOFeature.IsGeoPolygonClockwise(geomWgs [j + 1]) && convertedSubject != null))
                                        {
                                            GOFeature gfm = new GOFeature(gf);
//											gfm.index = (i +1)*j;
                                            gfm.convertedGeometry = convertedSubject;
                                            gfm.clips             = convertedClips;
                                            AddFatureToList(gfm, pl.goFeatures);

                                            convertedSubject = null;
                                            convertedClips   = new List <List <Vector3> >();
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }

                    if (goTile.combineFeatures)
                    {
                        pl = GOCombineFeatures.Combine(pl);
                    }

                    list.Add(pl);
                }
            }
        }
示例#19
0
 public VectorFeatureUnity(VectorTileFeature feature, UnityTile tile)
 {
     Data       = feature;
     Properties = Data.GetProperties();
     Points     = feature.GeometryAsWgs84((ulong)tile.Zoom, (ulong)tile.TileCoordinate.x, (ulong)tile.TileCoordinate.y);
 }
        public override GOFeature ParseFeatureData(VectorTileFeature feature, GOLayer layer)
        {
            IDictionary properties = feature.GetProperties();
            GOFeature   goFeature;

            if (layer.layerType == GOLayer.GOLayerType.Roads)
            {
                goFeature = new GORoadFeature();

                goFeature.kind = GOEnumUtils.MapzenToKind((string)properties ["kind"]);
                if (properties.Contains("kind_detail"))                   //Mapzen
                {
                    goFeature.detail = (string)properties ["kind_detail"];
                }

                ((GORoadFeature)goFeature).isBridge = properties.Contains("is_bridge") && properties ["is_bridge"].ToString() == "True";
                ((GORoadFeature)goFeature).isTunnel = properties.Contains("is_tunnel") && properties ["is_tunnel"].ToString() == "True";
                ((GORoadFeature)goFeature).isLink   = properties.Contains("is_link") && properties ["is_link"].ToString() == "True";
            }
            else
            {
                goFeature      = new GOFeature();
                goFeature.kind = GOEnumUtils.MapzenToKind((string)properties ["kind"]);
                if (properties.Contains("kind_detail"))                   //Mapzen
                {
                    goFeature.kind = GOEnumUtils.MapzenToKind((string)properties ["kind_detail"]);
                }
            }

            goFeature.name = (string)properties ["name"];

            Int64 sort = 0;

            if (properties.Contains("sort_rank"))
            {
                sort = Convert.ToInt64(properties ["sort_rank"]);
            }
            else if (properties.Contains("sort_key"))
            {
                sort = Convert.ToInt64(properties ["sort_key"]);
            }
            goFeature.y    = sort / 1000.0f;
            goFeature.sort = sort;

            goFeature.height = layer.defaultRendering.polygonHeight;

            if (layer.useRealHeight && properties.Contains("height"))
            {
                double h = Convert.ToDouble(properties["height"]);
                goFeature.height = (float)h * Global.tilesizeRank;
            }

            if (layer.useRealHeight && properties.Contains("min_height"))
            {
                double hm = Convert.ToDouble(properties["min_height"]) * Global.tilesizeRank;
                goFeature.y = (float)hm;
                if (goFeature.height >= hm)
                {
                    goFeature.y      = (float)hm;
                    goFeature.height = (float)goFeature.height - (float)hm;
                }
            }


            return(goFeature);
        }
示例#21
0
        private void ParseTilesetsToList(List <GOParsedLayer> list, VectorTile vt, GOTilesetLayer[] tilesets)
        {
            foreach (GOTilesetLayer tileSet in tilesets)
            {
                string kind = string.IsNullOrEmpty(tileSet.TilesetKindProperty)? tileSet.TilesetKindProperty : "kind";

                VectorTileLayer lyr = vt.GetLayer(tileSet.TilesetName);
                if (lyr != null)
                {
                    int featureCount = lyr.FeatureCount();

                    if (featureCount == 0)
                    {
                        continue;
                    }

                    GOParsedLayer pl = new GOParsedLayer();
                    pl.name         = lyr.Name;
                    pl.tilesetLayer = tileSet;
                    pl.goFeatures   = new List <GOFeature>();

                    for (int i = 0; i < featureCount; i++)
                    {
                        VectorTileFeature vtf = lyr.GetFeature(i);

                        List <List <LatLng> > geomWgs = vtf.GeometryAsWgs84((ulong)goTile.zoomLevel, (ulong)goTile.tileCoordinates.x, (ulong)goTile.tileCoordinates.y, 0);
                        GOFeature             gf      = new GOFeature();

                        gf.properties    = vtf.GetProperties();
                        gf.attributes    = GOFeature.PropertiesToAttributes(gf.properties);
                        gf.goFeatureType = vtf.GOFeatureType(geomWgs);
                        gf.tileSetKind   = kind;
                        gf.tilesetLayer  = tileSet;
                        gf.goTile        = goTile;
                        gf.featureIndex  = (Int64)i;
                        //gf.layerIndex = indexOfLayer;
                        gf.featureCount = featureCount;
                        //gf = tile.EditFeatureData(gf);
                        gf.goTile = goTile;
                        gf.ConvertAttributes();

                        if (gf.goFeatureType == GOFeatureType.Undefined)
                        {
                            continue;
                        }

                        string name = "Dataset " + gf.goFeatureType.ToString();
                        //Debug.Log(name);

                        if (geomWgs.Count > 0 && (gf.goFeatureType == GOFeatureType.Point || gf.goFeatureType == GOFeatureType.MultiPoint)) //Probably needs a fix for multi points
                        {
                            //GOPOIKind kind = GOEnumUtils.PoiKindToEnum((string)properties[kindKey]);
                            GOTilesetPOIRendering rendering = tileSet.TilesetPOIRenderingForKind(kind);
                            if (rendering == null)
                            {
                                continue;
                            }

                            gf.geometry            = geomWgs[0];
                            gf.tileSetPoiRendering = rendering;
                            gf.name = name;
                            gf.ConvertPOIGeometries();
                            AddFatureToList(gf, pl.goFeatures);
                        }

                        else if (geomWgs.Count > 0)
                        {
                            switch (gf.goFeatureType)
                            {
                            case GOFeatureType.Line:
                                GOTilesetLINERendering lineRendering = tileSet.TilesetLINERenderingForKind(kind);
                                if (lineRendering == null)
                                {
                                    continue;
                                }
                                gf.geometry = geomWgs[0];
                                gf.ConvertGeometries();
                                gf.tileSetLineRendering = lineRendering;
                                gf.name   = name;
                                gf.height = lineRendering.height;
                                AddFatureToList(gf, pl.goFeatures);
                                break;

                            case GOFeatureType.Polygon:

                                GOTilesetPOLYGONRendering polygonRendering = tileSet.TilesetPOLYGONRenderingForKind(kind);
                                if (polygonRendering == null)
                                {
                                    continue;
                                }
                                gf.geometry = geomWgs[0];
                                gf.ConvertGeometries();
                                gf.name = name;
                                gf.tileSetPolygonRendering = polygonRendering;
                                gf.height = polygonRendering.height;
                                AddFatureToList(gf, pl.goFeatures);
                                break;

                            case GOFeatureType.MultiLine:
                                lineRendering = tileSet.TilesetLINERenderingForKind(kind);
                                if (lineRendering == null)
                                {
                                    continue;
                                }
                                foreach (IList geometry in geomWgs)
                                {
                                    float     indexMulti = (((float)geomWgs.IndexOf((List <LatLng>)geometry) + 1) * (i + 1) / geomWgs.Count);
                                    GOFeature gfm        = new GOFeature(gf);
                                    gf.name      = name;
                                    gfm.geometry = geometry;
                                    gfm.ConvertGeometries();
                                    gf.tileSetLineRendering = lineRendering;
                                    gf.height = lineRendering.height;
                                    AddFatureToList(gfm, pl.goFeatures);
                                }
                                break;

                            case GOFeatureType.MultiPolygon:
                                foreach (IList geometry in geomWgs)
                                {
                                    polygonRendering = tileSet.TilesetPOLYGONRenderingForKind(kind);
                                    if (polygonRendering == null)
                                    {
                                        continue;
                                    }
                                    List <Vector3>         convertedSubject = null;
                                    List <List <Vector3> > convertedClips   = new List <List <Vector3> >();

                                    for (int j = 0; j < geomWgs.Count; j++)
                                    {     //Clip ascending
                                        IList          p          = geomWgs[j];
                                        List <Vector3> convertedP = GOFeature.CoordsToVerts(p, false);
                                        if (GOFeature.IsClockwise(convertedP))
                                        {
                                            convertedSubject = convertedP;
                                        }
                                        else
                                        {
                                            //Add clip
                                            convertedClips.Add(convertedP);
                                        }
                                        //Last one
                                        if (j == geomWgs.Count - 1 || (j < geomWgs.Count - 1 && GOFeature.IsGeoPolygonClockwise(geomWgs[j + 1]) && convertedSubject != null))
                                        {
                                            GOFeature gfm = new GOFeature(gf);
                                            //											gfm.index = (i +1)*j;
                                            gfm.convertedGeometry      = convertedSubject;
                                            gfm.clips                  = convertedClips;
                                            gf.tileSetPolygonRendering = polygonRendering;
                                            gf.name = name;
                                            AddFatureToList(gfm, pl.goFeatures);
                                            convertedSubject = null;
                                            convertedClips   = new List <List <Vector3> >();
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }

                    list.Add(pl);
                }
            }
        }
示例#22
0
        static int Main(string[] args)
        {
            //ul 14/4680/6260
            //lr 14/4693/6274
            ulong zoom   = 14;
            ulong minCol = 4680;
            ulong minRow = 6260;
            ulong maxCol = 4693;
            ulong maxRow = 6274;

            string fixturePath = Path.Combine(Path.Combine(Path.Combine(Path.Combine(Path.Combine("..", ".."), ".."), "bench"), "mvt-bench-fixtures"), "fixtures");

            if (!Directory.Exists(fixturePath))
            {
                Console.Error.WriteLine("fixture directory not found: [{0}]", fixturePath);
                return(1);
            }

            ulong           nrOfTiles = (maxCol - minCol + 1) * (maxRow - minRow + 1);
            List <TileData> tiles     = new List <TileData>((int)nrOfTiles);

            for (ulong col = minCol; col <= maxCol; col++)
            {
                for (ulong row = minRow; row <= maxRow; row++)
                {
                    string fileName = string.Format("{0}-{1}-{2}.mvt", zoom, col, row);
                    fileName = Path.Combine(fixturePath, fileName);
                    if (!File.Exists(fileName))
                    {
                        Console.Error.WriteLine("fixture mvt not found: [{0}]", fileName);
                        return(1);
                    }
                    else
                    {
                        tiles.Add(new TileData()
                        {
                            zoom = zoom,
                            col  = col,
                            row  = row,
                            pbf  = File.ReadAllBytes(fileName)
                        });
                    }
                }
            }

            Stopwatch   stopWatch = new Stopwatch();
            List <long> elapsed   = new List <long>();

            for (int i = 0; i <= 100; i++)
            {
                Console.Write(".");
                stopWatch.Start();
                foreach (var tile in tiles)
                {
                    VectorTile vt = new VectorTile(tile.pbf, false);
                    foreach (var layerName in vt.LayerNames())
                    {
                        VectorTileLayer layer = vt.GetLayer(layerName);
                        for (int j = 0; j < layer.FeatureCount(); j++)
                        {
                            VectorTileFeature feat = layer.GetFeature(j);
                            var props = feat.GetProperties();
                        }
                    }
                }
                stopWatch.Stop();
                //skip first run
                if (i != 0)
                {
                    elapsed.Add(stopWatch.ElapsedMilliseconds);
                }
                stopWatch.Reset();
            }


            Console.WriteLine(
                @"
runs          : {0}
tiles per run : {1}
min [ms]      : {2}
max [ms]      : {3}
avg [ms]      : {4}
StdDev        : {5:0.00}
overall [ms]  : {6}
tiles/sec     : {7:0.0}
",
                elapsed.Count,
                tiles.Count,
                elapsed.Min(),
                elapsed.Max(),
                elapsed.Average(),
                StdDev(elapsed),
                elapsed.Sum(),
                ((float)elapsed.Count * (float)tiles.Count / (float)elapsed.Sum()) * 1000
                );


            return(0);
        }