private void MergeAndFlushWays() { var mergeWatch = Stopwatch.StartNew(); var nodes = nodesIndex.ReadAllNodesById(wayBufNodeIds.OrderBy(x => x)).ToDictionary(x => x.Id); wayBufNodeIds.Clear(); totalWayNodes = 0; mergeWatch.Stop(); Console.WriteLine( $"Found: {nodes.Count} withing: {mergeWatch.Elapsed}. Speed: {nodes.Count / mergeWatch.Elapsed.TotalSeconds}/s"); foreach (var osmWay in waysBuf) { var wayNodes = osmWay.NodeIds.Select(x => nodes[x]).ToList(); for (var i = 1; i < wayNodes.Count; i++) { var diff = Math.Abs(wayNodes[i].Lat - wayNodes[i - 1].Lat); if (diff > maxDiff) { maxDiff = diff; maxDiffId = osmWay.Id; } diff = Math.Abs(wayNodes[i].Lat - wayNodes[i - 1].Lat); if (diff > maxDiff) { maxDiff = diff; maxDiffId = osmWay.Id; } } WriteWayToIndex(osmWay, wayNodes); } Console.WriteLine($"Max Diffs: {maxDiff:0,000}, ID: {maxDiffId:0,000}"); waysBuf.Clear(); }
public void ProcessPrimitives(PrimitiveAccessor accessor, string data) { if (accessor == null) { throw new ArgumentNullException(nameof(accessor)); } var nodeIds = accessor.Relations .SelectMany(x => x.Items) .Where(i => i.MemberType == RelationMemberTypes.Node) .Select(i => i.Id) .Distinct() .OrderBy(x => x); var nodes = nodesIndex.ReadAllNodesById(nodeIds).ToDictionary(x => x.Id); foreach (var relation in accessor.Relations) { var rect = new BoundingRect(); var itemInfos = new List <RelationItemInfo>(); foreach (var relationItem in relation.Items) { switch (relationItem.MemberType) { case RelationMemberTypes.Node: if (!nodes.TryGetValue(relationItem.Id, out var node)) { itemInfos.Add(new RelationItemInfo { Id = (ulong)relationItem.Id, Type = relationItem.MemberType, MidLat = int.MinValue, MidLon = int.MinValue }); } else { rect.Extend(node.Lat, node.Lon); itemInfos.Add(new RelationItemInfo { Id = (ulong)relationItem.Id, Type = relationItem.MemberType, MidLat = node.Lat, MidLon = node.Lon }); } break; case RelationMemberTypes.Way: var way = waysData.FindWayInfo((ulong)relationItem.Id); if (way == null) { itemInfos.Add(new RelationItemInfo { Id = (ulong)relationItem.Id, Type = relationItem.MemberType, MidLat = int.MinValue, MidLon = int.MinValue }); } else { rect.Extend(way.Rect); itemInfos.Add(new RelationItemInfo { Id = (ulong)relationItem.Id, Type = relationItem.MemberType, MidLat = int.MinValue, MidLon = int.MinValue }); } break; case RelationMemberTypes.Relation: itemInfos.Add(new RelationItemInfo { Id = (ulong)relationItem.Id, Type = relationItem.MemberType, MidLat = 0, MidLon = 0 }); // Relations will be assembled recursively. break; default: throw new NotSupportedException("Unknown relation type."); } } relationsFile.Add(relation, 0, itemInfos, rect); // ToDo: Implement type detection } }