Ejemplo n.º 1
0
        private static void SplitEdges(Graph g,
                                       string line0, string line1, long newNid,
                                       Dictionary <long, Dictionary <long, int> > tmpEdges)
        {
            Node newNode = new Node(newNid);

            g.nodes.Add(newNid, newNode);
            tmpEdges.Add(newNid, new Dictionary <long, int>());
            string[] words = line0.Split('*');
            long     e0    = long.Parse(words[0]);
            long     e1    = long.Parse(words[1]);
            long     f0    = long.Parse(words[2]);
            long     f1    = long.Parse(words[3]);

            words = line1.Split('*');
            double lon = double.Parse(words[0]);
            double lat = double.Parse(words[1]);

            newNode.SetData(lat, lon);
            SplitEdge(g, e0, e1, newNid, tmpEdges);
            SplitEdge(g, f0, f1, newNid, tmpEdges);
        }
Ejemplo n.º 2
0
        ProcessOSMGraphFile(StreamReader r, Graph g)
        {
            Dictionary <long, Dictionary <long, int> > tmpEdges
                = new Dictionary <long, Dictionary <long, int> >();
            Node n = null;

            string line = r.ReadLine();

            string[] words  = line.Split(' ');
            bool     inside = bool.Parse(words[3]);

            while (!r.EndOfStream)
            {
                if (true)
                //  if (inside)
                {
                    n = new Node(long.Parse(words[0]));
                    n.SetData(double.Parse(words[1]), double.Parse(words[2]));
                    inside = bool.Parse(words[3]);

                    n.inside = inside;
                    g.nodes.Add(n.id, n);
                    tmpEdges[n.id] = new Dictionary <long, int>();
                }
                line  = r.ReadLine();
                words = line.Split(' ');
                while (!r.EndOfStream && words.Count() == 2)
                {
                    tmpEdges[n.id][long.Parse(words[0])]
                          = int.Parse(words[1]);
                    line  = r.ReadLine();
                    words = line.Split(' ');
                }
            }
            return(tmpEdges);
        }
        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);

        }