本文整理汇总了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)
}
};
}