Exemplo n.º 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");
        }
Exemplo n.º 2
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"));
        }
Exemplo n.º 3
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);
        }