Exemple #1
0
        public void Add(VectorTileFeature feature, double tolerance, bool noSimplify)
        {
            this.AddFeature(feature, tolerance, noSimplify);

            var min = feature.Min;
            var max = feature.Max;

            if (min[0] < this.Min[0])
            {
                this.Min[0] = min[0];
            }
            if (min[1] < this.Min[1])
            {
                this.Min[1] = min[1];
            }
            if (max[0] > this.Max[0])
            {
                this.Max[0] = max[0];
            }
            if (max[1] > this.Max[1])
            {
                this.Max[1] = max[1];
            }
        }
Exemple #2
0
        private void AddFeature(VectorTileFeature feature, double tolerance, bool noSimplify)
        {
            //   var geom = feature.Geometry;
            var type       = feature.Type;
            var simplified = new List <VectorTileGeometry>();

            var sqTolerance = tolerance * tolerance;

            // i, j, ring, p;

            if (type == 1)
            {
                var first  = new VectorTileGeometry(); simplified.Add(first);
                var points = feature.GetPoints();
                for (var i = 0; i < points.Count; i++)
                {
                    first.Add(points[i]);
                    NumPoints++;
                    NumSimplified++;
                }
            }
            else
            {
                var geom = feature.GetRings();
                // simplify and transform projected coordinates for tile geometry
                for (var i = 0; i < geom.Length; i++)
                {
                    var ring = geom[i];

                    // filter out tiny polylines & polygons
                    if (!noSimplify && ((type == 2 && ring.Distance < tolerance) ||
                                        (type == 3 && ring.Area < sqTolerance)))
                    {
                        NumPoints += ring.Count;
                        continue;
                    }

                    var simplifiedRing = new VectorTileGeometry()
                    {
                        Area = ring.Area, Distance = ring.Distance
                    };

                    for (var j = 0; j < ring.Count; j++)
                    {
                        var p = ring[j];
                        // keep points with importance > tolerance
                        if (noSimplify || p[2] > sqTolerance)
                        {
                            simplifiedRing.Add(p);
                            NumSimplified++;
                        }
                        NumPoints++;
                    }

                    simplified.Add(simplifiedRing);
                }
            }

            if (simplified.Count > 0)
            {
                Features.Add(new VectorTileFeature
                {
                    Geometry = type == 1? simplified.Single() : simplified.ToArray() as object,
                    Type     = type,
                    Tags     = feature.Tags
                });
            }
        }