public SpatialSplitInfo Split(string otherFileName)
        {
            var latSize = BoundingRect.LatSize;
            var lonSize = BoundingRect.LonSize;

            var allNodes = ReadAllNodes();
            var allWays  = ReadAllWays();
            var allItems = new List <IMapObject>(nodesCount + waysCount);

            allItems.AddRange(allNodes);
            allItems.AddRange(allWays);

            Comparison <IMapObject> comparison;
            var splitByLatitude = latSize >= lonSize;

            if (splitByLatitude)
            {
                comparison = (a, b) => a.MidLat - b.MidLat;
            }
            else
            {
                comparison = (a, b) => a.MidLon - b.MidLon;
            }

            var splitter = new QuickSortSplitter <IMapObject>(Comparer <IMapObject> .Create(comparison));
            var position = splitter.Split(allItems, allItems.Count / 100);

            var splitValue = splitByLatitude ? allItems[position].MidLat : allItems[position].MidLon;


            var task = Task.Run(() =>
            {
                Clear();
                AddAll(this, allItems, 0, position);
            });

            var other = new SpatialBlock(otherFileName);

            AddAll(other, allItems, position, allItems.Count);

            task.Wait();

            return(new SpatialSplitInfo
            {
                SplitByLatitude = splitByLatitude,
                SplitValue = splitValue,
                FirstChild = new SpatialSplitInfo {
                    Block = this
                },
                SecondChild = new SpatialSplitInfo {
                    Block = other
                }
            });
        }
        private static void AddAll(SpatialBlock other, IReadOnlyList <IMapObject> items, int start, int end)
        {
            for (var i = start; i < end; i++)
            {
                if (items[i].Type != RelationMemberTypes.Node)
                {
                    continue;
                }
                other.Add((SNode)items[i]);
            }

            for (var i = start; i < end; i++)
            {
                if (items[i].Type != RelationMemberTypes.Way)
                {
                    continue;
                }
                other.Add((SWay)items[i]);
            }
        }
Beispiel #3
0
 private static void Test()
 {
     var block = new SpatialBlock(@"C:\git\test-projects\OSM\MapView\Blocks\sp-0001.map");
 }