当前位置: 首页>>代码示例>>C#>>正文


C# Envelope.ToPolygon方法代码示例

本文整理汇总了C#中DotSpatial.Topology.Envelope.ToPolygon方法的典型用法代码示例。如果您正苦于以下问题:C# Envelope.ToPolygon方法的具体用法?C# Envelope.ToPolygon怎么用?C# Envelope.ToPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DotSpatial.Topology.Envelope的用法示例。


在下文中一共展示了Envelope.ToPolygon方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildQuadTree

        private static QuadTree<byte> BuildQuadTree(StRtree Tree, Dictionary<string, byte> Countries, Coordinate TopLeft, Coordinate BottomRight, int MaxDepth, int Depth = 0)
        {
            // Bounding box for this node.
            var envelope = new Envelope(TopLeft, BottomRight);

            // Find all countries whose bounding boxes intersect with this node.
            var coarseResults = Tree.Query(envelope);

            // Of those countries, find those whose geometry actually intersects with this node.
            var fineResults = (from Tuple<string, IGeometry> r in coarseResults select r).Where(r => r.Item2.Intersects(envelope.ToPolygon()));

            // In case of either:
            // 1) No countries intersect, in which case we mark this node as empty. Or;
            // 2) Exactly one country intersects, in which case we mark this node as that country.
            var results = fineResults as IList<Tuple<string, IGeometry>> ?? fineResults.ToList();
            if (results.Count() <= 1)
            {
                var country = results.FirstOrDefault();
                var countryName = country != null ? country.Item1 : "";

                Console.WriteLine("Adding {0}, Depth {1}, {2}x{3}", countryName, Depth, BottomRight.X - TopLeft.X, BottomRight.Y - TopLeft.Y);
                ++_nleafs;
                return new QuadTreeLeaf<byte>
                {
                    Data = Countries[countryName],
                    TopLeft = TopLeft.ToGeomoirCoordinate(),
                    BottomRight = BottomRight.ToGeomoirCoordinate()
                };
            }

            // If we have reached the maximum depth and multiple countries interect
            // with this node, mark it as the country with the largest overlap.
            if (Depth >= MaxDepth)
            {
                byte label = 0;
                // Take country with largest area intersecting.
                var r = (from Tuple<string, IGeometry> t in results orderby t.Item2.Intersection(envelope.ToPolygon()).Area descending select t).First();
                if (r.Item2.Intersection(envelope.ToPolygon()).Area > 0)
                    label = Countries[r.Item1];

                ++_nleafs;
                return new QuadTreeLeaf<byte>
                {
                    Data = label,
                    TopLeft = TopLeft.ToGeomoirCoordinate(),
                    BottomRight = BottomRight.ToGeomoirCoordinate()
                };
            }

            // Split the node into 4 quadrants and recurse on each.
            var middleTop = new Coordinate((BottomRight.X + TopLeft.X) / 2, TopLeft.Y);
            var middleBottom = new Coordinate((BottomRight.X + TopLeft.X) / 2, BottomRight.Y);
            var middleLeft = new Coordinate(TopLeft.X, (BottomRight.Y + TopLeft.Y) / 2);
            var middleRight = new Coordinate(BottomRight.X, (BottomRight.Y + TopLeft.Y) / 2);
            var middle = new Coordinate(middleTop.X, middleLeft.Y);
            return new QuadTreeNode<byte>
            {
                TopLeft = TopLeft.ToGeomoirCoordinate(),
                BottomRight = BottomRight.ToGeomoirCoordinate(),
                Children = new []
                {
                    BuildQuadTree(Tree, Countries, TopLeft, middle, MaxDepth, Depth + 1),
                    BuildQuadTree(Tree, Countries, middleTop, middleRight, MaxDepth, Depth + 1),
                    BuildQuadTree(Tree, Countries, middleLeft, middleBottom, MaxDepth, Depth + 1),
                    BuildQuadTree(Tree, Countries, middle, BottomRight, MaxDepth, Depth + 1)
                }
            };
        }
开发者ID:peterdn,项目名称:Geomoir,代码行数:68,代码来源:Program.cs


注:本文中的DotSpatial.Topology.Envelope.ToPolygon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。