Exemple #1
0
        public static Graph CreateOSMGraph(
            string OSMGraphFile, string intersectionsFile)
        {
            Graph g = new Graph();

            g.nodes = new Dictionary <long, Node>();
            try
            {
                StreamReader r = new StreamReader(OSMGraphFile);
                Dictionary <long, Dictionary <long, int> > tmpEdges
                    = ProcessOSMGraphFile(r, g);

                Console.WriteLine("Before IS: " + tmpEdges.Keys.Count);
                HandleIntersections(g, tmpEdges, intersectionsFile);
                Console.WriteLine("After IS: " + tmpEdges.Keys.Count);

                AddEdges(g, tmpEdges);
            }
            catch
            {
                throw new InvalidDataException();
            }

            /*
             * maxLat = 51.0404296;
             * minLat = 48.5874212;
             * maxLon = 18.8446152;
             * minLot = 12.1295496
             */

            g.SetBounds(48.5874212, 51.0404296, 12.1295496, 18.8446152);
            return(g);
        }
        public void ReadFile(string inputFileName, bool inside)
        {

            try
            {
                file = new StreamReader(inputFileName);
            }
            catch (IOException)
            {
                return;

            }
            string line;
            const string way = "      \"type\": \"way\",";
            long id;
            StringBuilder SBid;
            StringBuilder SBnodes;
            while (!file.EndOfStream)
            {

                line = file.ReadLine();
                if ((line == way) | (line == "  \"type\": \"way\","))
                {
                    SBid = new StringBuilder();
                    char c = ' ';
                    while (c != ':')
                        c = (char)file.Read();
                    c = (char)file.Read();
                    c = (char)file.Read();
                    while (c != ',')
                    {
                        SBid.Append(c);
                        c = (char)file.Read();

                    }
                    id = long.Parse(SBid.ToString());


                    line = file.ReadLine();
                    line = file.ReadLine();
                    line = file.ReadLine();
                    SBnodes = new StringBuilder();
                    while ((line != "      ],") && (line != "      ]")
                        && (line != "  ],"))
                    {

                        SBnodes.Append(line);
                        line = file.ReadLine();
                    }
                    string oneWay = "no";
                    bool found = false;
                    while ((line != "      }") && (line != "  }")
                        && (line != "  }") && (!found) && (!file.EndOfStream))
                    {
                        line = file.ReadLine();
                        string[] split = line.Split('\"');
                        if (split.Length > 2 && split[1] == "oneway")
                        {
                            oneWay = split[3];
                            found = true;
                        }

                    }
                    graph.GetEdges(oneWay, SBnodes.ToString());

                }
                else if ((line == "      \"type\": \"node\",")
                        | (line == "  \"type\": \"node\","))
                {

                    char[] sep = new char[] { ' ', ',' };
                    line = file.ReadLine();
                    string[] words = line.Split(
                        sep, StringSplitOptions.RemoveEmptyEntries);
                    long idNode = long.Parse(words[1]);

                    line = file.ReadLine();
                    words = line.Split(sep, StringSplitOptions.RemoveEmptyEntries);

                    double lat = double.Parse(words[1]);
                    if (lat < minLat)
                        minLat = lat;
                    if (lat > maxLat)
                        maxLat = lat;
                    line = file.ReadLine();
                    words = line.Split(sep, StringSplitOptions.RemoveEmptyEntries);

                    double lon = double.Parse(words[1]);
                    if (lon < minLon)
                        minLon = lon;
                    if (lon > maxLon)
                        maxLon = lon;

                    Node node = new Node(idNode);
                    Node nodeOut;
                    if (idNode == 74122365)
                        lat = lat;
                    node.SetData(lat, lon);
                    if (!graph.nodes.TryGetValue(idNode, out nodeOut))
                    {
                        graph.nodes.Add(idNode, node);
                        node.inside = inside;

                    }
                    else
                    {
                        nodeOut.SetData(lat, lon);
                       
                        nodeOut.inside = inside;

                    }
                }


            }

            List<long> deletedC = new List<long>();


            graph.SetBounds(minLat, maxLat, minLon, maxLon);

        }