Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/18/12 12:56:35 (12 years ago)
Author:
spimming
Message:

#1894:

  • graph data structures added
  • method to get the ways for a specific node
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm.Data/XmlDataSource.cs

    r8293 r8300  
    1010    private IDictionary<long, Way> ways;
    1111    private IDictionary<long, Relation> relations;
     12
     13    private IDictionary<long, List<long>> nodeWays;
    1214
    1315
     
    3840      relations = new Dictionary<long, Relation>();
    3941
     42      nodeWays = new Dictionary<long, List<long>>();
     43
    4044      ReadData();
    4145    }
     
    5559      if (ways.ContainsKey(wayId)) {
    5660        return ways[wayId];
     61      }
     62      return null;
     63    }
     64
     65    public List<Way> GetWays(Node node) {
     66      if (nodeWays.ContainsKey(node.Id)) {
     67        List<long> wayIds = nodeWays[node.Id];
     68        List<Way> result = new List<Way>(wayIds.Count);
     69        for (int i = 0; i < wayIds.Count; i++) {
     70          result.Add(GetWay(wayIds[i]));
     71        }
     72        return result;
    5773      }
    5874      return null;
     
    117133
    118134          ways.Add(way.Id, way);
     135          InsertNodeWayRelation(way);
    119136
    120137          reader.Read();
     
    170187
    171188    }
     189
     190    private void InsertNodeWayRelation(Way way) {
     191      foreach (Node node in way.Nodes) {
     192        if (!nodeWays.ContainsKey(node.Id)) {
     193          nodeWays.Add(node.Id, new List<long>());
     194        }
     195        nodeWays[node.Id].Add(way.Id);
     196      }
     197    }
    172198  }
    173199}
Note: See TracChangeset for help on using the changeset viewer.