Example #1
0
        private void findConnectedIntersections()
        {
            foreach (OSMWay way in Ways)
            {
                if (way.NodeReferences.Count < 2)
                {
                    continue;
                }

                if (!way.Tags.ContainsKey("highway") || !AcceptedRoadTypes.Contains(way.Tags["highway"]))
                {
                    continue;
                }

                bool              firstLoop = true;
                double            distSinceMatch = 0;
                LatitudeLongitude previousLoc = null;
                OSMIntersection   intersection = null, previousIntersection = null;
                foreach (string nodeId in way.NodeReferences)
                {
                    if (nodeId == "149232745" && previousIntersection != null && previousIntersection.ID == "149161225")
                    {
                        var str = "str";
                    }
                    OSMNode node;
                    if (!NodesById.TryGetValue(nodeId, out node))
                    {
                        int index = way.NodeReferences.IndexOf(nodeId);
                        way.NodeReferences.RemoveAt(index);
                        way.NodeDistances.RemoveAt(index);
                        continue;
                    }

                    if (!firstLoop)
                    {
                        distSinceMatch += previousLoc.DistanceFrom(node.Location);
                    }

                    previousLoc = node.Location;
                    firstLoop   = false;
                    if (Intersections.TryGetValue(nodeId, out intersection))
                    {
                        if (previousIntersection != null)
                        {
                            previousIntersection.ConnectedIntersectionDistances[nodeId] = distSinceMatch;
                            if (!way.Oneway)
                            {
                                intersection.ConnectedIntersectionDistances[previousIntersection.ID] = distSinceMatch;
                            }
                            distSinceMatch = 0;
                        }
                        previousIntersection = intersection;
                    }
                }
            }
        }